public string CreateOrder(OrderCreateBindingModel model, ApplicationUserDTO user) { List <OrderProduct> orderProducts = new List <OrderProduct>(); var shoppingCartProducts = this.shoppingCartService.FindAllDomainShoppingCartProducts(user.UserName).ToList(); if (shoppingCartProducts.Count == 0) { return(string.Empty); } var country = this.FindCountryByName(model.Country); var order = this.MapOrderAndSetNewId(model, user, country); orderProducts = this.CreateOrderProductsFromShoppingCartProducts(orderProducts, shoppingCartProducts, order); order.OrderProducts = orderProducts; order.TotalPrice = this.CalculateTotalPrice(order); this.dbContext.OrderProducts.AddRange(orderProducts); this.dbContext.Orders.Add(order); this.dbContext.SaveChanges(); return(order.Id); }
private Order MapOrderAndSetNewId(OrderCreateBindingModel model, ApplicationUserDTO user, Country country) { var order = this.mapper.Map <Order>(model); this.mapper.Map <ApplicationUserDTO, Order>(user, order); this.mapper.Map <Country, Order>(country, order); order.Id = Guid.NewGuid().ToString(); return(order); }
public async Task <IHttpActionResult> CreateOrder([FromBody] OrderCreateBindingModel model) { // validate var orderGraph = Mapper.Map <Order>(model); _orderManager.AssignNumber(orderGraph, orderGraph.Number, null); await _orderManager.SaveAsync(orderGraph, UserId); // temp !!! return(Ok(new { name = orderGraph.Name })); }
public async Task <IActionResult> Order(OrderCreateBindingModel model) { var serviceModel = Mapper.Map <OrderServiceModel>(model); serviceModel.OrderedOn = DateTime.Now; var result = await this.orderService.Create(serviceModel, this.User.Identity.Name); if (!result) { return(this.RedirectToAction("All", "Events")); } return(this.RedirectToAction("MyEvents", "Events")); }
public IActionResult Create(OrderCreateBindingModel model) { var user = this.usersService.FindUserByUsername(this.User.Identity.Name); var countries = this.orderService.FindAllCountries(); var shoppingCartProducts = this.shoppingCartService.FindAllShoppingCartProducts(user.Username); if (shoppingCartProducts == null) { var creationErrorViewModel = this.errorService.CreateCreateionErrorViewModel(NoProductsInShoppingCartErrorMessage, HyperLinkForDoesntExistError); return(this.RedirectToAction("CreationError", "Error", creationErrorViewModel)); } var shoppingCartProductsViewModel = this.mapper.Map <List <ShoppingCartProductsViewModel> >(shoppingCartProducts); if (this.ModelState.IsValid) { var orderId = this.orderService.CreateOrder(model, user); if (orderId == string.Empty) { var actualModel = this.CreateOrderShoppingCartViewWithCountries(model, countries, shoppingCartProductsViewModel); return(this.View(actualModel)); } this.shoppingCartService.RemoveAllProductsFromShoppingCart(this.User.Identity.Name); return(this.Redirect($"/Orders/Details/{orderId}")); } else { var actualModel = this.CreateOrderShoppingCartViewWithCountries(model, countries, shoppingCartProductsViewModel); return(this.View(actualModel)); } }
private OrderShoppingCartViewModel CreateOrderShoppingCartViewWithCountries(OrderCreateBindingModel model, List <string> countries, List <ShoppingCartProductsViewModel> shoppingCartProductsViewModel) { return(new OrderShoppingCartViewModel { ShoppingCartProductsViewModels = shoppingCartProductsViewModel, Countries = countries, OrderCreateViewModel = model }); }
private OrderShoppingCartViewModel CreateOrderShoppingCartViewWithoutCountries(OrderCreateBindingModel fillFormViewModel, List <ShoppingCartProductsViewModel> shoppingCartProductsViewModel) { return(new OrderShoppingCartViewModel { ShoppingCartProductsViewModels = shoppingCartProductsViewModel, OrderCreateViewModel = fillFormViewModel, Id = fillFormViewModel.Id }); }