public ActionResult DoOrder(OrderGetItem model) { var customer = _customerDA.GetCustomerItem(CustomerId); var date = ConvertDate.TotalSeconds(DateTime.Now); var hour = 0; var orderType = model.ListProductModel.Select(m => (CORE.OrderType)m.OrderType).OrderBy(m => m.GetOrder()).FirstOrDefault(); var receive = DateTime.Today; if (orderType == CORE.OrderType.TOMORROW) { hour = 12; receive = receive.AddDays(1); } if (orderType == CORE.OrderType.BEFORE12H) { hour = 12; } if (orderType == CORE.OrderType.BEFORE17H) { hour = 17; } var order = new Shop_ContactOrder() { Address = model.Address, CustomerID = CustomerId, CustomerName = model.CustomerName, Mobile = model.Mobile, AgencyId = customer.AgencyId, Status = (int)FDI.CORE.OrderStatus.Pending, ReceiveDate = ConvertDate.TotalSeconds(receive), ReceiveHour = hour, DateCreated = date, IsDelete = false }; foreach (var productItem in model.ListProductModel) { var product = _productDa.GetProductDetailItem(productItem.ID); if (product == null) { return(Json(new JsonMessage(true, "Sản phẩm không tồn tại"))); } var day = OrderExtensions.GetDayByOrderType((OrderType)productItem.OrderType); var hours = OrderExtensions.GetHourByOrderType((OrderType)productItem.OrderType); var todayCode = ConvertDate.TotalSeconds(DateTime.Today.AddDays(day)); var receiveDate = ConvertDate.TotalSeconds(DateTime.Today.AddDays(day).AddHours(hours)); var productitem = new Shop_ContactOrder_Details() { Quantity = productItem.Q, ProductID = productItem.ID, Price = product.PriceUnit, //don gia Weight = productItem.Weight, DateCreated = date, OrderType = productItem.OrderType, TodayCode = todayCode, ReceiveDate = receiveDate, GID = Guid.NewGuid(), }; switch (productitem.OrderType) { case 1: productitem.DateCreated = ConvertDate.TotalSeconds(DateTime.Today.AddHours(12)); break; } order.Shop_ContactOrder_Details.Add(productitem); } order.TotalPrice = order.Shop_ContactOrder_Details.Sum(m => m.Price * m.Quantity * m.Weight); _orderDa.Add(order); _orderDa.Save(); return(Json(new JsonMessage(false, "Đặt hàng thành công"))); }