public ActionResult AddBuylead(FormCollection form, List <string> BuyleadImgPath, List <string> BuyLeadImgOldfile) { var svBuylead = new BuyleadService(); b2bBuylead model = new b2bBuylead(); try { #region Set Buylead Model var date = form["BuyleadExpire"]; model.BuyleadName = form["BuyleadName"]; model.BuyleadCode = form["BuyleadCode"]; model.BuyleadType = DataManager.ConvertToInteger(form["BuyleadType"]); //model.BuyleadExpDate = DateTime.Parse(form["BuyleadExpire"]); var d = form["BuyleadExpire"]; DateTime t = DataManager.ConvertToDateTime(d); model.BuyleadExpDate = t; model.BuyleadKeyword = form["BuyleadKeyword"]; if (form["BuyleadDetail"] != "") { model.BuyleadDetail = form["BuyleadDetail"]; } model.Qty = DataManager.ConvertToDecimal(form["Qty"]); model.QtyUnit = form["QtyUnit"]; if (BuyleadImgPath != null) { model.BuyleadIMGPath = BuyleadImgPath[0]; } model.CompID = LogonCompID; model.CateLV1 = Convert.ToInt32(form["Catecode"].Substring(9, 4)); model.CateLV2 = Convert.ToInt32(form["Catecode"].Substring(14, 4)); model.CateLV3 = Convert.ToInt32(form["CateLV3"]); model.IsShow = true; model.IsJunk = false; #region Check ว่าเป็น OutSource Add หรือ User Add model.RowFlag = (LogonServiceType >= 9) ? (short)2 : (short)6; #endregion if (LogonServiceType >= 9) { model.CompCode = LogonCompCode; } #region Company Information model.BuyleadCompanyName = form["CompName"]; model.BuyleadContactPerson = form["ContactName"]; model.BuyleadContactPosition = form["Position"]; model.BuyleadTel = form["Phone"]; model.BuyleadEmail = form["Email"]; if (form["Mobile"] != "") { model.BuyleadMobilePhone = form["Mobile"]; } if (form["Fax"] != "") { model.BuyleadFax = form["Fax"]; } if (form["Address"] != "") { model.BuyleadAddressLine1 = form["Address"]; } model.DistrictID = Convert.ToInt32(form["District"]); model.ProvinceID = Convert.ToInt32(form["Province"]); if (form["Postal"] != "") { model.BuyleadPostelCode = form["Postal"]; } #endregion #endregion model.ContactCount = 0; model.ListNo = 0; model.ViewCount = 0; model.CreatedDate = DateTime.Now; model.ModifiedDate = DateTime.Now; model.CreatedBy = "sa"; model.ModifiedBy = "sa"; if (form["BuyleadID"] == null) { #region Insert Buylead And BuyleadImage svBuylead.InsertBuylead(model, LogonCompID); #endregion } else { #region Update Data if (Convert.ToInt32(form["RowFlag"]) == 3) { model.RowFlag = 2; } model.BuyleadID = Convert.ToInt32(form["BuyleadID"]); svBuylead.UpdateBuylead(model); #endregion } var Floder = 0; if (LogonCompID > 0) { Floder = LogonCompID; } else { Floder = 2; } #region Save Image Files if (BuyleadImgPath != null) { imgManager = new FileHelper(); imgManager.DirPath = "Buylead/" + Floder + "/" + model.BuyleadID; imgManager.DirTempPath = "Temp/Buylead/" + Floder; SaveFileImage( imgManager.DirTempPath, imgManager.DirPath, BuyleadImgPath, 150, 450); if (BuyLeadImgOldfile != null && (BuyleadImgPath[0] != BuyLeadImgOldfile[0])) { DeleteFileImage(imgManager.DirPath, BuyLeadImgOldfile, BuyleadImgPath); } } #endregion } catch (Exception ex) { CreateLogFiles(ex); } return(Json(new { IsResult = svBuylead.IsResult, MsgError = GenerateMsgError(svBuylead.MsgError), ID = model.BuyleadID })); }