public ActionResult Add(string key, string json, string code, Guid UserId, string port = ":3000") { try { if (key == Keyapi) { var obj = JsonConvert.DeserializeObject <ModelOrderGetItem>(json); var listcontact = new List <Shop_ContactOrder>(); foreach (var item in obj.list) { decimal totalprice = 0; var order = new Shop_ContactOrder { StartDate = obj.StartDate, UserID = UserId, EndDate = obj.EndDate, BedDeskID = item.idbed, TotalMinute = obj.Value, AgencyId = Agencyid(), IsDelete = false, DateCreated = DateTime.Now.TotalSeconds(), CustomerID = obj.CustomerID, CustomerName = obj.CustomerName, Address = obj.Address, Mobile = obj.Mobile, IsEarly = obj.IsEarly, Status = (int)(int)FDI.CORE.OrderStatus.Pending, Content = HttpUtility.UrlDecode(obj.Note) }; if (obj.Lstproduct != null) { var orderDetail = new Shop_ContactOrder_Details(); var lstp = obj.Lstproduct.Split(','); for (int i = 0; i < lstp.Length; i++) { var product = _da.GetProductItem(int.Parse(lstp[i])); totalprice += product.PriceNew; orderDetail = new Shop_ContactOrder_Details { ProductID = int.Parse(lstp[i]), Quantity = 1, Status = (int)(int)FDI.CORE.OrderStatus.Complete, Price = product.PriceNew, DateCreated = DateTime.Now.TotalSeconds(), }; order.Shop_ContactOrder_Details.Add(orderDetail); } order.TotalPrice = totalprice; } listcontact.Add(order); } foreach (var item in listcontact) { _da.Add(item); } _da.Save(); foreach (var jsonnew in listcontact.Select(item => new OrderProcessItem { ID = item.ID, BedDeskID = item.BedDeskID, Minute = item.TotalMinute, StartDate = item.StartDate, EndDate = item.EndDate, IsEarly = obj.IsEarly.HasValue && obj.IsEarly.Value, AgencyId = Agencyid(), Status = 0 })) { json = new JavaScriptSerializer().Serialize(jsonnew); Node(port + "/addcontactorder/" + json); } return(Json(1, JsonRequestBehavior.AllowGet)); } return(Json(0, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(0, JsonRequestBehavior.AllowGet)); } }
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"))); }