public static ApplicationUser CreateFromViewModel(UserViewModel user) { return new ApplicationUser() { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, ShoppingCart = user.ShoppingCart }; }
public ActionResult Create(UserViewModel userviewmodel) { if (ModelState.IsValid) { db.Users.Add(UserViewModel.CreateFromViewModel(userviewmodel)); db.SaveChanges(); return RedirectToAction("Index"); } return View(userviewmodel); }
public void CreateShouldCreateProperUser() { Guid guid = new Guid("50d3ebaa-eea3-453f-8e8b-b835605b3e85"); UserViewModel user = new UserViewModel() { Id = guid.ToString(), FirstName = "Ivan", LastName = "jorkov" }; var usersRepoMock = new Mock<IRepository<ApplicationUser>>(); var uofMock = new Mock<IUnitOfWorkData>(); uofMock.Setup(x => x.Users).Returns(usersRepoMock.Object); var controller = new UserController(uofMock.Object); RedirectToRouteResult result = (RedirectToRouteResult)controller.Create(user); Assert.IsNotNull(result, "Create action returns null."); //Assert.AreEqual("Index", result.RouteValues); }
public ActionResult Edit(UserViewModel userviewmodel) { if (ModelState.IsValid) { //db.Entry(userviewmodel).State = EntityState.Modified; var user = UserViewModel.CreateFromViewModel(userviewmodel); this.db.Users.Update(user); this.db.SaveChanges(); return RedirectToAction("Index"); } return View(userviewmodel); }