public HearingDto GetHearingById(int id) { var hearing = _dbContext.Hearing.Where(x => x.HearingId == id && x.IsDeleted == false) .Include(x => x.UserHearing) .ThenInclude(userHearing => userHearing.User).FirstOrDefault(); if (hearing == null) { throw new NSIException("Hearing not found"); } var correctNote = _dbContext.Entry(hearing).Collection(h => h.Note) .Query().Where(n => n.CreatedByUserId == hearing.CreatedByUserId).ToList(); hearing.Note = correctNote; return(Mappers.HearingsRepository.MapToDto(hearing)); }
public PaggedContactDto GetContacts(int pageSize, int pageNumber, String searchString, String searchColumn, String sortOrder, int caseId) { try { IQueryable <Contact> contacts = null; if (caseId == 0) { contacts = _dbContext.Contact.Where(a => (bool)!a.IsDeleted); } else { contacts = _dbContext.Contact.Where(a => !(bool)a.IsDeleted && a.CaseContact.Any(b => b.CaseId == caseId)); } if (contacts == null) { return(null); } if (!String.IsNullOrEmpty((string)searchString)) { switch ((string)searchColumn) { case "email": contacts = contacts.Where(s => s.Email.Any(email => email.EmailAddress.ToUpper().Contains((string)searchString.ToUpper()))); break; case "phone": contacts = contacts.Where(s => s.Phone.Any(phone => phone.PhoneNumber.ToUpper().Contains((string)searchString.ToUpper()))); break; default: contacts = contacts.Where(s => (s.FirsttName + " " + s.LastName).ToUpper().Contains((string)searchString.ToUpper()));; break; } } var sortingOrder = String.IsNullOrEmpty((string)sortOrder) ? "date_modified" : (string)sortOrder; // date_modified will be our default sort order switch (sortingOrder) { case "name_asc": contacts = contacts.OrderBy(a => a.FirsttName + " " + a.LastName); break; case "name_desc": contacts = contacts.OrderByDescending(a => a.FirsttName + " " + a.LastName); break; case "phone_asc": contacts = contacts.OrderBy(a => a.Phone.FirstOrDefault().PhoneNumber); break; case "phone_desc": contacts = contacts.OrderByDescending(a => a.Phone.FirstOrDefault().PhoneNumber); break; case "email_asc": contacts = contacts.OrderBy(a => a.Email.FirstOrDefault().EmailAddress); break; case "email_desc": contacts = contacts.OrderByDescending(a => a.Email.FirstOrDefault().EmailAddress); break; default: contacts = contacts.OrderByDescending(a => a.ModifiedDate); break; } if (contacts != null) { var total = contacts.Count(); var contactsList = contacts.ToPagedList(pageNumber, pageSize).ToList(); ICollection <ContactDto> contactDto = new List <ContactDto>(); foreach (var item in contactsList) { _dbContext.Entry(item).Collection(p => p.Phone).Load(); _dbContext.Entry(item).Collection(p => p.Email).Load(); _dbContext.Entry(item).Reference(p => p.Address).Load(); contactDto.Add(Mappers.ContactRepository.MapToDto(item)); } var paggedContactsDto = new PaggedContactDto() { Contacts = contactDto, Total = total }; return(paggedContactsDto); } } catch (Exception ex) { //log ex throw new Exception(ex.Message); } return(null); }