public void UpdateAddressBook(AddressBook addressBookUpdate) { try { using (var db = new Entities()) { AddressBook original = new AddressBook { AddressId = addressBookUpdate.AddressId }; /// stub model, only has Id UDCRepository udcRepository = new UDCRepository(); string type = udcRepository.GetUdcById("AB_Type", addressBookUpdate.PeopleXrefId); addressBookUpdate.Type = type; var entry = db.Entry(original); entry.State = System.Data.Entity.EntityState.Modified; entry.CurrentValues.SetValues(addressBookUpdate); db.SaveChanges(); } } catch (Exception ex) { } }
public List <AddressBookModels> GetAllAddressBooks(string searchString, string keyCode) { List <AddressBookModels> resultList = new List <AddressBookModels>(); UDCRepository udcRepository = new UDCRepository(); long xRefId = udcRepository.GetUdcByKeyCode("AB_Type", keyCode); try { using (var db = new Entities()) { var query = (from b in db.AddressBooks join c in db.UDCs on b.PeopleXrefId equals c.XRefId where (b.PeopleXrefId == c.XRefId && c.XRefId == xRefId) select new AddressBookModels { AddressId = b.AddressId, Name = b.Name, FirstName = b.FirstName, LastName = b.LastName, Company = b.Company, CellPhone = b.CellPhone, MailingCity = b.MailingCity, MailingState = b.MailingState, MailingAddress = b.MailingAddress, MailingZipcode = b.MailingZipcode, BillingCity = b.BillingCity, BillingState = b.BillingState, BillingZipcode = b.BillingZipcode, BillingAddress = b.BillingAddress, Type = c.KeyCode, KeyCode = c.KeyCode, Value = c.Value, PeopleXrefId = b.PeopleXrefId, ProductKey = b.ProductKey, Email = b.Email, Fax = b.Fax, ShippingAddress = b.ShippingAddress, ShippingCity = b.ShippingCity, ShippingZipcode = b.ShippingZipcode, ShippingState = b.ShippingState }); if (!String.IsNullOrEmpty(searchString)) { query = query.Where(s => s.Name.Contains(searchString) || s.FirstName.Contains(searchString) || s.LastName.Contains(searchString)); } query = query.OrderBy(s => s.Name); resultList = query.ToList <AddressBookModels>(); //foreach (var item in query) //{ // resultList.Add(item); //} } } catch (Exception ex) { } return(resultList); }
public List <AddressBookModels> GetPersonList(string keyCode) { List <AddressBookModels> resultList = new List <AddressBookModels>(); UDCRepository udcRepository = new UDCRepository(); long xRefId = udcRepository.GetUdcByKeyCode("AB_Type", keyCode); try { using (var db = new Entities()) { var query = (from b in db.AddressBooks join c in db.UDCs on b.PeopleXrefId equals c.XRefId where (b.PeopleXrefId == c.XRefId && c.XRefId == xRefId) select new AddressBookModels { AddressId = b.AddressId, Name = b.Name, FirstName = b.FirstName, LastName = b.LastName, Company = b.Company, CellPhone = b.CellPhone, MailingCity = b.MailingCity, MailingState = b.MailingState, MailingAddress = b.MailingAddress, MailingZipcode = b.MailingZipcode, BillingCity = b.BillingCity, BillingState = b.BillingState, BillingZipcode = b.BillingZipcode, BillingAddress = b.BillingAddress, Type = c.KeyCode, KeyCode = c.KeyCode, Value = c.Value, PeopleXrefId = b.PeopleXrefId, ProductKey = b.ProductKey, Email = b.Email, Fax = b.Fax, ShippingAddress = b.ShippingAddress, ShippingCity = b.ShippingCity, ShippingZipcode = b.ShippingZipcode, ShippingState = b.ShippingState } ); query = query.OrderBy(s => s.Name); resultList = query.ToList <AddressBookModels>(); /* * var query = from b in db.AddressBooks * .Where(b => b.PeopleXrefId == xRefId) * select b; * * query = query.OrderBy(s => s.Name); * * * foreach (var item in query) * { * resultList.Add(item); * } */ } } catch (Exception ex) { } return(resultList); }