public async Task <IActionResult> Order(OrderInputViewModel inputModel) { if (!ModelState.IsValid) { return(RedirectToAction("Index", "Home")); } var result = await this.ordersService.MakeOrder(this.User.Identity.Name, inputModel.Id, inputModel.PickUpPlace, inputModel.ReturnPlace, inputModel.Price, inputModel.PickUp, inputModel.Return, inputModel.DiscountCode); if (!result) { return(RedirectToAction(nameof(Invalid))); } var carModel = await this.carsService.GetCarModelById(inputModel.Id); var days = (inputModel.Return - inputModel.PickUp).Days; var message = string.Format(GlobalConstants.SignalRMessageForNewOrder, carModel, days); await this.notifyHub.Clients.All.SendAsync(GlobalConstants.SignalRMethodNewOrder, message); return(RedirectToAction(nameof(MyOrders))); }
public async Task <IActionResult> Order(OrderInputViewModel inputModel) { if (!this.ModelState.IsValid) { return(this.RedirectToAction("Index", "Home")); } var result = await this.ordersService.MakeOrder(this.User.Identity.Name, inputModel.Id, inputModel.PickUpPlace, inputModel.ReturnPlace, inputModel.Price, inputModel.PickUp, inputModel.Return); var carModel = this.carsService.GetCarModelById(id: inputModel.Id); var days = (inputModel.Return - inputModel.PickUp).Days; return(this.RedirectToAction(nameof(this.MyOrders))); }
public async Task BuyProductAsync(OrderInputViewModel order) { // Mapping order information(which contains user information) to user domain model. var newUser = Mapper.Map <User>(order); var newOrder = new Order() { User = newUser, OrderDate = DateTime.UtcNow, OrderItems = new List <OrderItem>() }; newOrder.OrderItems.Add(new OrderItem() { Order = newOrder, ProductId = order.ProductId }); // Saving information about order to all repositories. await Orders.AddAsync(newOrder); }