public object GetById(int id) { if (BasicHttpAuth.IsAuthorized()) { Article article; try { article = _articleService.GetById(id); } catch { throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.ServerError, HttpStatusCode.InternalServerError)); } if (article == null) { throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.RecordNotFound, HttpStatusCode.NotFound)); } return(new ArticleServiceSuccessVM() { Article = ArticleMappers.MapToVM(article), Total_elements = 1 }); } else { throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.NotAuthorized, HttpStatusCode.Unauthorized)); } }
public object Get() { if (BasicHttpAuth.IsAuthorized()) { try { var articles = _articleService.GetAll(); return(new ArticlesServiceSuccessVM() { Articles = articles.Select(x => ArticleMappers.MapToVM(x)).ToList(), Total_elements = articles.Count }); } catch { throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.ServerError, HttpStatusCode.InternalServerError)); } } else { throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.NotAuthorized, HttpStatusCode.Unauthorized)); } }
public object Get() { if (BasicHttpAuth.IsAuthorized()) { try { var stores = new StoreService().GetAll(); return(new StoreServiceSuccessVM() { Stores = stores, Total_elements = stores.Count }); } catch { throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.ServerError, HttpStatusCode.InternalServerError)); } } else { throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.NotAuthorized, HttpStatusCode.Unauthorized)); } }