public IHttpActionResult GetUnpublishedArticles() { try { var unpublishedArticles = GetService.GetArticleService().GetUnpublishedArticles(); return(Ok(unpublishedArticles)); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public IHttpActionResult Delete(int id) { try { GetService.GetArticleService().Delete(id); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public IHttpActionResult GetArticlesByTitle(string title) { try { var articlesByTitle = GetService.GetArticleService().GetArticlesByTitle(title).OrderByDescending(x => x.ArticleID).AsQueryable(); return(Ok(articlesByTitle)); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public IHttpActionResult GetArticlesByTitle(string title, [FromUri] PagingParameterModel pagingparametermodel) { try { var source = GetService.GetArticleService().GetPublishedArticlesByTitle(title).OrderByDescending(x => x.ArticleId).AsQueryable(); int count = source.Count(); // Parameter is passed from Query string if it is null then it default Value will be pageNumber:1 int currentPage = pagingparametermodel.pageNumber; // Parameter is passed from Query string if it is null then it default Value will be pageSize:20 int pageSize = pagingparametermodel.pageSize; // Display TotalCount to Records to User int totalCount = count; // Calculating Totalpage by Dividing (No of Records / Pagesize) int totalPages = (int)Math.Ceiling(count / (double)pageSize); // Returns List of Customer after applying Paging var items = source.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList(); // if CurrentPage is greater than 1 means it has previousPage var previousPage = currentPage > 1 ? "Yes" : "No"; // if TotalPages is greater than CurrentPage means it has nextPage var nextPage = currentPage < totalPages ? "Yes" : "No"; // Object which we are going to send in header var paginationMetadata = new { totalCount = totalCount, pageSize = pageSize, currentPage = currentPage, totalPages = totalPages, previousPage, nextPage }; // Setting Header HttpContext.Current.Response.Headers.Add("Paging-Headers", JsonConvert.SerializeObject(paginationMetadata)); // Returing List of Customers Collections return(Ok(new { items, totalPages })); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public IHttpActionResult UpdateArticle(ArticleModel articleModel) { try { //userId GetService.GetArticleService().Update(articleModel.ArticleId, articleModel); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public IHttpActionResult PublishArticle([FromUri] int articleId) { try { var userId = RequestContext.Principal.Identity.GetUserId(); GetService.GetArticleService().PublishArticle(userId, articleId); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public List <ArticleModel> Get() { try { var articles = GetService.GetArticleService().GetPublishedArticles(); return(articles); } catch (Exception ex) { var message = ex.ToString(); return(new List <ArticleModel> { }); } }
public IHttpActionResult GetAllArticlesByCategory(int categoryId) { try { var articlesByCategory = GetService.GetArticleService().GetArticlesByCategory(categoryId).OrderByDescending(x => x.ArticleID).AsQueryable(); return(Ok(articlesByCategory)); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public IHttpActionResult PostPendingArticle(ArticleModel articleModel) { try { articleModel.UploadedUserId = RequestContext.Principal.Identity.GetUserId(); GetService.GetArticleService().Insert(articleModel); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public ArticleModel GetPublishedArticlesById(int id) { try { var article = GetService.GetArticleService().GetPublishedArticlesById(id); if (article == null) { article = new ArticleModel(); } return(article); } catch (Exception ex) { var message = ex.ToString(); return(new ArticleModel()); } }
public IHttpActionResult GetAllArticlesById(int id) { try { var article = GetService.GetArticleService().GetAllArticlesById(id); if (article == null) { article = new ArticleModel(); } return(Ok(article)); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public IHttpActionResult GetPublishedArticlesByCategoryAndTitle(int categoryId, string title, [FromUri] PagingParameterModel pagingParameterModel) { try { var source = GetService.GetArticleService().GetPublishedArticlesByCategoryAndTitle(categoryId, title).OrderByDescending(x => x.ArticleId).AsQueryable(); int count = source.Count(); int currentPage = pagingParameterModel.pageNumber; int pageSize = pagingParameterModel.pageSize; int totalCount = count; int totalPages = (int)Math.Ceiling(count / (double)pageSize); var items = source.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList(); var previousPage = currentPage > 1 ? "Yes" : "No"; var nextPage = currentPage < totalPages ? "Yes" : "No"; var paginationMetadata = new { totalCount = totalCount, pageSize = pageSize, currentPage = currentPage, totalPages = totalPages, previousPage, nextPage }; HttpContext.Current.Response.Headers.Add("Paging-Headers", JsonConvert.SerializeObject(paginationMetadata)); return(Ok(new { items, totalPages })); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }