public IHttpActionResult GetStoreById(string id) { int idInt = 0; var response = new SingularStoreResponse(); var result = new StoreDTO(); try { // Validate request if (string.IsNullOrEmpty(id) || !int.TryParse(id, out idInt)) { return(Ok(ResponseHandler.Error(400))); } result = ContextBehaviours.GetStoreById(idInt); // Validate if find record if (result == null) { return(Ok(ResponseHandler.Error(404))); } // Prepare success response response.store = result; response.success = true; return(Ok(response)); } catch (Exception ex) { return(Ok(ResponseHandler.Error(500))); } }
public IHttpActionResult GetStores() { var response = new PluralStoreResponse(); var result = new List <StoreDTO>(); try { result = ContextBehaviours.GetStores(); // Validate if find record if (result.Count == 0) { return(Ok(ResponseHandler.Error(404))); } // Prepare success response response.stores = result; response.total_elements = result.Count; response.success = true; return(Ok(response)); } catch (Exception ex) { return(Ok(ResponseHandler.Error(500))); } }
public IHttpActionResult GetArticlesByStore(string storeId) { int storeIdInt; var response = new PluralArticleResponse(); var result = new List <ArticleDTO>(); try { // Validate request if (string.IsNullOrEmpty(storeId) || !int.TryParse(storeId, out storeIdInt)) { return(Ok(ResponseHandler.Error(400))); } result = ContextBehaviours.GetArticlesByStore(storeIdInt); // Validate if find record if (result.Count == 0) { return(Ok(ResponseHandler.Error(404))); } // Prepare success response response.articles = result; response.success = true; response.total_elements = result.Count; } catch (Exception ex) { return(Ok(ResponseHandler.Error(500))); } return(Ok(response)); }
public IHttpActionResult DeleteArticle([FromBody] IdModels id) { int idInt; var response = new SingularArticleResponse(); try { // Validate request if (string.IsNullOrEmpty(id.id) || !int.TryParse(id.id, out idInt)) { return(Ok(ResponseHandler.Error(400))); } var result = ContextBehaviours.DeleteArticle(idInt); // Prepare success response response.article = result; response.success = true; return(Ok(response)); } catch (Exception ex) { return(Ok(ResponseHandler.Error(500))); } }
public IHttpActionResult ExistStore(int storeId) { try { var result = ContextBehaviours.ExistStore(storeId); } catch (Exception ex) { return(Ok(ResponseHandler.Error(500))); } return(Ok(true)); }
public IHttpActionResult CreateStore([FromBody] StoreDTO store) { var response = new SingularStoreResponse(); try { ContextBehaviours.CreateStore(store); // Prepare success response response.store = store; response.success = true; return(Ok(response)); } catch (Exception ex) { return(Ok(ResponseHandler.Error(500))); } }
public IHttpActionResult UpdateArticle([FromBody] ArticleDTO article) { var response = new SingularArticleResponse(); try { ContextBehaviours.UpdateArticle(article); // Prepare success response response.article = article; response.success = true; return(Ok(response)); } catch (Exception ex) { return(Ok(ResponseHandler.Error(500))); } }