public static void Delete(int id) { Entity.Contact contact = Get(id); if (contact != null) { DbContextHelper.DbContext.DeleteObject(contact); DbContextHelper.DbContext.SaveChanges(); } }
protected void btnSave_Click(object sender, EventArgs e) { decimal balance = 0; CRM.Data.Entities.Contact contact = null; int clientID = Core.SessionHelper.getClientId(); int contactID = 0; Page.Validate("contact"); if (!Page.IsValid) { return; } contactID = Convert.ToInt32(hdId.Value); if (contactID == 0) { contact = new CRM.Data.Entities.Contact(); contact.ClientID = clientID; // TO-DO: remove trigger in database contact.IsActive = true; try { int userID = SessionHelper.getUserId(); CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID); string email = secUser.Email; string password = SecurityManager.Decrypt(secUser.emailPassword); string url = "https://" + secUser.emailHost + "/EWS/Exchange.asmx"; ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.Credentials = new WebCredentials(email, password); service.Url = new Uri(url); Microsoft.Exchange.WebServices.Data.Contact outlookContact = new Microsoft.Exchange.WebServices.Data.Contact(service); outlookContact.GivenName = txtFirstName.Text; outlookContact.Surname = txtLastName.Text; outlookContact.FileAsMapping = FileAsMapping.SurnameCommaGivenName; outlookContact.EmailAddresses[EmailAddressKey.EmailAddress1] = txtEmail.Text; outlookContact.PhoneNumbers[PhoneNumberKey.HomePhone] = txtPhone.Text; outlookContact.Save(); } catch (Exception ex) { } } else { contact = ContactManager.Get(contactID); } if (contact != null) { contact.CompanyName = txtCompanyName.Text; contact.DepartmentName = txtDepartmentName.Text; contact.ContactTitle = txtContactTile.Text; contact.FirstName = txtFirstName.Text; contact.LastName = txtLastName.Text; contact.ContactName = txtFirstName.Text + " " + txtLastName.Text; contact.Address1 = txtAddress1.Text; contact.Address2 = txtAddress2.Text; contact.Mobile = txtMobile.Text; contact.Phone = txtPhone.Text; contact.Email = txtEmail.Text; contact.Fax = txtContactFax.Text; contact.County = txtCounty.Text; //contact.ClaimName = txtClaimName.Text; if (ddlState.SelectedIndex > 0) { contact.StateID = Convert.ToInt32(ddlState.SelectedValue); } if (ddlCity.SelectedIndex > 0) { contact.CityID = Convert.ToInt32(ddlCity.SelectedValue); } if (ddlContactType.SelectedIndex > 0) { contact.CategoryID = Convert.ToInt32(ddlContactType.SelectedValue); } if (ddlLossZip.SelectedIndex > 0) { contact.ZipCodeID = Convert.ToInt32(ddlLossZip.SelectedValue); } decimal.TryParse(txtBalance.Text, out balance); contact.Balance = balance; try { ContactManager.Save(contact); pnlContact.Visible = true; pnlContactDetail.Visible = false; loadData(null); } catch (Exception ex) { EmailHelper.emailError(ex); } } }
protected void gvContact_RowCommand(object sender, GridViewCommandEventArgs e) { int contactID = 0; CRM.Data.Entities.Contact contact = null; int stateID = 0; if (e.CommandName == "DoEdit") { hdId.Value = e.CommandArgument.ToString(); contactID = Convert.ToInt32(e.CommandArgument); pnlContact.Visible = false; pnlContactDetail.Visible = true; contact = ContactManager.Get(contactID); if (contact != null) { txtAddress1.Text = contact.Address1; txtAddress2.Text = contact.Address2; txtCompanyName.Text = contact.CompanyName; txtDepartmentName.Text = contact.DepartmentName; txtContactTile.Text = contact.ContactTitle; txtEmail.Text = contact.Email; txtFirstName.Text = contact.FirstName; txtLastName.Text = contact.LastName; txtMobile.Text = contact.Mobile; txtPhone.Text = contact.Phone; txtBalance.Text = contact.Balance.ToString(); //txtClaimName.Text = contact.ClaimName; txtCounty.Text = contact.County; txtContactFax.Text = contact.Fax; bindContactTypes(); bindStates(); stateID = contact.StateID ?? 0; if (stateID > 0) { ddlState.SelectedValue = stateID.ToString(); CollectionManager.FillCollection(ddlCity, "CityId", "CityName", City.GetAll(stateID)); } if (contact.CityID != null && contact.CityID > 0) { try { ddlCity.SelectedValue = contact.CityID.ToString(); } catch { } CollectionManager.FillCollection(ddlLossZip, "ZipCodeID", "ZipCode", ZipCode.getByCityID((int)contact.CityID)); } if (contact.ZipCodeID != null && contact.ZipCodeID > 0) { try { ddlLossZip.SelectedValue = contact.ZipCodeID.ToString(); } catch { } } if (contact.CategoryID != null) { try { ddlContactType.SelectedValue = contact.CategoryID.ToString(); } catch (Exception ex) { Core.EmailHelper.emailError(ex); } } } } else if (e.CommandName == "DoDelete") { contactID = Convert.ToInt32(e.CommandArgument); try { contact = ContactManager.Get(contactID); contact.IsActive = false; contact = ContactManager.Save(contact); loadData(null); } catch (Exception ex) { EmailHelper.emailError(ex); } } }
public static Contact UpdateContact(Contact contact) { int contactId = contact.ContactID; Contact objContact = DbContextHelper.DbContext.Contact.First(x => x.ContactID == contactId); objContact.ContactName = contact.ContactName; DbContextHelper.DbContext.SaveChanges(); return objContact; }
public static Contact Update(Contact contact) { int contactId=contact.ContactID; Contact objContact = DbContextHelper.DbContext.Contact.First(x => x.ContactID == contactId); objContact.ContactName = contact.ContactName; objContact.Address1 = contact.Address1; objContact.CityName = contact.CityName; objContact.State = contact.State; objContact.ZipCode = contact.ZipCode; objContact.Phone = contact.Phone; DbContextHelper.DbContext.SaveChanges(); return contact; }
public static Contact SaveContact(Contact contact) { DbContextHelper.DbContext.Add(contact); DbContextHelper.DbContext.SaveChanges(); return contact; }
public static int Save1(Contact contact) { int contactID = 0; Contact lcontact = null; if (contact.ContactID == 0) { lcontact = new Contact(); DbContextHelper.DbContext.Add(lcontact); } else { lcontact = Get(contact.ContactID); } if (lcontact != null) { lcontact.Address1 = contact.Address1; lcontact.Address2 = contact.Address2; lcontact.CategoryID = contact.CategoryID; lcontact.Balance = contact.Balance; lcontact.CarrierID = contact.CarrierID; lcontact.CityID = contact.CityID; lcontact.ClaimName = contact.ClaimName; lcontact.ClientID = contact.ClientID; lcontact.CompanyName = contact.CompanyName; lcontact.County = contact.County; lcontact.Email = contact.Email; lcontact.FirstName = contact.FirstName; lcontact.LastName = contact.LastName; lcontact.Mobile = contact.Mobile; lcontact.Phone = contact.Phone; lcontact.StateID = contact.StateID; lcontact.ZipCodeID = contact.ZipCodeID; lcontact.CarrierID = contact.CarrierID; lcontact.ContactTitle = contact.ContactTitle; lcontact.DepartmentName = contact.DepartmentName; lcontact.IsPrimary = contact.IsPrimary; DbContextHelper.DbContext.SaveChanges(); contactID = contact.ContactID; } return contactID; }
public static Contact Save(Contact contact) { if (contact.ContactID == 0) { DbContextHelper.DbContext.Add(contact); } DbContextHelper.DbContext.SaveChanges(); return contact; }
public static Contact GetAllContact(int clientID) { Contact contacts = null; contacts = new Contact(); contacts = (from x in DbContextHelper.DbContext.Contact where x.ClientID == clientID && x.IsActive == true select x) as Contact; return contacts; }
protected void fillForm(CRM.Data.Entities.Contact contact) { int stateID = 0; int cityID = 0; int zipCodeID = 0; this.txtFirstName.Text = contact.FirstName; this.txtLastName.Text = contact.LastName; this.txtContactEmail.Text = contact.Email; this.txtContactPhone.Text = contact.Phone; this.txtMobilePhone.Text = contact.Mobile; this.txtContactTile.Text = contact.ContactTitle; this.txtDepartmentName.Text = contact.DepartmentName; this.txtCompanyName.Text = contact.CompanyName; cbxPrimary.Checked = contact.IsPrimary ?? false; txtContactFax.Text = contact.Fax; txtAddress1.Text = contact.Address1; txtAddress2.Text = contact.Address2; ddlContactType.SelectedValue = (contact.CategoryID ?? 0).ToString(); stateID = contact.StateID ?? 0; if (stateID > 0) { ddlState.SelectedValue = stateID.ToString(); CollectionManager.FillCollection(ddlCity, "CityId", "CityName", City.GetAll(stateID)); } cityID = contact.CityID ?? 0; if (cityID > 0) { try { ddlCity.SelectedValue = cityID.ToString(); } catch { } CollectionManager.FillCollection(ddlLossZip, "ZipCodeID", "ZipCode", ZipCode.getByCityID(cityID)); } zipCodeID = contact.ZipCodeID ?? 0; if (zipCodeID > 0) { try { ddlLossZip.SelectedValue = zipCodeID.ToString(); } catch { } } if (contact.CategoryID != null) { try { ddlContactType.SelectedValue = contact.CategoryID.ToString(); } catch (Exception ex) { Core.EmailHelper.emailError(ex); } } }
protected void btnSave_Click(object sender, EventArgs e) { decimal balance = 0; CRM.Data.Entities.Contact contact = null; int clientID = Core.SessionHelper.getClientId(); int contactID = 0; Page.Validate("contact"); if (!Page.IsValid) return; contactID = Convert.ToInt32(hdId.Value); if (contactID == 0) { contact = new CRM.Data.Entities.Contact(); contact.ClientID = clientID; // TO-DO: remove trigger in database contact.IsActive = true; try { int userID = SessionHelper.getUserId(); CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID); string email = secUser.Email; string password = SecurityManager.Decrypt(secUser.emailPassword); string url = "https://" + secUser.emailHost + "/EWS/Exchange.asmx"; ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.Credentials = new WebCredentials(email, password); service.Url = new Uri(url); Microsoft.Exchange.WebServices.Data.Contact outlookContact = new Microsoft.Exchange.WebServices.Data.Contact(service); outlookContact.GivenName = txtFirstName.Text; outlookContact.Surname = txtLastName.Text; outlookContact.FileAsMapping = FileAsMapping.SurnameCommaGivenName; outlookContact.EmailAddresses[EmailAddressKey.EmailAddress1] = txtEmail.Text; outlookContact.PhoneNumbers[PhoneNumberKey.HomePhone] = txtPhone.Text; outlookContact.Save(); } catch (Exception ex) { } } else contact = ContactManager.Get(contactID); if (contact != null) { contact.CompanyName = txtCompanyName.Text; contact.DepartmentName = txtDepartmentName.Text; contact.ContactTitle = txtContactTile.Text; contact.FirstName = txtFirstName.Text; contact.LastName = txtLastName.Text; contact.ContactName = txtFirstName.Text + " " + txtLastName.Text; contact.Address1 = txtAddress1.Text; contact.Address2 = txtAddress2.Text; contact.Mobile = txtMobile.Text; contact.Phone = txtPhone.Text; contact.Email = txtEmail.Text; contact.Fax = txtContactFax.Text; contact.County = txtCounty.Text; //contact.ClaimName = txtClaimName.Text; if (ddlState.SelectedIndex > 0) contact.StateID = Convert.ToInt32(ddlState.SelectedValue); if (ddlCity.SelectedIndex > 0) contact.CityID = Convert.ToInt32(ddlCity.SelectedValue); if (ddlContactType.SelectedIndex > 0) contact.CategoryID = Convert.ToInt32(ddlContactType.SelectedValue); if (ddlLossZip.SelectedIndex > 0) contact.ZipCodeID = Convert.ToInt32(ddlLossZip.SelectedValue); decimal.TryParse(txtBalance.Text, out balance); contact.Balance = balance; try { ContactManager.Save(contact); pnlContact.Visible = true; pnlContactDetail.Visible = false; loadData(null); } catch (Exception ex) { EmailHelper.emailError(ex); } } }