Example #1
0
 public IEnumerable<Contact> GetAll()
 {
     using (var dataContext = new ApplicationDbContext())
      {
     return dataContext.Contacts.ToList();
      }
 }
Example #2
0
 public Contact Get(int contactId)
 {
     using (var dataContext = new ApplicationDbContext())
      {
     return dataContext.Contacts.FirstOrDefault(p => p.UserId == contactId);
      }
 }
Example #3
0
 public void Delete(int contactId)
 {
     using (var dataContext = new ApplicationDbContext())
      {
     var contactToDelete = new Contact() { UserId = contactId };
     dataContext.Contacts.Attach(contactToDelete);
     dataContext.Contacts.Remove(contactToDelete);
     dataContext.SaveChanges();
      }
 }
Example #4
0
 public IEnumerable<Contact> GetPagedContacts(int startPage, int countPerPage, string searchString)
 {
     using (var dataContext = new ApplicationDbContext())
      {
     var contacts = dataContext.Contacts.Include("ZipLocation").Select(x=>x);
     if (!String.IsNullOrEmpty(searchString))
     {
        contacts = contacts.Where(s => s.LastName.Contains(searchString)||
                                       s.FirstName.Contains(searchString)||
                                       s.UserName.Contains(searchString)||
                                       s.Street.Contains(searchString)||
                                       s.PhoneNumber.Contains(searchString)||
                                       s.RoleName.Contains(searchString)
                                       ).OrderBy(x=>x.UserId);
     }
     else{
       contacts = contacts.OrderBy(x => x.UserId);
     }
     return contacts.Skip(startPage).Take(countPerPage).ToList();
      }
 }
Example #5
0
        public PagedData<Contact> GetContacts(int currentPage, int pageSize, string searchString)
        {
            using (var dataContext = new ApplicationDbContext())
             {
            var contacts = dataContext.Contacts.OrderBy(p => p.UserId);

            if (!String.IsNullOrEmpty(searchString))
            {
               contacts = (IOrderedQueryable<Contact>)contacts.Where(s => s.UserName.Contains(searchString));
            }

            int totalItemsCount = contacts.Count();

            return new PagedData<Contact>
            {
               TotalItemsCount = totalItemsCount,
               CurrentPage = currentPage,
               PageSize = pageSize,
               Data = contacts.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList()
            };
             }
        }
Example #6
0
 public int Insert(Contact contact)
 {
     using (var dataContext = new ApplicationDbContext())
      {
     dataContext.Contacts.Add(contact);
     dataContext.SaveChanges();
     return Convert.ToInt32(contact.UserId);
      }
 }
Example #7
0
 public int GetTotalCount()
 {
     using (var dataContext = new ApplicationDbContext())
      {
     var contacts = dataContext.Contacts.OrderBy(p => p.FirstName);
     return contacts.Count();
      }
 }
Example #8
0
 public void Update(Contact contact)
 {
     using (var dataContext = new ApplicationDbContext())
      {
     dataContext.Contacts.AddOrUpdate(contact);
     dataContext.SaveChanges();
      }
 }