public IHttpActionResult Put(int?id, [FromBody] EraDto era) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id == null || id <= 0) { return(NotFound()); } var dbEra = eraService.GetByID((int)id); dbEra.Name = era.Name; eraService.Update(dbEra); eraService.Save(); return(StatusCode(HttpStatusCode.NoContent)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Get(string name) { if (string.IsNullOrEmpty(name)) { return(BadRequest()); } var era = eraService.GetEraByName(name); if (era == null) { return(NotFound()); } var dtoEra = new EraDto(era); return(Ok(dtoEra)); }
public IHttpActionResult Get(int?id) { if (id <= 0 || id == null) { return(BadRequest()); } var era = eraService.GetByID((int)id); if (era == null) { return(NotFound()); } var eraDto = new EraDto(era); return(Ok(eraDto)); }
public IHttpActionResult Post([FromBody] EraCreateDto era) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Era newEra = new Era() { Name = era.Name }; eraService.Add(newEra); eraService.Save(); var dtoEra = new EraDto(newEra); return(Ok(dtoEra)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }