public async Task <IActionResult> Create(OrderDisplayInputModel orderDisplayInputModel) { if ((orderDisplayInputModel.DeliveryAddressId == "on" && orderDisplayInputModel.OfficeAddress == null) || (orderDisplayInputModel.DeliveryAddressId == null && orderDisplayInputModel.OfficeAddress == null)) { this.TempData["Error"] = DeliveryAddressCantBeNull; return(this.RedirectToAction(nameof(this.Create))); } if (!await this.promoCodeService.ExistsAsync(orderDisplayInputModel.PromoCodeName) && orderDisplayInputModel.PromoCodeName != null) { this.TempData["Error"] = PromoCodeDoesNotExistErrorMessage; return(this.RedirectToAction(nameof(this.Create))); } this.ProccessCreateForm(orderDisplayInputModel); var user = await this.userManager.GetUserAsync(this.User); if (orderDisplayInputModel.PromoCodeName != null) { orderDisplayInputModel.PromoCodeId = await this.promoCodeService.GetIdByNameAsync(orderDisplayInputModel.PromoCodeName); } var orderCreateInputModel = orderDisplayInputModel.To <OrderCreateInputModel>(); var shoppingCartId = await this.shoppingCartService.GetIdByUserId(user.Id); if (await this.shoppingCartProductsService.RemoveDisabledProducts(shoppingCartId)) { this.TempData["Error"] = SomeProductsHaveBeenRemoved; return(this.Redirect("/ShoppingCart")); } await this.orderService.CreateUproccessedOrder(orderCreateInputModel, shoppingCartId); return(this.RedirectToAction(nameof(this.SuccesfullPayment))); }
private void ProccessCreateForm(OrderDisplayInputModel orderDisplayInputModel) { if (orderDisplayInputModel.Recipient == null) { orderDisplayInputModel.Recipient = orderDisplayInputModel.FirstName; } if (orderDisplayInputModel.RecipientLastName == null) { orderDisplayInputModel.RecipientLastName = orderDisplayInputModel.LastName; } if (orderDisplayInputModel.RecipientPhoneNumber == null) { orderDisplayInputModel.RecipientPhoneNumber = orderDisplayInputModel.PhoneNumber; } if (orderDisplayInputModel.DeliveryAddressId == "on") { orderDisplayInputModel.DeliveryAddressId = null; } }