예제 #1
0
 public ActionResult AddTranporterToContract(string id, string data)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         db.Delete<DC_LG_Contract_Transporter>(p => p.ContractID == id);
         if (!string.IsNullOrEmpty(data))
         {
             string[] arr = data.Split(',');
             foreach (string item in arr)
             {
                 var detail = new DC_LG_Contract_Transporter();
                 detail.ContractID = id;
                 detail.TransporterID = int.Parse(item);
                 detail.Note = "";
                 detail.UpdatedAt = DateTime.Now;
                 detail.CreatedAt = DateTime.Now;
                 detail.CreatedBy = currentUser.UserID;
                 detail.UpdatedBy = currentUser.UserID;
                 db.Insert<DC_LG_Contract_Transporter>(detail);
             }
         }
         return Json(new { success = true });
     }
     catch (Exception e) { return Json(new { success = false, message = e.Message }); }
     finally { db.Close(); }
 }
예제 #2
0
 public ActionResult Create(DC_LG_Contract item)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         if (!string.IsNullOrEmpty(item.ContractID) &&
             !string.IsNullOrEmpty(item.ContractName)
             )
         {
             var isExist = db.SingleOrDefault<DC_LG_Contract>("ContractID={0}", item.ContractID);
             var data = Request["TransporterID"];
             //string data = !string.IsNullOrEmpty(item.TransporterID) ? item.TransporterID : "";
             double n;
             item.StartDate = item.StartDate != null ? item.StartDate : DateTime.Now;
             item.EndDate = item.EndDate != null ? item.EndDate : DateTime.Now;
             item.DiscountPercent = double.TryParse(item.DiscountPercent.ToString(),out n) ? item.DiscountPercent/100 : 0;
             if(item.StartDate>item.EndDate)
             {
                 return Json(new { success = false, message = "Ngày kết thúc không thể lớn hơn " + item.StartDate });
             }
             item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
             item.DiscountPercent = !string.IsNullOrEmpty(item.DiscountPercent.ToString()) ? item.DiscountPercent : 0;
             if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
             {
                 if (isExist != null)
                     return Json(new { success = false, message = "Mã hợp đồng đã tồn tại" });
                 item.ContractName = !string.IsNullOrEmpty(item.ContractName) ? item.ContractName : "";
                 item.CreatedAt = DateTime.Now;
                 item.UpdatedAt = DateTime.Parse("1900-01-01");
                 item.CreatedBy = currentUser.UserID;
                 db.Insert(item);
                 db.Delete<DC_LG_Contract_Transporter>(p => p.ContractID ==item.ContractID);
                 if (!string.IsNullOrEmpty(data))
                 {
                     string[] arr = data.Split(',');
                     foreach (string ite in arr)
                     {
                         var detail = new DC_LG_Contract_Transporter();
                         detail.ContractID = item.ContractID;
                         detail.TransporterID = int.Parse(ite);
                         detail.Note = "";
                         detail.UpdatedAt = DateTime.Now;
                         detail.CreatedAt = DateTime.Now;
                         detail.CreatedBy = currentUser.UserID;
                         detail.UpdatedBy = currentUser.UserID;
                         db.Insert<DC_LG_Contract_Transporter>(detail);
                     }
                 }
                 return Json(new { success = true, ContractID = item.ContractID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt, });
             }
             else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
             {
                 item.ContractName = !string.IsNullOrEmpty(item.ContractName) ? item.ContractName : "";
                 item.CreatedBy = isExist.CreatedBy;
                 item.CreatedAt = isExist.CreatedAt;
                 item.UpdatedAt = DateTime.Now;
                 item.UpdatedBy = currentUser.UserID;
                 db.Update(item);
                 db.Delete<DC_LG_Contract_Transporter>(p => p.ContractID == item.ContractID);
                 if (!string.IsNullOrEmpty(data))
                 {
                     string[] arr = data.Split(',');
                     foreach (string ite in arr)
                     {
                         var detail = new DC_LG_Contract_Transporter();
                         detail.ContractID = item.ContractID;
                         detail.TransporterID = int.Parse(ite);
                         detail.Note = "";
                         detail.UpdatedAt = DateTime.Now;
                         detail.CreatedAt = DateTime.Now;
                         detail.CreatedBy = currentUser.UserID;
                         detail.UpdatedBy = currentUser.UserID;
                         db.Insert<DC_LG_Contract_Transporter>(detail);
                     }
                 }
                 return Json(new { success = true });
             }
             else
                 return Json(new { success = false, message = "Bạn không có quyền" });
         }
         else
         {
             return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
         }
     }
     catch (Exception e)
     {
         log.Error("Contract - Create - " + e.Message);
         return Json(new { success = false, message = e.Message });
     }
     finally { db.Close(); }
 }