public ExhibitorListResponse GetExhibitorById(int exhibitorId) { int groupId = _context.GroupExhibitors.Where(x => x.ExhibitorId == exhibitorId && x.IsActive == true && x.IsDeleted == false).Select(x => x.GroupId).FirstOrDefault(); IEnumerable <ExhibitorResponse> exhibitorResponses = null; ExhibitorListResponse exhibitorListResponses = new ExhibitorListResponse(); exhibitorResponses = (from exhibitor in _context.Exhibitors join address in _context.Addresses on exhibitor.AddressId equals address.AddressId into address1 from address2 in address1.DefaultIfEmpty() where exhibitor.IsActive == true && exhibitor.IsDeleted == false && address2.IsActive == true && address2.IsDeleted == false && exhibitor.ExhibitorId == exhibitorId select new ExhibitorResponse { ExhibitorId = exhibitor.ExhibitorId, GroupId = _context.Groups.Where(x => x.GroupId == groupId && x.IsActive == true && x.IsDeleted == false).Select(x => x.GroupId).FirstOrDefault(), GroupName = _context.Groups.Where(x => x.GroupId == groupId && x.IsActive == true && x.IsDeleted == false).Select(x => x.GroupName).FirstOrDefault(), BackNumber = exhibitor.BackNumber, FirstName = exhibitor.FirstName, LastName = exhibitor.LastName, BirthYear = exhibitor.BirthYear, IsDoctorNote = exhibitor.IsDoctorNote, IsNSBAMember = exhibitor.IsNSBAMember, PrimaryEmail = exhibitor.PrimaryEmail, SecondaryEmail = exhibitor.SecondaryEmail, Phone = exhibitor.Phone, QTYProgram = exhibitor.QTYProgram, AddressId = address2 != null ? address2.AddressId : 0, Address = address2 != null ? address2.Address : "", ZipCodeId = address2 != null ? address2.ZipCodeId : 0, CityId = address2 != null ? address2.CityId : 0, CityName = address2 != null ? _context.Cities.Where(x => x.CityId == address2.CityId).Select(x => x.Name).FirstOrDefault():"", StateId = address2 != null ? _context.Cities.Where(x => x.CityId == address2.CityId).Select(y => y.StateId).FirstOrDefault() : 0, exhibitorStallAssignmentResponses = (from stallassign in _context.StallAssignment where stallassign.ExhibitorId == exhibitor.ExhibitorId && stallassign.IsActive == true && stallassign.IsDeleted == false select new ExhibitorStallAssignmentResponse { StallAssignmentId = stallassign.StallAssignmentId, StallId = stallassign.StallId, StallAssignmentTypeId = stallassign.StallAssignmentTypeId, GroupId = stallassign.GroupId, ExhibitorId = stallassign.ExhibitorId, BookedByType = stallassign.BookedByType, BookedByName = exhibitor.FirstName + ' ' + exhibitor.LastName, StallAssignmentDate = stallassign.Date }).ToList() });; if (exhibitorResponses.Count() != 0) { exhibitorListResponses.exhibitorResponses = exhibitorResponses.ToList(); exhibitorListResponses.TotalRecords = exhibitorResponses.Count(); } return(exhibitorListResponses); }
public ExhibitorListResponse GetAllExhibitors(BaseRecordFilterRequest filterRequest) { IEnumerable <ExhibitorResponse> exhibitorResponses = null; ExhibitorListResponse exhibitorListResponses = new ExhibitorListResponse(); exhibitorResponses = (from exhibitor in _context.Exhibitors where exhibitor.IsActive == true && exhibitor.IsDeleted == false select new ExhibitorResponse { ExhibitorId = exhibitor.ExhibitorId, AddressId = exhibitor.AddressId, FirstName = exhibitor.FirstName, LastName = exhibitor.LastName, BackNumber = exhibitor.BackNumber, BirthYear = exhibitor.BirthYear, IsNSBAMember = exhibitor.IsNSBAMember, IsDoctorNote = exhibitor.IsDoctorNote, QTYProgram = exhibitor.QTYProgram, PrimaryEmail = exhibitor.PrimaryEmail, SecondaryEmail = exhibitor.SecondaryEmail, Phone = exhibitor.Phone, }).ToList(); if (exhibitorResponses.Count() > 0) { if (filterRequest.SearchTerm != null && filterRequest.SearchTerm != "") { exhibitorResponses = exhibitorResponses.Where(x => Convert.ToString(x.ExhibitorId).Contains(filterRequest.SearchTerm) || x.FirstName.ToLower().Contains(filterRequest.SearchTerm.ToLower()) || x.LastName.ToLower().Contains(filterRequest.SearchTerm.ToLower()) || Convert.ToString(x.BirthYear).Contains(filterRequest.SearchTerm)); } var propertyInfo = typeof(ExhibitorResponse).GetProperty(filterRequest.OrderBy); if (filterRequest.OrderByDescending == true) { exhibitorResponses = exhibitorResponses.OrderByDescending(s => s.GetType().GetProperty(filterRequest.OrderBy).GetValue(s)).ToList(); } else { exhibitorResponses = exhibitorResponses.AsEnumerable().OrderBy(s => propertyInfo.GetValue(s, null)).ToList(); } exhibitorListResponses.TotalRecords = exhibitorResponses.Count(); if (filterRequest.AllRecords == true) { exhibitorListResponses.exhibitorResponses = exhibitorResponses.ToList(); } else { exhibitorListResponses.exhibitorResponses = exhibitorResponses.Skip((filterRequest.Page - 1) * filterRequest.Limit).Take(filterRequest.Limit).ToList(); } } return(exhibitorListResponses); }