コード例 #1
0
 public static ApplicationUser CreateFromViewModel(UserViewModel user)
 {
     return new ApplicationUser()
     {
         Id = user.Id,
         FirstName = user.FirstName,
         LastName = user.LastName,
         ShoppingCart = user.ShoppingCart
     };
 }
コード例 #2
0
        public ActionResult Create(UserViewModel userviewmodel)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(UserViewModel.CreateFromViewModel(userviewmodel));
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(userviewmodel);
        }
コード例 #3
0
        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); 
        }
コード例 #4
0
 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);
 }