public ActionResult ChangeStatusOrder(Guid id, string status) { try { var order = _orderService.GetById(id); var sa = SetOrderStatus.SetStatusTypeInt(Convert.ToInt32(status)); order.Status = SetOrderStatus.SetStatus(sa); _orderService.Update(order); return(Json(new { id = id, status = status }, JsonRequestBehavior.AllowGet)); } catch { return(RedirectToAction("Erorr500", "HomdeAdmin")); } }
public async Task <ActionResult> Order(CheckoutViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var cookie = Request.Cookies["UserId"].Value; var cart = _shoppingCartService.GetShoppingCartByUserId(cookie); // Search Shoppping Cart by user id on cookie decimal subTotal = SumProductPriceInOrder(model.shoppingCartDetailModels); // Total price of order // create new order var order = new Order() { Id = Guid.NewGuid(), DeliveryName = model.customerModel.Name, DeliveryAddress = model.customerModel.Address, DeliveryPhone = model.customerModel.Phone, Email = model.customerModel.Email, CreatedDate = DateTime.Now, IsActive = true, Status = SetOrderStatus.SetStatus(OrderStatus.Receive), OrderDate = DateTime.Now, Note = model.customerModel.Note, SubPrice = subTotal, ToatalPrice = subTotal + 1, DeliveryFee = 1 }; _orderService.Insert(order); //Add Order Detail for order AddOrderDetails(model.shoppingCartDetailModels, order.Id); // Update Quanlity of product variation UpdateQuanlityProductVariation(model.shoppingCartDetailModels); // Delete ShoppingCart _shoppingCartService.Delete(cart); // Send email await UserManager.SendEmailAsync(User.Identity.GetUserId(), "Confirm Order From PerfumeShop", "Thank You"); return(RedirectToAction("Success", "Checkout")); } catch { return(RedirectToAction("Erorr", "Home")); } }
public async Task <IActionResult> SetOrderStatus([FromBody] SetOrderStatus content) { var order = await _context.Orders.FindAsync(content.Id); if (order == null) { return(NotFound()); } order.StatusId = content.StatusId; order.Status = _context.OrderStatuses.Find(content.StatusId); if (content.StatusId == 5) // Заказ закрыт { order.DateClosed = DateTime.Now; } _context.Entry(order).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { } return(NoContent()); }