public ActionResult Create(RegisterViewModel model) { if (ModelState.IsValid) { var user = new User() { UserName = model.UserName, Email = model.Email, }; var result = _userManager.CreateAsync(user, model.Password).Result; if (result.Succeeded) { _userManager.AddToRole(user.Id, "Customer"); var mapping = new UserProductsMapping() { UserId = user.Id, ProductID = model.ProductId }; _productUserService.CreateUserProductsMapping(mapping); return(RedirectToAction("Index")); } else { AddErrors(result); } } model.Products = _productService.GetProducts(); // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Edit(UserEditViewModel model) { if (ModelState.IsValid) { var user = Mapper.Map <UserEditViewModel, User>(model); user.FirstName = model.Name; _userService.EditUser(user); var mapping = new UserProductsMapping() { UserId = user.Id, ProductID = model.ProductId }; _productUserService.EditUserProductsMapping(mapping); return(RedirectToAction("Index")); } return(View(model)); }
public IEnumerable <ValidationResult> CanAddUserProductsMapping(UserProductsMapping order) { return(null); }
public void EditUserProductsMapping(UserProductsMapping orderToEdit) { orderRepository.Update(orderToEdit); SaveUserProductsMapping(); }
public void CreateUserProductsMapping(UserProductsMapping order) { orderRepository.Add(order); SaveUserProductsMapping(); }