public ActionResult Create(SAL02_Contacts modelContact, string submitCustomertoAppointment, string submitCustomer, string submitCustomerToProject) { try { ModelState.Remove("SalContId"); if (!modelContact.EmailExists) { modelContact.SalContEmail = BusinessConstants.NA; ModelState.Remove("SalContEmail"); } if (ModelState.IsValid) { modelContact.SalContPhone = DataAccess.Entity.Common.FormatPhoneText(modelContact.SalContPhone); modelContact.SalContMobile = DataAccess.Entity.Common.FormatPhoneText(modelContact.SalContMobile); modelContact.SalContFax = DataAccess.Entity.Common.FormatPhoneText(modelContact.SalContFax); var result = CustomerDAL.saveCustomer(modelContact); if (result > 0) { Session["ContID"] = ""; Session.Remove("ContID"); if (submitCustomertoAppointment != null) { return(RedirectToAction("create", "appointments", new { id = result, assign = "1" })); } else if (submitCustomerToProject != null && submitCustomerToProject == "save") { return(RedirectToAction("index", "project")); } else if (submitCustomer != null) { return(RedirectToAction("index", "customers")); } } else { ModelState.AddModelError(String.Empty, BusinessConstants.duplicateRecord); LoadCombos(); ViewBag.Title = string.IsNullOrWhiteSpace(Convert.ToString(modelContact.SalContId)) ? BusinessConstants.titleNewCustomer : BusinessConstants.titleEditCustomer; return(View(modelContact)); } } LoadCombos(); ViewBag.Title = string.IsNullOrWhiteSpace(Convert.ToString(modelContact.SalContId)) ? BusinessConstants.titleNewCustomer : BusinessConstants.titleEditCustomer; return(View()); } catch (Exception ex) { ModelState.AddModelError(String.Empty, ex.Message + BusinessConstants.contactAdmin); LoadCombos(); ViewBag.Title = string.IsNullOrWhiteSpace(Convert.ToString(modelContact.SalContId)) ? BusinessConstants.titleNewCustomer : BusinessConstants.titleEditCustomer; return(View()); } }
public static int saveCustomer(SAL02_Contacts modelContact) { int result = 0; try { string spName = string.Empty; List <SqlParameter> parametersList = new List <SqlParameter>(); if (modelContact.SalContId > 0) { parametersList.Add(new SqlParameter("@ContId", modelContact.SalContId)); spName = "spATL_CRM_Cont_Upd"; } else { spName = "spATL_CRM_Cont_Ins"; } parametersList.Add(new SqlParameter("@CompId", modelContact.SalCompId)); parametersList.Add(new SqlParameter("@FName", modelContact.SalContFirstName)); parametersList.Add(new SqlParameter("@LName", modelContact.SalContLastName)); parametersList.Add(new SqlParameter("@Address", modelContact.SalContAddress)); parametersList.Add(new SqlParameter("@City", modelContact.SalContCity)); parametersList.Add(new SqlParameter("@State", modelContact.SalContState)); parametersList.Add(new SqlParameter("@ZipCode", modelContact.SalContZip)); parametersList.Add(new SqlParameter("@Phone", modelContact.SalContPhone)); parametersList.Add(new SqlParameter("@Ext", modelContact.SalContPhoneExt)); parametersList.Add(new SqlParameter("@Fax", modelContact.SalContFax)); parametersList.Add(new SqlParameter("@Mobile", modelContact.SalContMobile)); parametersList.Add(new SqlParameter("@EMail", modelContact.SalContEmail)); parametersList.Add(new SqlParameter("@ActiveFlag", modelContact.SalContActiveFlag)); parametersList.Add(new SqlParameter("@LedSource", modelContact.LedSourceId)); DataTable resultSet = (SqlHelper.ExecuteDataset(_myConnection, CommandType.StoredProcedure, spName, parametersList.ToArray()).Tables[0]); result = Convert.ToInt32(resultSet.Rows[0]["ID"]); } catch (Exception ex) { } return(result); }
public static List <SAL02_Contacts> getCustomerCollection(dynamic dataSet) { List <SAL02_Contacts> lstContacts = new List <SAL02_Contacts>(); foreach (var record in dataSet) { SAL02_Contacts contacts = new SAL02_Contacts(); if (!record["SalContId"].Equals(DBNull.Value)) { contacts.SalContId = Convert.ToInt32(record["SalContId"]); } if (!record["SalContFirstName"].Equals(DBNull.Value)) { contacts.SalContFirstName = Common.ToTitleCase(Convert.ToString(record["SalContFirstName"])); } if (!record["SalContLastName"].Equals(DBNull.Value)) { contacts.SalContLastName = Common.ToTitleCase(Convert.ToString(record["SalContLastName"])); } if (!record["SalContAddress"].Equals(DBNull.Value)) { contacts.SalContAddress = Convert.ToString(record["SalContAddress"]); } if (!record["SalContCity"].Equals(DBNull.Value)) { contacts.SalContCity = Convert.ToString(record["SalContCity"]); } if (!record["SalContState"].Equals(DBNull.Value)) { contacts.SalContState = Convert.ToString(record["SalContState"]); } if (!record["SalContZip"].Equals(DBNull.Value)) { contacts.SalContZip = Convert.ToString(record["SalContZip"]); } if (record.Table.Columns.Contains("SalContPhone") && !record["SalContPhone"].Equals(DBNull.Value)) { contacts.SalContPhone = Convert.ToString(record["SalContPhone"]); } if (record.Table.Columns.Contains("SalContPhoneExt") && !record["SalContPhoneExt"].Equals(DBNull.Value)) { contacts.SalContPhoneExt = Convert.ToString(record["SalContPhoneExt"]); } if (record.Table.Columns.Contains("SalContFax") && !record["SalContFax"].Equals(DBNull.Value)) { contacts.SalContFax = Convert.ToString(record["SalContFax"]); } if (record.Table.Columns.Contains("SalContMobile") && !record["SalContMobile"].Equals(DBNull.Value)) { contacts.SalContMobile = Convert.ToString(record["SalContMobile"]); } if (record.Table.Columns.Contains("SalContEmail") && !record["SalContEmail"].Equals(DBNull.Value)) { contacts.SalContEmail = Convert.ToString(record["SalContEmail"]); } if (record.Table.Columns.Contains("SalCompId") && !record["SalCompId"].Equals(DBNull.Value)) { contacts.SalCompId = Convert.ToString(record["SalCompId"]); } if (record.Table.Columns.Contains("SalContActiveFlag") && !record["SalContActiveFlag"].Equals(DBNull.Value)) { contacts.SalContActiveFlag = Convert.ToString(record["SalContActiveFlag"]); } if (record.Table.Columns.Contains("LedSourceId") && !record["LedSourceId"].Equals(DBNull.Value)) { contacts.LedSourceId = Convert.ToInt32(record["LedSourceId"]); } lstContacts.Add(contacts); } return(lstContacts); }