public Infrastructure.ApiResponse <Services.ViewModel.NewsViewModel> Post([FromBody] Services.ViewModel.NewsViewModel model) { var response = new Infrastructure.ApiResponse <Services.ViewModel.NewsViewModel>(); try{ var req = new Services.Message.AddNewsRequest(); req.news = model; _newsService.AddNews(req); response.status = true; response.data = model; response.code = System.Net.HttpStatusCode.Created; }catch (Infrastructure.BusinessRuleException bex) { response.status = true; response.code = System.Net.HttpStatusCode.BadRequest; response.brokenRules = bex.BrokenRules; response.error_message = bex.Message; }catch (Exception ex) { response.status = true; response.code = System.Net.HttpStatusCode.InternalServerError; response.error_message = "Ocorreu um erro inesperado. Entre em contato com o nosso time de desenvolvimento."; } return(response); }
public async Task <IActionResult> Detail([Bind("Id,title,body")] Services.ViewModel.NewsViewModel model) { Infrastructure.ApiResponse <EscolaDeVoce.Services.ViewModel.NewsViewModel> response = null; System.Net.Http.HttpMethod method = System.Net.Http.HttpMethod.Post; if (model.Id != Guid.Empty) { method = System.Net.Http.HttpMethod.Put; } response = await ApiRequestHelper.postPutRequest <Infrastructure.ApiResponse <EscolaDeVoce.Services.ViewModel.NewsViewModel> >( Helpers.EscolaDeVoceEndpoints.News.getNews + "/" + model.Id.ToString(), method, JsonConvert.SerializeObject(model) ); return(View(response.data)); }
public Infrastructure.ApiResponse <Services.ViewModel.NewsViewModel> Put(string id, [FromBody] Services.ViewModel.NewsViewModel model) { var response = new Infrastructure.ApiResponse <Services.ViewModel.NewsViewModel>(); try{ Guid newsid = Guid.Empty; if (!Guid.TryParse(id, out newsid)) { return(Infrastructure.ApiResponse <Services.ViewModel.NewsViewModel> .CreateResponse(false, "Noticia não encontrada", null, System.Net.HttpStatusCode.NotFound)); } model.Id = newsid; _newsService.UpdateNews(new Services.Message.UpdateNewsRequest() { news = model }); response.status = true; response.data = model; response.code = System.Net.HttpStatusCode.Created; }catch (Infrastructure.BusinessRuleException bex) { response.status = true; response.code = System.Net.HttpStatusCode.BadRequest; response.brokenRules = bex.BrokenRules; response.error_message = bex.Message; }catch (Exception ex) { response.status = true; response.code = System.Net.HttpStatusCode.InternalServerError; response.error_message = "Ocorreu um erro inesperado. Entre em contato com o nosso time de desenvolvimento."; } return(response); }