public IActionResult Bill(int id) { var userID = Task.Run(async() => await userManager.FindByNameAsync(User.Identity.Name)).Result.Id; var rolecheck = (from role in context.UserRoles.ToList() where role.UserId == userID select role).FirstOrDefault(); if (rolecheck != null) { var order = orderRepository.Get(id); order.EndTime = DateTime.Now; order.Using = false; var resultO = orderRepository.Edit(order); var orderdetails = (from ods in orderDetailRepository.Gets() where ods.OrderId == id select ods).ToList(); foreach (var od in orderdetails) { od.Paid = true; od.UserId = userID; orderDetailRepository.Edit(od); } if (resultO != null) { var url = "https://localhost:44366/Home/Index/" + id; return(Redirect(url)); } return(View()); } return(RedirectToAction("AccessDenied", "Account")); }
public IActionResult EditDetails(EditOrderDetailModel orderDetailModel) { if (orderDetailModel.OrderDetailToppings != null) { orderDetailModel.OrderDetailToppings.RemoveAll(t => !t.IsChecked); } var isNew = orderDetailModel.OrderDetailId == 0; var orderDetail = isNew ? new OrderDetail() : _orderDetailRepository.GetById(orderDetailModel.OrderDetailId); _mapper.Map(orderDetailModel, orderDetail); //set drink name/drink size if new if (isNew) { var drink = _drinkRepository.GetDrinkById(orderDetail.DrinkId); orderDetail.DrinkName = drink.Name; orderDetail.IsNewDrink = drink.IsNew; } var drinkSize = _drinkRepository.GetSizeById(orderDetailModel.DrinkSizeId); orderDetail.DrinkSize = drinkSize.Name; orderDetail.Price = drinkSize.Price; //update price orderDetail.FullPrice = orderDetail.Price + (orderDetail.OrderDetailToppings?.Sum(t => t.Price * t.Quantity) ?? 0); orderDetail.Amount = orderDetail.FullPrice * orderDetail.Quantity; var success = isNew ? _orderDetailRepository.Create(orderDetail) : _orderDetailRepository.Edit(orderDetail); if (success) { TempData["Message"] = "Lưu thành công"; } else { TempData["Message"] = "Lưu thất bại"; } //update order var order = _orderRepository.GetById(orderDetail.OrderId); order.IsSpecialPromo = _promotionRepository.CheckPromotionBuy1Get1(); _orderRepository.Edit(order); return(new RedirectResult(Url.Action("Edit", new { orderId = orderDetail.OrderId }) + "#editdrinks")); }