public ActionResult DeleteConfirmed(int id) { CoContacts coContacts = db.CoContacts.Find(id); db.CoContacts.Remove(coContacts); db.SaveChanges(); return(RedirectToAction("Index")); }
private bool EditContact(GetContactInfoByContactID_Result Model) { int siteCoID = siteusercompanyid; CommonRepository repo = new CommonRepository(); CoContactCompanies company = null; if (!string.IsNullOrWhiteSpace(Model.ContactCompany)) { company = repo.AddCompany(siteCoID, Model.ContactCompany); } if (company == null) { company = new CoContactCompanies() { ContactCoID = 0 }; } CoContacts contact = db.CoContacts .Include(p => p.CoContactAddresses) .Include(p => p.CoContactEmails) .Where(p => p.ContactID == Model.ViewID).FirstOrDefault(); contact.ContactID = Model.ViewID; contact.SiteCoID = siteCoID; contact.ContactTypeID = Model.ContactTypeID ?? 0; contact.ContactSubtypeID = Model.ContactSubtypeID ?? 0; contact.ContactStatusID = Model.ContactStatusID; contact.ContactFirstName = Model.ContactFirst; contact.ContactLastName = Model.ContactLast; contact.ContactCoID = company.ContactCoID; contact.ModifiedDate = DateTime.Now; contact.ContactManager = Model.ContactOwnerID; contact.Custom1 = Model.Custom1; contact.Custom2 = Model.Custom2; contact.Custom3 = Model.Custom3; contact.Custom4 = Model.Custom4; db.SaveChanges(); repo.UpdatePhone(Model.ViewID, (int)EnumWrapper.PhoneTypes.Mobile, Model.Mobile, true); repo.UpdatePhone(Model.ViewID, (int)EnumWrapper.PhoneTypes.Phone, Model.Phone, true); repo.UpdateEmail(Model.ViewID, Model.ContactEmail, true); repo.UpdateAddress(Model.ViewID, new CoContactAddresses() { Address1 = Model.ContactAddress1, Address2 = Model.ContactAddress2, City = Model.ContactCity, State = Model.ContactState, Zip = Model.ContactZip, CountryID = Model.CountryID, AddressTypeID = (int)EnumWrapper.AddressTypes.Main }); return(true); }
public ActionResult Edit(int id) { var siteCoID = siteusercompanyid; ViewBag.ContactCo = new SelectList(db.GetContactCompaniesBySiteCoID(siteCoID), "ViewID", "Company", siteCoID); ViewBag.Country = new SelectList(new CommonRepository().GetCountries(), "CountryID", "Country"); ViewBag.ContactType = new SelectList(db.GetPeopleTypesBySiteCoID(siteCoID), "ViewID", "Name", siteCoID); ViewBag.ContactSubType = new SelectList(db.GetContactSubTypesBySiteCoID(siteCoID), "ViewID", "Type", siteCoID); ViewBag.ContactStatus = new SelectList(db.SiteContactStatus.OrderBy(p => p.StatusOrder), "StatusID", "Status"); ViewBag.Owner = new SelectList(db.GetCoUsersBySiteCoID(siteCoID), "UserID", "User", siteCoID); ViewBag.ContactCustoms = db.GetContactCustomFieldsBySiteCoID(siteCoID).FirstOrDefault(); ViewBag.siteuserid = siteuserid; GetContactInfoByContactID_Result Model = new GetContactInfoByContactID_Result(); CoContacts contact = db.CoContacts .Include(p => p.CoContactAddresses) .Include(p => p.CoContactEmails) .Where(p => p.ContactID == id).FirstOrDefault(); CoContactAddresses address = contact.CoContactAddresses.Where(p => p.ContactID == id).FirstOrDefault() ?? new CoContactAddresses(); if (contact != null) { Model = new GetContactInfoByContactID_Result() { ContactAddress1 = address.Address1, ContactAddress2 = address.Address2, ContactCity = address.City, CountryID = address.CountryID, ContactState = address.State, ContactZip = address.Zip, ContactCompany = contact.CoContactCompanies != null ? contact.CoContactCompanies.ContactCoName : "", ViewID = contact.ContactID, ContactEmail = contact.CoContactEmails.Any() ? contact.CoContactEmails.Select(p => p.EmailAddress).FirstOrDefault() : "", ContactFirst = contact.ContactFirstName, ContactLast = contact.ContactLastName, Mobile = contact.CoContactPhones.Any() ? contact.CoContactPhones.Where(p => p.PhoneTypeID == 2).Select(p => p.Phone).FirstOrDefault() : "", Phone = contact.CoContactPhones.Any() ? contact.CoContactPhones.Where(p => p.PhoneTypeID == 1).Select(p => p.Phone).FirstOrDefault() : "", ContactStatusID = contact.ContactStatusID, ContactTypeID = contact.ContactTypeID, ContactOwnerID = contact.ContactManager, ContactSubtypeID = contact.ContactSubtypeID, FaceBook = contact.FaceBook, LinkedIn = contact.LinkedIn, Skype = contact.Skype, Custom1 = contact.Custom1, Custom2 = contact.Custom2, Custom3 = contact.Custom3, Custom4 = contact.Custom4 }; } return(View("_Edit", Model)); }
// GET: Mobile/mContactInfo/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CoContacts coContacts = db.CoContacts.Find(id); if (coContacts == null) { return(HttpNotFound()); } return(View(coContacts)); }
public ActionResult Edit(int id) { ViewBag.ContactCo = new SelectList(db.CoContactCompanies.Where(p => p.SiteCoID == siteusercompanyid).OrderBy(p => p.ContactCoName), "ContactCoID", "ContactCoName"); ViewBag.Country = new SelectList(db.SiteCountries.OrderBy(p => p.Country), "CountryID", "Country"); ViewBag.ContactType = new SelectList(db.CoContactTypes.Where(p => p.SiteCoID == siteusercompanyid).OrderBy(p => p.ContactTypeOrder), "ContactTypeID", "ContactTypeName"); ViewBag.ContactStatus = new SelectList(db.SiteContactStatus.OrderBy(p => p.StatusOrder), "StatusID", "Status"); ViewBag.Owner = new SelectList(db.SiteUsers.Where(p => p.SiteCoID == siteusercompanyid).OrderBy(p => p.UserDisplayName), "SiteUserID", "UserDisplayName", siteuserid); ViewBag.siteuserid = siteuserid; PeopleModels.NewContact Model = new PeopleModels.NewContact(); CoContacts contact = db.CoContacts .Include(p => p.CoContactAddresses) .Include(p => p.CoContactEmails) .Where(p => p.ContactID == id).FirstOrDefault(); CoContactAddresses address = contact.CoContactAddresses.Where(p => p.ContactID == id).FirstOrDefault() ?? new CoContactAddresses(); if (contact != null) { Model = new PeopleModels.NewContact() { Address1 = address.Address1, Address2 = address.Address2, City = address.City, CountryID = address.CountryID, State = address.State, Zip = address.Zip, Company = contact.CoContactCompanies != null ? contact.CoContactCompanies.ContactCoName : "", ContactID = contact.ContactID, Email = contact.CoContactEmails.Any() ? contact.CoContactEmails.Select(p => p.EmailAddress).FirstOrDefault() : "", First = contact.ContactFirstName, Last = contact.ContactLastName, Mobile = contact.CoContactPhones.Any() ? contact.CoContactPhones.Where(p => p.PhoneTypeID == 1).Select(p => p.Phone).FirstOrDefault() : "", Phone = contact.CoContactPhones.Any() ? contact.CoContactPhones.Where(p => p.PhoneTypeID == 2).Select(p => p.Phone).FirstOrDefault() : "", StatusID = contact.ContactStatusID, TypeID = contact.ContactTypeID, OwnerID = contact.ContactManager }; } return(View("_Edit", Model)); }
// GET: Mobile/mContactInfo public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CoContacts coContacts = db.CoContacts.Find(id); if (coContacts == null || coContacts.SiteCoID != base.siteusercompanyid) { return(HttpNotFound()); } ViewBag.Country = ""; var address = coContacts.CoContactAddresses.FirstOrDefault(); if (address != null) { ViewBag.Country = new CommonRepository().GetCountryNameByID(address.CountryID ?? 0); } if (coContacts.CoContactTypes == null) { coContacts.CoContactTypes = new CoContactTypes();//to prevent null checks, init to new() } ViewBag.Activities = db.GetActivitiesByContactID(id); if ((coContacts.CoContactTypes).IsVendor != true) { ViewBag.Projects = db.GetProjectsByContactID(id); } if (coContacts.CoContactTypes.IsVendor == true) { ViewBag.POR = db.GetPORByContactID(id); } return(View("details", coContacts)); }
public bool AddUpdateSaleztoolSync(string fileid, SessionInfoModel Sessioninfo) { bool ret = false; try { STClientModel info = Sessioninfo.clientInfo; if (info != null) { CoContacts contact = db.CoContacts.Where(s => (s.ContactFirstName == null ? "" : s.ContactFirstName).Trim().ToLower() == info.firstName.Trim().ToLower() && (s.ContactLastName == null ? "" : s.ContactLastName).Trim().ToLower() == info.lastName.Trim().ToLower()).FirstOrDefault(); if (contact != null) { contact.ApiLinkID = fileid;// info.otherField == null ? "" : info.otherField; db.SaveChanges(); } else { string firstName = info.firstName == null ? "" : info.firstName.Trim(); string lastName = info.lastName == null ? "" : info.lastName.Trim(); string otherField = fileid;//info.otherField == null ? "" : info.otherField.Trim(); string address1 = info.homeAddress == null ? "" : info.homeAddress.Street == null ? "" : info.homeAddress.Street.Trim(); string City = info.homeAddress == null ? "" : info.homeAddress.City == null ? "" : info.homeAddress.City.Trim(); string Zip = info.homeAddress == null ? "" : info.homeAddress.Zip == null ? "" : info.homeAddress.Zip.Trim(); string State = info.homeAddress == null ? "" : info.homeAddress.State == null ? "" : info.homeAddress.State.Trim(); string emailAddress = info.emailAddress == null ? "" : info.emailAddress.Trim(); string Phone = info.homeAddress == null ? "" : info.homeAddress.Phone == null ? "" : info.homeAddress.Phone.Trim(); db.InsertSalezToolzCustomer(siteusercompanyid, firstName, lastName, siteuserid, siteuserid, otherField, address1, City, State, Zip, emailAddress, Phone); //Get Contact contact = db.CoContacts.Where(s => (s.ContactFirstName == null ? "" : s.ContactFirstName).Trim().ToLower() == firstName.ToLower() && (s.ContactLastName == null ? "" : s.ContactLastName).Trim().ToLower() == lastName.ToLower()).FirstOrDefault(); } //Project for contact if (contact != null) { string projectname = info.fileName == null ? "" : info.fileName.Trim(); if (projectname != "") { ProjectInfo project = db.ProjectInfo.Where(s => (s.ProjectName == null ? "" : s.ProjectName).Trim().ToLower() == projectname.ToLower()).FirstOrDefault(); if (project != null) { project.ApiLinkID = fileid;// info.otherField == null ? "" : info.otherField; db.SaveChanges(); } else { string otherField = fileid;//info.otherField == null ? "" : info.otherField.Trim(); string address1 = info.workAddress == null ? "" : info.workAddress.Street == null ? "" : info.workAddress.Street.Trim(); string City = info.workAddress == null ? "" : info.workAddress.City == null ? "" : info.workAddress.City.Trim(); string Zip = info.workAddress == null ? "" : info.workAddress.Zip == null ? "" : info.workAddress.Zip.Trim(); string State = info.workAddress == null ? "" : info.workAddress.State == null ? "" : info.workAddress.State.Trim(); string emailAddress = info.emailAddress == null ? "" : info.emailAddress.Trim(); string Phone = info.workAddress == null ? "" : info.workAddress.Phone == null ? "" : info.workAddress.Phone.Trim(); DateTime startdate = info.createDate == null ? DateTime.Now : info.createDate; //tax info bool istax = Sessioninfo.taxProfile != null; string taxCode = !istax ? "" : Sessioninfo.taxProfile.taxName == null ? "" : Sessioninfo.taxProfile.taxName.Trim(); string taxDescription = (istax && Sessioninfo.taxProfile.taxes != null && Sessioninfo.taxProfile.taxes.Count > 0) ? Sessioninfo.taxProfile.taxes[0].applyType == null ? "" : Sessioninfo.taxProfile.taxes[0].applyType : ""; decimal salesrate_dec = (istax && Sessioninfo.taxProfile.taxes != null && Sessioninfo.taxProfile.taxes.Count > 0) ? Sessioninfo.taxProfile.taxes[0].value == null ? 0 : ExtractDecimalFromString(Sessioninfo.taxProfile.taxes[0].value) : 0; //decimal salesrate_dec = 0; //decimal.TryParse(salesrate, out salesrate_dec); //Adjustment bool isadjust = Sessioninfo.adjustment != null; decimal equipAdjust = 0; string equipAdjustLabel = ""; decimal laborAdjust = 0; string laborAdjustLabel = ""; decimal otherAdjust = 0; string otherAdjustLabel = ""; string otherAdjustType = ""; decimal profileAdjust = 0; string profileAdjustLabel = ""; string profileAdjustType = ""; StringBuilder projectItems = new StringBuilder(); if (isadjust) { equipAdjust = Sessioninfo.adjustment.equipment == null ? 0 : ExtractDecimalFromString(Sessioninfo.adjustment.equipment.Trim()); equipAdjustLabel = Sessioninfo.adjustment.equipmentLabel == null ? "" : Sessioninfo.adjustment.equipmentLabel.Trim(); laborAdjust = Sessioninfo.adjustment.labor == null ? 0 : ExtractDecimalFromString(Sessioninfo.adjustment.labor.Trim()); laborAdjustLabel = Sessioninfo.adjustment.laborLabel == null ? "" : Sessioninfo.adjustment.laborLabel.Trim(); otherAdjust = Sessioninfo.adjustment.otherDiscountValue == null ? 0 : ExtractDecimalFromString(Sessioninfo.adjustment.otherDiscountValue.Trim()); otherAdjustLabel = Sessioninfo.adjustment.otherDiscountLabel == null ? "" : Sessioninfo.adjustment.otherDiscountLabel.Trim(); otherAdjustType = Sessioninfo.adjustment.discountType == null ? "" : Sessioninfo.adjustment.discountType.Trim(); //profileAdjust = Sessioninfo.adjustment.equipment == null ? 0 : ExtractDecimalFromString(Sessioninfo.adjustment.equipment.Trim()); } if (Sessioninfo.selectedPackages != null && Sessioninfo.selectedPackages.Count > 0) { projectItems.Append("<ArrayProjectItems>"); foreach (STPackageModel package in Sessioninfo.selectedPackages) { projectItems.Append("<ProjectItem>"); projectItems.Append("<SiteUserID>" + siteuserid + "</SiteUserID>"); projectItems.Append("<GroupName>" + SetValueForXML(package.packageGroupName) + "</GroupName>"); projectItems.Append("<ManufacturerName>" + SetValueForXML(package.manufacturer) + "</ManufacturerName>"); projectItems.Append("<ContactCoName>" + SetValueForXML(package.vendor) + "</ContactCoName>"); projectItems.Append("<Model>" + SetValueForXML(package.packageName) + "</Model>"); projectItems.Append("<SKU>" + SetValueForXML(package.sku) + "</SKU>"); projectItems.Append("<ProductDescription>" + SetValueForXML(package.description) + "</ProductDescription>"); projectItems.Append("<SalesDescription>" + SetValueForXML(package.description) + "</SalesDescription>"); //projectItems.Append("<ProductDescription></ProductDescription>"); //projectItems.Append("<SalesDescription></SalesDescription>"); projectItems.Append("<Hyperlink></Hyperlink>"); projectItems.Append("<StageName>" + SetValueForXML(package.phase) + "</StageName>"); projectItems.Append("<SalesTaxed>" + (SetValueForXML(package.taxable).Trim().ToLower() == "yes" ? "True" : "False") + "</SalesTaxed>"); projectItems.Append("<Cost>" + SetDecimalValueForXML(package.cost) + "</Cost>"); projectItems.Append("<Price>" + SetDecimalValueForXML(package.equipment) + "</Price>"); projectItems.Append("<DivisionName>" + SetValueForXML(package.packageGroupName) + "</DivisionName>"); if (package.roomsQuantity != null && package.roomsQuantity.Count > 0) { projectItems.Append("<Qty>" + SetDecimalValueForXML(package.roomsQuantity[0].quantity) + "</Qty>"); } else { projectItems.Append("<Qty>1</Qty>"); } projectItems.Append("<EstHrs>" + (SetDecimalValueForXML(package.labor1Hours) <= 0 ? 1 : SetDecimalValueForXML(package.labor1Hours)) + "</EstHrs>"); projectItems.Append("<StageLabor1Cost>" + SetDecimalValueForXML(package.labor1HourlyRateCost) + "</StageLabor1Cost>"); projectItems.Append("<StageLabor1Price>" + SetDecimalValueForXML(package.labor1HourlyRate) + "</StageLabor1Price>"); projectItems.Append("<StageLabor2Cost>" + SetDecimalValueForXML(package.labor2HourlyRateCost) + "</StageLabor2Cost>"); projectItems.Append("<StageLabor2Price>" + SetDecimalValueForXML(package.labor2HourlyRate) + "</StageLabor2Price>"); projectItems.Append("<Labor1Cost>" + SetDecimalValueForXML(package.labor1Cost) + "</Labor1Cost>"); projectItems.Append("<Labor1Price>" + SetDecimalValueForXML(package.labor1Price) + "</Labor1Price>"); projectItems.Append("<Labor2Cost>" + SetDecimalValueForXML(package.labor2Cost) + "</Labor2Cost>"); projectItems.Append("<Labor2Price>" + SetDecimalValueForXML(package.labor2Price) + "</Labor2Price>"); projectItems.Append("<ModelLabor1>" + SetValueForXML(package.packageName) + " Labor 1</ModelLabor1>"); projectItems.Append("<ModelLabor2>" + SetValueForXML(package.packageName) + " Labor 2</ModelLabor2>"); projectItems.Append("</ProjectItem>"); } projectItems.Append("</ArrayProjectItems>"); } db.InsertSalezToolzProjectInfo(siteusercompanyid, 5 /*projecttypeid*/, projectname, contact.ContactID, address1, City, State, Zip, startdate, Phone, emailAddress, siteuserid /*salesid*/, otherField, taxCode, taxDescription, salesrate_dec, equipAdjust, equipAdjustLabel, laborAdjust, laborAdjustLabel, otherAdjust, otherAdjustLabel, otherAdjustType, profileAdjust, profileAdjustLabel, profileAdjustType, projectItems.ToString()); } } } } ret = true; } catch (Exception ex) { ret = false; //throw ex; } return(ret); }
private int SaveContact(PeopleModels.NewContact Model) { int siteCoID = siteusercompanyid; CommonRepository repo = new CommonRepository(); CoContactCompanies company = null; if (!string.IsNullOrWhiteSpace(Model.Company)) { company = repo.AddCompany(siteCoID, Model.Company); } if (company == null) { company = new CoContactCompanies() { ContactCoID = 0 }; } var coContact = new CoContacts() { ContactID = Model.ContactID ?? 0, SiteCoID = siteCoID, ContactTypeID = Model.TypeID ?? 0, ContactStatusID = Model.StatusID, ContactFirstName = Model.First, ContactLastName = Model.Last, ContactCoID = company.ContactCoID, ModifiedDate = DateTime.Now, ContactManager = Model.OwnerID }; coContact.CoContactPhones.Add(new CoContactPhones() { PhoneTypeID = (int)EnumWrapper.PhoneTypes.Mobile, Phone = Model.Mobile, IsDefault = true }); coContact.CoContactPhones.Add(new CoContactPhones() { PhoneTypeID = (int)EnumWrapper.PhoneTypes.Phone, Phone = Model.Phone, IsDefault = true }); coContact.CoContactEmails.Add(new CoContactEmails() { EmailAddress = Model.Email, IsDefault = true }); coContact.CoContactAddresses.Add(new CoContactAddresses() { Address1 = Model.Address1, Address2 = Model.Address2, City = Model.City, State = Model.State, Zip = Model.Zip, CountryID = Model.CountryID, AddressTypeID = (int)EnumWrapper.AddressTypes.Main }); int contactID = repo.AddContact(coContact); if (contactID > 0) { return(contactID); } else { return(0); } }
private int SaveContact(GetContactInfoByContactID_Result Model) { int siteCoID = siteusercompanyid; CommonRepository repo = new CommonRepository(); CoContactCompanies company = null; if (!string.IsNullOrWhiteSpace(Model.ContactCompany)) { company = repo.AddCompany(siteCoID, Model.ContactCompany); } if (company == null) { company = new CoContactCompanies() { ContactCoID = 0 }; } var coContact = new CoContacts() { ContactID = Model.ViewID, SiteCoID = siteCoID, ContactTypeID = Model.ContactTypeID ?? 0, ContactSubtypeID = Model.ContactSubtypeID ?? 0, //When creating it needs to be set to 1 Active otherwise if they do Not it errors - REQUIRED ContactStatusID = Model.ContactStatusID, ContactFirstName = Model.ContactFirst, ContactLastName = Model.ContactLast, ContactCoID = company.ContactCoID, ModifiedDate = DateTime.Now, Custom1 = Model.Custom1, Custom2 = Model.Custom2, Custom3 = Model.Custom3, Custom4 = Model.Custom4, ContactManager = Model.ContactOwnerID }; coContact.CoContactPhones.Add(new CoContactPhones() { PhoneTypeID = (int)EnumWrapper.PhoneTypes.Mobile, Phone = Model.Mobile, IsDefault = true }); coContact.CoContactPhones.Add(new CoContactPhones() { PhoneTypeID = (int)EnumWrapper.PhoneTypes.Phone, Phone = Model.Phone, IsDefault = true }); coContact.CoContactEmails.Add(new CoContactEmails() { EmailAddress = Model.ContactEmail, IsDefault = true }); coContact.CoContactAddresses.Add(new CoContactAddresses() { Address1 = Model.ContactAddress1, Address2 = Model.ContactAddress2, City = Model.ContactCity, State = Model.ContactState, Zip = Model.ContactZip, CountryID = Model.CountryID, AddressTypeID = (int)EnumWrapper.AddressTypes.Main }); int contactID = repo.AddContact(coContact); if (contactID > 0) { return(contactID); } else { return(0); } }