public IActionResult MustSignUp(CheckOutMustSignUpViewModel vm) { if (ModelState.IsValid) { _context.Users.Add(vm.User); _context.SaveChanges(); AnoCart anocart = _context.AnoCarts.Where(ac => ac.Id == vm.AnoCartId).FirstOrDefault(); Cart cart = new Cart(); int userid = _context.Users.Where(u => u.PhoneNumber == vm.User.PhoneNumber).FirstOrDefault().Id; cart.User_Id = userid; cart.CartStatus_Id = anocart.CartStatus_Id; cart.TotalQuantity = anocart.TotalQuantity; cart.TotalPrice = anocart.TotalPrice; cart.DateCreate = anocart.DateCreate; cart.DateModify = anocart.DateModify; _context.Carts.Add(cart); _context.SaveChanges(); int cartid = _context.Carts.Where(c => c.User_Id == userid).FirstOrDefault().Id; if (_context.AnoCartDetails.Where(ac => ac.Cart_Id == anocart.Id).FirstOrDefault() != null) { List <AnoCartDetail> anodetails = _context.AnoCartDetails.Where(ac => ac.Cart_Id == anocart.Id).ToList(); foreach (AnoCartDetail detail in anodetails) { CartDetail cdt = new CartDetail() { Cart_Id = cartid, Product_Id = detail.Product_Id, PriceSingle = detail.PriceSingle, PriceTotal = detail.PriceTotal, Quantity = detail.Quantity, DateCreate = detail.DateCreate, DateModify = detail.DateModify }; _context.CartDetails.Add(cdt); _context.SaveChanges(); } } return(RedirectToAction("AlreadySignUp", "Checkout", new { userid = userid })); } else { return(View( new CheckOutMustSignUpViewModel() { User = vm.User, AnoCartId = vm.AnoCartId, ProductTypes = _context.ProductTypes.ToList(), productBrands = _context.ProductBrands.ToList() } )); } }
public IActionResult MustSignUp(int anocartid) { CheckOutMustSignUpViewModel vm = new CheckOutMustSignUpViewModel() { User = new User() { Role_Id = 4 }, AnoCartId = anocartid, ProductTypes = _context.ProductTypes.ToList() }; return(View(vm)); }