public ActionResult Update(string key, string codeLogin)
 {
     try
     {
         if (key != Keyapi)
         {
             return(Json(0, JsonRequestBehavior.AllowGet));
         }
         var model = _da.GetById(ItemId);
         if (model == null)
         {
             return(Json(1, JsonRequestBehavior.AllowGet));
         }
         UpdateModel(model);
         model.IsActive = false;
         model.Status   = (int)StatusWarehouse.Pending;
         var dateCreated = Request["DateCreated_"];
         var date        = ConvertDate.StringToDate(dateCreated);
         var lst         = model.FreightWarehouses.Where(c => c.IsDelete == false).ToList();
         var lstNew      = GetListImportItem(codeLogin, date);
         //xóa
         var result1 = lst.Where(p => lstNew.All(p2 => p2.ProductID != p.ProductID)).ToList();
         foreach (var i in result1)
         {
             i.IsDelete = true;
         }
         //sửa
         foreach (var i in lst)
         {
             var j = lstNew.FirstOrDefault(c => c.ProductID == i.ProductID);
             if (j == null)
             {
                 continue;
             }
             i.Quantity = j.Quantity;
             i.Price    = j.Price;
             i.Date     = j.Date;
         }
         //thêm mới
         var result2 = lstNew.Where(p => lst.All(p2 => p2.ProductID != p.ProductID)).ToList();
         model.FreightWarehouses.AddRange(result2);
         model.DateImport = ConvertDate.TotalSeconds(date);
         model.Note       = HttpUtility.UrlDecode(model.Note);
         _da.Save();
         return(Json(1, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(0, JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult Add(string key, string codeLogin, string port = ":4000")
        {
            var model = new StorageFreightWarehouse();

            try
            {
                if (key != Keyapi)
                {
                    return(Json(0, JsonRequestBehavior.AllowGet));
                }
                UpdateModel(model);
                model.Note = HttpUtility.UrlDecode(model.Note);
                var dateCreated = Request["DateCreated_"];
                var date        = ConvertDate.StringToDate(dateCreated);
                model.FreightWarehouses = GetListImportItem(codeLogin, date);
                //model.DateImport = date.TotalSeconds();
                model.Status      = (int)StatusWarehouse.Pending;
                model.DateCreated = ConvertDate.TotalSeconds(DateTime.Now);
                model.Code        = DateTime.Now.ToString("yyMMddHHmm");
                model.AgencyId    = Agencyid();
                model.IsDelete    = false;
                _da.Add(model);
                _da.Save();
                var user    = _dnUserDa.GetById(model.UserID ?? new Guid());
                var jsonnew = new StorageFreightWarehouseItemNew()
                {
                    ID       = model.ID,
                    Note     = model.Note,
                    Fullname = user.LoweredUserName,
                };
                var json = new JavaScriptSerializer().Serialize(jsonnew);
                Node(port + "/addnotify/" + json);
                return(Json(model.ID, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(0, JsonRequestBehavior.AllowGet));
            }
        }