Adding a root dir will not add it to the DB until after it is saved, also will not save if the path is blank.

This commit is contained in:
Mark McDowall 2011-06-15 19:32:55 -07:00
parent 1fbf9a1416
commit c3d4732baa
3 changed files with 41 additions and 26 deletions

View file

@ -187,9 +187,16 @@ namespace NzbDrone.Web.Controllers
[HttpPost]
public JsonResult SaveRootDir(int id, string path)
{
if (String.IsNullOrWhiteSpace(path))
return new JsonResult { Data = "failed" };
try
{
_rootFolderProvider.Update(new RootDir { Id = id, Path = path });
if (id == 0)
id = _rootFolderProvider.Add(new RootDir { Path = path });
else
_rootFolderProvider.Update(new RootDir { Id = id, Path = path });
}
catch (Exception ex)
{
@ -199,30 +206,33 @@ namespace NzbDrone.Web.Controllers
return new JsonResult { Data = "failed" };
}
return new JsonResult { Data = "ok" };
return new JsonResult { Data = id };
}
public PartialViewResult AddRootDir()
{
var rootDir = new RootDir { Path = String.Empty };
var model = new RootDirModel
{
Id = 0,
Path = "",
SelectList = new SelectList(new List<string> { "" }, "")
};
var id = _rootFolderProvider.Add(rootDir);
rootDir.Id = id;
var model = new RootDirModel();
model.Id = rootDir.Id;
model.Path = rootDir.Path;
model.SelectList = new SelectList(new List<string> { rootDir.Path }, rootDir.Path);
ViewData["guid"] = Guid.NewGuid();
return PartialView("RootDir", model);
}
public ActionResult GetRootDirView(RootDir rootDir)
{
var model = new RootDirModel();
model.Id = rootDir.Id;
model.Path = rootDir.Path;
model.SelectList = new SelectList(new List<string> { rootDir.Path }, rootDir.Path);
var model = new RootDirModel
{
Id = rootDir.Id,
Path = rootDir.Path,
SelectList = new SelectList(new List<string> { rootDir.Path }, rootDir.Path)
};
ViewData["guid"] = Guid.NewGuid();
return PartialView("RootDir", model);
}