public bool InsertCompanyLead(b2bCompanyLead model) { #region set default model.RowFlag = 1; model.CreatedBy = "sa"; model.ModifiedBy = "sa"; model.ModifiedDate = DateTimeNow; model.CreatedDate = DateTimeNow; model.IsDelete = false; model.RowVersion = 1; #endregion qDB.b2bCompanyLeads.InsertOnSubmit(model); qDB.SubmitChanges(); IsResult = true; return(IsResult); }
public ActionResult SaveAssignLead(FormCollection form) { var b2bAssignLead = new b2bAssignLead(); svPurchase = new PurchaseService(); svCompany = new CompanyService(); int SupplierCompID = 0; try { int CompID = DataManager.ConvertToInteger(form["hidToCompID"]); var AssignLeadCode = form["hidAssignLeadCode"]; if (CompID > 0) { b2bAssignLead.ToCompID = CompID; } else { b2bAssignLead.ToCompID = null; } #region set ค่า b2bAssignLead b2bAssignLead.AssignLeadCode = AssignLeadCode; b2bAssignLead.AssignLeadName = form["hidProductName"]; b2bAssignLead.ToCompCode = form["hidToCompCode"]; b2bAssignLead.ToCompName = form["ToCompName"]; b2bAssignLead.ToAddrLine1 = form["ToAddress"]; b2bAssignLead.ToDistrictID = DataManager.ConvertToInteger(form["ToDistrictID"]); b2bAssignLead.ToContactName = form["ToContactName"]; b2bAssignLead.ToContactEmail = form["ToContactEmail"]; b2bAssignLead.ToContactTel = form["ToContactTel"]; //b2bAssignLead.IsSentEmail = DataManager.ConvertToBool(form["chkSendEmail"]); b2bAssignLead.OtherEmail = form["ToSendEmail"]; b2bAssignLead.IsDefaultLead = DataManager.ConvertToBool(form["chkSetDefaultLead"]); b2bAssignLead.IsRegisterMember = DataManager.ConvertToBool(form["chkRegMember"]); b2bAssignLead.CompLeadCount = DataManager.ConvertToShort(form["hidCountCompLead"]); #endregion #region Set Email var Email = ""; if (!string.IsNullOrEmpty(form["ToSendEmail"])) { Email = form["ToSendEmail"]; } else if (!string.IsNullOrEmpty(form["ToContactEmail"])) { Email = form["ToContactEmail"]; } b2bAssignLead.IsSentEmail = true; #endregion #region Save AssignLead int AssignLeadID = svPurchase.InsertAssignLead(b2bAssignLead); #endregion #region set and save b2bCompanyLead if (!string.IsNullOrEmpty(form["hidAllSupplierCompID"])) { string supplierID = form["hidAllSupplierCompID"]; string[] subSupplierCompID = supplierID.Split(','); for (int i = 0; i < subSupplierCompID.Length; i++) { var b2bCompanyLead = new b2bCompanyLead(); //Get CompID and CompCode SupplierCompID = DataManager.ConvertToInteger(subSupplierCompID[i]); var Company = svCompany.SelectData <b2bCompany>("CompID,CompCode", "CompID = " + SupplierCompID).First(); b2bCompanyLead.AssignLeadID = AssignLeadID; b2bCompanyLead.CompID = SupplierCompID; b2bCompanyLead.CompCode = Company.CompCode; svPurchase.InsertCompanyLead(b2bCompanyLead); } } #endregion #region Save b2bEmLead and b2bEmCompanyLead if (b2bAssignLead.IsDefaultLead == true) { #region set ค่า b2bEmLead var b2bEmLead = new b2bEmLead(); if (LogonCompID > 0) { svMember = new MemberService(); string sqlWhere = "IsDelete = 0 AND CompID = " + LogonCompID; var Member = svMember.SelectData <view_CompMember>("MemberID,CompID,UserName", sqlWhere).First(); b2bEmLead.MemberID = Member.MemberID; } var EmLeadCode = svPurchase.GenLeadCode(CompID, 2); b2bEmLead.EmLeadCode = EmLeadCode; b2bEmLead.EmLeadName = form["txtSetDefaultLead"]; b2bEmLead.EmLeadKeyword = form["hidProductName"]; b2bEmLead.LeadCount = DataManager.ConvertToShort(form["hidCountCompLead"]); #endregion #region Save EmLead then return EmLeadID int EmLeadID = svPurchase.InsertEmLead(b2bEmLead); #endregion #region set and save b2bEmCompanyLead if (!string.IsNullOrEmpty(form["hidAllSupplierCompID"])) { string supplierID = form["hidAllSupplierCompID"]; string[] subSupplierCompID = supplierID.Split(','); for (int i = 0; i < subSupplierCompID.Length; i++) { var b2bEmCompanyLead = new b2bEmCompanyLead(); SupplierCompID = DataManager.ConvertToInteger(subSupplierCompID[i]); b2bEmCompanyLead.EmLeadID = EmLeadID; b2bEmCompanyLead.CompID = SupplierCompID; b2bEmCompanyLead.EmCompLeadCode = svPurchase.GenLeadCode(SupplierCompID, 3); svPurchase.InsertEmCompanyLead(b2bEmCompanyLead); } } #endregion } #endregion #region Register Member if (b2bAssignLead.IsRegisterMember == true) { RegisterNewMember(form); } #endregion #region Send Email SendEmailToBuyer(Email, AssignLeadID, form, SupplierCompID); #endregion return(Json(true)); } catch (Exception ex) { CreateLogFiles(ex); return(Redirect("~/MyB2B/Purchase/CreateLead")); } }