public async Task <IActionResult> Checkout(CheckoutViewModel model) { if (!ModelState.IsValid) { return(View(model)); } else { if (!_adress.GetAllAdresses.Any(a => a.Id == model.AdressId)) { _adress.CreateAdress(new Adress() { Country = model.Country, City = model.City, Street = model.Street, House = model.House, Building = model.Building, Flat = model.Flat, Floor = model.Floor }); } var items = _shopBasket.GetBookBasket(); _shopBasket.ListBookBasket = items; var adress = _adress.GetAdressById(model.AdressId); var user = await userManager.FindByIdAsync(model.UserId); var order = new Order() { UserId = model.UserId, User = user, AdressId = model.AdressId, Adress = adress, AllPrice = _shopBasket.AllPrice }; _allOrders.CreateOrder(order); ShopBasket.CloseSession(_service); return(View("Complete", order)); } }
public async Task <IActionResult> UserInfo(UserInfoViewModel model) { if (!ModelState.IsValid) { return(View(model)); } else { var user = await userManager.FindByIdAsync(model.Id); if (user is null) { return(NotFound()); } else { user.UserName = model.UserName; user.NormalizedUserName = model.UserName.ToUpper(); user.Name = model.Name; user.SurName = model.SurName; user.BirthDate = model.BirthDate; user.Email = model.Email; user.NormalizedEmail = model.Email.ToUpper(); user.PhoneNumber = model.PhonNumber; var edit_result = await userManager.UpdateAsync(user); if (!edit_result.Succeeded) { var errors = edit_result.Errors.Select(e => e.Description); ModelState.AddModelError("", string.Join(", ", errors)); return(View(model)); } var modelAdress = new Adress() { Id = model.AdressId, Country = model.Country, City = model.City, Street = model.Street, House = model.House, Building = model.Building, Flat = model.Flat, Floor = model.Floor, UserId = user.Id, User = user }; if (!_adress.GetAllAdresses.Any(a => a.Id == modelAdress.Id)) { _adress.CreateAdress(modelAdress); } else { _adress.EditAdress(modelAdress); } return(RedirectToAction("Index")); } } }