public HttpResponseMessage Post(CategoryDTO categoryDTO) { var category = new Category(); var converter = new CategoryConverter(); converter.Convert(categoryDTO, category); try { CategoryApplication.Save(category); return(Request.CreateResponse(HttpStatusCode.OK, new Note("Categoria adicionado com sucesso", Note.NoteType.Success))); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new Note("Não foi possível adicionar a categoria.", ex.Message, Note.NoteType.Error))); } }
public HttpResponseMessage Put(Guid id, [FromBody] CategoryDTO categoryDTO) { var category = CategoryApplication.Get(id); if (category == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, new Note("Categoria não encontrado", Note.NoteType.Success))); } var converter = new CategoryConverter(); converter.Convert(categoryDTO, category); try { CategoryApplication.Save(category); return(Request.CreateResponse(HttpStatusCode.OK, new Note("Categoria criado com sucesso", Note.NoteType.Success))); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new Note("Não foi possível salvar a categoria", ex.Message, Note.NoteType.Error))); } }