public ActionResult ChangeHAWB(Guid?id, string ids, string hawb) { try { Shipping model = db.Shippings.Find(id); var model_hawb = db.HAWBs.Find(hawb); //list ShippingHAWBs List <Guid> lstShippingHAWBs = new List <Guid>(); var idShippingHAWB = Guid.NewGuid(); if (model.ShippingHAWBs.Where(n => n.HAWBId == model_hawb.Id).Count() == 0) { //tao moi hawb cho chuyen bay var ShippingHAWB = new ShippingHAWB() { Id = idShippingHAWB, AgencyId = user.Agency.Id, HAWBId = model_hawb.Id, CreatedAt = DateTime.Now, CreatedBy = user.Staff.UserName, ShippingId = model.Id, UpdatedAt = DateTime.Now, UpdatedBy = user.Staff.UserName }; db.ShippingHAWBs.Add(ShippingHAWB); } else { idShippingHAWB = model.ShippingHAWBs.Single(n => n.HAWBId == model_hawb.Id).Id; } //xu ly xoa ShippingHAWBDetails foreach (var item in ids.Split(',')) { var detail = db.ShippingHAWBDetails.Find(Guid.Parse(item)); lstShippingHAWBs.Add(detail.ShippingHAWBId.Value); detail.ShippingHAWBId = idShippingHAWB; detail.UpdatedAt = DateTime.Now; detail.UpdatedBy = user.Staff.UserName; } //xu ly xoa ShippingHAWBs foreach (var item in lstShippingHAWBs.Distinct()) { if (db.ShippingHAWBs.Find(item).ShippingHAWBDetails.Count == 0) { db.ShippingHAWBs.Remove(db.ShippingHAWBs.Find(item)); } } db.SaveChanges(); return(Json(new { message = new { mess = "Xử lý thành công !", weigh = db.ShippingHAWBDetails.Where(n => n.AgencyId == user.Agency.Id && n.ShippingHAWB.ShippingId == model.Id).Sum(n => n.ExportGood.Weigh) }, status = true }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { message = "Đã xảy ra lỗi trong quá trình xử lý dữ liệu", status = false }, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddShippingMaskItems(Guid?id, string ids) { try { Shipping model = db.Shippings.Find(id); var listHAWB = db.HAWBs.Where(n => n.AgencyId == user.Agency.Id && n.IsActive == true).OrderBy(n => n.CreatedAt); if (listHAWB != null && listHAWB.Count() > 0) { var hawmb = listHAWB.First(); //check exist in table ShippingHAWB var idShippingHAWB = Guid.NewGuid(); if (model.ShippingHAWBs.Where(n => n.HAWBId == hawmb.Id).Count() == 0) { //tao moi hawb cho chuyen bay var ShippingHAWB = new ShippingHAWB() { Id = idShippingHAWB, AgencyId = user.Agency.Id, HAWBId = hawmb.Id, CreatedAt = DateTime.Now, CreatedBy = user.Staff.UserName, ShippingId = model.Id, UpdatedAt = DateTime.Now, UpdatedBy = user.Staff.UserName }; db.ShippingHAWBs.Add(ShippingHAWB); } else { idShippingHAWB = model.ShippingHAWBs.Single(n => n.HAWBId == hawmb.Id).Id; } //them chi tiet kien chuyen bay foreach (var item in ids.Split(',')) { var ShippingHAWBDetail = new ShippingHAWBDetail() { AgencyId = user.Agency.Id, Id = Guid.NewGuid(), CreatedAt = DateTime.Now, CreatedBy = user.Staff.UserName, ExportGoodId = Guid.Parse(item), ShippingHAWBId = idShippingHAWB, ShippingMark = db.ExportGoods.Find(Guid.Parse(item)).ShippingMarkVN, UpdatedAt = DateTime.Now, UpdatedBy = user.Staff.UserName }; db.ShippingHAWBDetails.Add(ShippingHAWBDetail); } db.SaveChanges(); return(Json(new { message = new { mess = "Thêm kiện VN thành công !", weigh = db.ShippingHAWBDetails.Where(n => n.AgencyId == user.Agency.Id && n.ShippingHAWB.ShippingId == model.Id).Sum(n => n.ExportGood.Weigh) }, status = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { message = "Vui lòng cập nhật danh sách HAWB.", status = false }, JsonRequestBehavior.AllowGet)); } } catch { return(Json(new { message = "Đã xảy ra lỗi trong quá trình xử lý dữ liệu", status = false }, JsonRequestBehavior.AllowGet)); } }