public async Task <IActionResult> Selection() { var user = await _userManager.GetUserAsync(HttpContext.User); var viewModel = new PaymentSelectionViewModel { PhoneNumber = user.PhoneNumber, Email = user.Email, ClientName = user.FullName }; return(View(viewModel)); }
public async Task <IActionResult> Selection(PaymentSelectionViewModel model) { var orderItemsSessionModel = HttpContext.Session.Get <List <OrderItemSessionModel> >(SessionConstants.ORDER_ITEMS_SESSION_MODEL_NAME); var paymentSessionModel = HttpContext.Session.Get <PaymentSessionModel>(SessionConstants.PAYMENT_SESSION_MODEL_NAME); var user = await _userManager.GetUserAsync(HttpContext.User); if (paymentSessionModel == null || orderItemsSessionModel == null) { return(RedirectToActionPermanent("Index", "Home")); } using (IUnitOfWork uow = _uowProvider.CreateUnitOfWork()) { var orderRepo = uow.GetRepository <Order>(); var order = new Order { PaymentType = model.PaymentType, GrossTotal = paymentSessionModel.GrossTotal, NetTotal = paymentSessionModel.NetTotal, OrderCode = paymentSessionModel.OrderCode, CreatedUserId = user.Id, OrderItems = new List <OrderItem>() }; foreach (var item in orderItemsSessionModel) { var orderItem = new OrderItem { ProductId = item.Product.Id, Currency = item.Product.Price.Currency, Price = item.Product.Price.Price, Quantity = item.Quantity, CreatedUserId = user.Id, ExtraProperties = new List <ProductProperty>() }; foreach (var extraProperty in item.Properties) { var productProperty = new ProductProperty { Currency = extraProperty.Price.Currency, Price = extraProperty.Price.Price, Description = extraProperty.Description, Name = extraProperty.Name, Type = extraProperty.Type, Value = extraProperty.Value, Unit = extraProperty.Unit, CreatedUserId = user.Id }; orderItem.ExtraProperties.Add(productProperty); } order.OrderItems.Add(orderItem); } orderRepo.Add(order); await uow.SaveChangesAsync(); } paymentSessionModel.PaymentType = model.PaymentType; HttpContext.Session.Set(SessionConstants.PAYMENT_SESSION_MODEL_NAME, paymentSessionModel); return(RedirectToAction("Complete", "Payment")); }