public ResponseResults <NewsLetterViewModel> GetNewsLetters(SearchNewLetterViewModel searchParam) { var response = new ResponseResults <NewsLetterViewModel> { IsSucceed = true, Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY }; try { var models = UnitOfWork.NewsLetterRepository.GetNewsLetters(searchParam); response.ViewModels = models.ToViewModel <NewsLetterEntityModel, NewsLetterViewModel>().ToList(); if (response.ViewModels != null && response.ViewModels.Count > 0 && searchParam.UserId > 0) { var userNewsLetterLookUp = UnitOfWork.UserNewsLetterRepository.Get(o => o.UserId == searchParam.UserId); if (userNewsLetterLookUp != null && userNewsLetterLookUp.NewsLetterIds != null && userNewsLetterLookUp.NewsLetterIds.Length > 0) { response.ViewModels.ForEach(o => o.IsSubscribed = userNewsLetterLookUp.NewsLetterIds.Contains(o.Id.ToString())); } } if (response.ViewModels.Count <= 0) { response.Message = AppMessages.NO_RECORD_FOUND; } } catch (Exception ex) { response.IsSucceed = false; response.Message = ex.Message; } return(response); }
public HttpResponseMessage GetNewsLetters([FromUri] SearchNewLetterViewModel searchParam) { try { var response = newsLetterService.GetNewsLetters(searchParam); return(Request.CreateResponse(HttpStatusCode.OK, new { response.ViewModels, message = response.Message })); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public List<NewsLetterEntityModel> GetNewsLetters(SearchNewLetterViewModel searchParam) { var query = DbSet.AsQueryable(); if (!string.IsNullOrWhiteSpace(searchParam.Publisher)) { query = query.Where(o => o.Publisher.ToLower().Trim().Contains(searchParam.Publisher.ToLower().Trim())); } if (!string.IsNullOrWhiteSpace(searchParam.Author)) { query = query.Where(o => o.Author.StartsWith(searchParam.Author.Trim())); } return query.ToList(); }