public ActionResult Create(view.User formUser) { lib.User libUser = view.Mapper.Map(formUser); userRepo.Create(db.Mapper.Map(libUser)); userRepo.SaveChanges(); return(RedirectToAction(nameof(Index))); }
/***** Library -> View *****/ public static view.User Map(lib.User libUser) { view.User viewUser = new view.User { Id = libUser.Id, FirstName = libUser.FirstName, LastName = libUser.LastName }; try { if (libUser.DefaultLocationId != null) { viewUser.DefaultLocationName = lib.Location.GetById((int)libUser.DefaultLocationId).Name; } else { viewUser.DefaultLocationName = null; } } catch (e.InvalidIdException) { viewUser.DefaultLocationName = null; } return(viewUser); }
public ActionResult Delete(int id, view.User formUser) { try { lib.User libUser = lib.User.GetById(id); lib.User.Users.Remove(libUser); db.User dbUser = db.Mapper.Map(libUser); userRepo.Delete(dbUser); userRepo.SaveChanges(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
/***** View -> Library *****/ public static lib.User Map(view.User viewUser) { lib.User libUser = new lib.User { FirstName = viewUser.FirstName, LastName = viewUser.LastName }; if (viewUser.Id != 0) { libUser.Id = viewUser.Id; } try { libUser.DefaultLocationId = lib.Location.GetByName(viewUser.DefaultLocationName).Id; } catch (e.InvalidNameException) { viewUser.DefaultLocationName = null; } return(libUser); }