public ActionResult UpdateProductType(string orderId, string productId, string type) { var orderProduct = db.OrderProducts.Where(p => p.ProductId == productId && p.OrderId == orderId).FirstOrDefault(); if (orderProduct == null) { return(Json(new { id = 0 }, JsonRequestBehavior.AllowGet)); } orderProduct.ProductType = type; db.Entry(orderProduct).State = EntityState.Modified; db.SaveChanges(); string typeName = "Chưa xác định"; if (type == "warehouse") { typeName = "Hàng gửi kho"; } else if (type == "new") { typeName = "Hàng xuất mới"; } var staff = orderProduct.HaiOrder.OrderStaffs.Where(p => p.ProcessId == "create").FirstOrDefault(); if (staff != null) { Utitl.Send("Đơn hàng " + orderProduct.HaiOrder.Code, "Đã thay đổi loại hàng: " + typeName, staff.HaiStaff.UserLogin, db, mongoHelp); } return(Json(new { id = 1 }, JsonRequestBehavior.AllowGet)); }
public ActionResult UpdateDelivery(string orderId, string productId, int?can, int?box) { if (can == null || box == null) { return(Json(new { id = 0 }, JsonRequestBehavior.AllowGet)); } var orderProduct = db.OrderProducts.Where(p => p.ProductId == productId && p.OrderId == orderId).FirstOrDefault(); if (orderProduct == null) { return(Json(new { id = 0 }, JsonRequestBehavior.AllowGet)); } var quantity = box + orderProduct.ProductInfo.Quantity * can; orderProduct.QuantityFinish = quantity; db.Entry(orderProduct).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); string stt = ""; if (quantity == 0) { stt = "Chưa giao"; } else if (quantity == orderProduct.Quantity) { stt = "Giao đủ"; } else if (quantity > orderProduct.Quantity) { stt = "Giao nhiều hơn"; } else if (quantity < orderProduct.Quantity) { stt = "Giao ít hơn"; } var order = orderProduct.HaiOrder; string deliveryStt = GetDeliveryStatus(order); order.DStatus = deliveryStt; db.Entry(order).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); // save history var haiStaff = db.HaiStaffs.Where(p => p.UserLogin == User.Identity.Name).FirstOrDefault(); var history = new OrderProductHistory() { Id = Guid.NewGuid().ToString(), CreateDate = DateTime.Now, Notes = "Quan ly cong ty cap nhat", OrderId = orderProduct.OrderId, ProductId = orderProduct.ProductId, Quantity = quantity, StaffId = haiStaff.Id }; db.OrderProductHistories.Add(history); db.SaveChanges(); Utitl.Send("Đơn hàng " + orderProduct.HaiOrder.Code, "Đã cập nhật số lượng giao " + HaiUtil.ConvertProductQuantityText(orderProduct.ProductInfo.Quantity, quantity, orderProduct.ProductInfo.Unit) + "\nCho sản phẩm " + orderProduct.ProductInfo.PName, haiStaff.UserLogin, db, mongoHelp); return(Json(new { id = 1, money = (quantity * orderProduct.PerPrice).Value.ToString("C", Util.Cultures.VietNam), stt = stt }, JsonRequestBehavior.AllowGet)); }