public Folder CreateFolder(string email, Folder folder) { //TODO Api //найдём пользователя в БД var userFromDb = Db.SingleOrDefault<User>(u => u.Email == email); if (userFromDb != null) { folder.LogDate = DateTime.Now; folder.User = new User { Id = userFromDb.Id }; var result = Db.SaveOrUpdate(folder); _logger.Info($"Создана папка {folder}"); } else { throw new UserNotFoundException(email); } return folder; }
public ActionResult CreateFolder(FolderViewModel model) { var item = new Folder(); if (model.Id > 0) { item = FileService.GetFolder(model.Id); } item = Mapper.Map(model, item); try { FileService.CreateFolder(UserInfo.Email, item); } catch (UserNotFoundException ex) { return View("ServerError", ex.Message); } catch (Exception ex) { Logger.Fatal(ex); return View("ServerError", (object)"Произошла непредвиденная ошибка"); } return RedirectToAction("Edit", new { id = item.Id}); }
public ActionResult CreateFolder(FolderViewModel model) { var user = YandexAuth.GetUser(Request); //найдём пользователя в БД var userFromDb = Db.SingleOrDefault<User>(u => u.Email == user.default_email); if (userFromDb != null) { var item = new Folder(); if (model.Id > 0) { item = Db.Get<Folder>(model.Id); } item = Mapper.Map(model, item); item.LogDate = DateTime.Now; item.User = new User { Id = userFromDb.Id }; var result = Db.SaveOrUpdate(item); return RedirectToAction("Edit", new {id = result}); } return View("ServerError", (object)"Не удалось определить пользователя"); }
public void DeleteFolder(Folder folder) { var result = Db.Delete(folder); _logger.Info($"Удалена папка {folder}"); }