public ActionResult AddMailer(string documentId, string mailerId) { var mailer = db.MM_Mailers.Find(mailerId); var document = db.MM_PackingList.Where(p => p.DocumentID == documentId).FirstOrDefault(); if (mailer == null) { return(Json(new { error = 1, msg = "Sai mã vận đơn" }, JsonRequestBehavior.AllowGet)); } if (mailer.CurrentStatusID != 2 && mailer.CurrentStatusID != 5) { return(Json(new { error = 1, msg = "Đơn không thể thực hiện" }, JsonRequestBehavior.AllowGet)); } if (document == null) { return(Json(new { error = 1, msg = "Sai thông tin" }, JsonRequestBehavior.AllowGet)); } if (document.StatusID != 0) { return(Json(new { error = 1, msg = "Bảng kê không thể thêm" }, JsonRequestBehavior.AllowGet)); } if (document.PostOfficeID != mailer.CurrentPostOfficeID) { return(Json(new { error = 1, msg = "Đơn không thuộc bưu cục bạn" }, JsonRequestBehavior.AllowGet)); } var checkDetail = db.MM_PackingListDetail.Where(p => p.DocumentID == document.DocumentID && p.MailerID == mailerId).FirstOrDefault(); if (checkDetail != null) { return(Json(new { error = 1, msg = "Đơn đã trong danh sách" }, JsonRequestBehavior.AllowGet)); } var checkDetailOther = db.MM_PackingListDetail.Where(p => p.MailerID == mailerId && p.StatusID == 12).FirstOrDefault(); if (checkDetailOther != null) { return(Json(new { error = 1, msg = "Đơn đã trong bảng kê khác" }, JsonRequestBehavior.AllowGet)); } var ins = new MM_PackingListDetail() { CreationDate = DateTime.Now, DocumentID = document.DocumentID, MailerID = mailer.MailerID, StatusID = 12, Notes = "" }; db.MM_PackingListDetail.Add(ins); db.SaveChanges(); mailer.CurrentStatusID = 12; mailer.LastUpdateDate = DateTime.Now; db.Entry(mailer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); HandleHistory.AddTracking(12, mailerId, mailer.CurrentPostOfficeID, "Hàng đang được đóng giói chuẩn bị vận chuyển"); var mailerDetail = db.MAILERPACKING_GETMAILER_ByID(document.DocumentID, mailer.MailerID).FirstOrDefault(); return(Json(new { error = 0, data = mailerDetail }, JsonRequestBehavior.AllowGet)); }
public ActionResult AddListMailer(List <string> mailers, string documentId) { var document = db.MM_PackingList.Where(p => p.DocumentID == documentId).FirstOrDefault(); if (document.StatusID != 0) { return(Json(new { error = 1, msg = "Bảng kê không thể thêm" }, JsonRequestBehavior.AllowGet)); } foreach (var item in mailers) { var mailer = db.MM_Mailers.Find(item); if (mailer == null) { continue; } if (mailer.CurrentStatusID != 2 && mailer.CurrentStatusID != 5) { continue; } if (document.PostOfficeID != mailer.CurrentPostOfficeID) { continue; } var checkDetail = db.MM_PackingListDetail.Where(p => p.DocumentID == document.DocumentID && p.MailerID == item).FirstOrDefault(); if (checkDetail != null) { continue; } var checkDetailOther = db.MM_PackingListDetail.Where(p => p.MailerID == item && p.StatusID == 12).FirstOrDefault(); if (checkDetailOther != null) { continue; } var ins = new MM_PackingListDetail() { CreationDate = DateTime.Now, DocumentID = document.DocumentID, MailerID = mailer.MailerID, StatusID = 12, Notes = "" }; db.MM_PackingListDetail.Add(ins); db.SaveChanges(); mailer.CurrentStatusID = 12; mailer.LastUpdateDate = DateTime.Now; db.Entry(mailer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); HandleHistory.AddTracking(12, item, mailer.CurrentPostOfficeID, "Hàng đang được đóng giói chuẩn bị vận chuyển"); } return(Json(new { error = 0 }, JsonRequestBehavior.AllowGet)); }