public async Task <ActionResult <EstadoViewModel> > Put(string sigla, [FromBody] EstadoCommand estado) { if (!ModelState.IsValid) { return(BadRequest()); } var existe = await db.Estado.AnyAsync(c => c.Sigla.ToUpper().Equals(sigla.ToUpper())); if (!existe) { return(BadRequest("Estado não encontrado na base")); } db.Estado.Update(_mapper.Map <Estado>(estado)); await db.SaveChangesAsync(); var result = await db.Estado.FirstAsync(c => c.Sigla.ToUpper().Equals(sigla.ToUpper())); if (result == null) { return(BadRequest()); } return(Ok(estado)); }
public static EstadoCommand ToModelDomain(Estado estado) { if (estado == null) { return(null); } var estadoCommand = new EstadoCommand( estado.Nome, estado.UF, estado.IdEstado); return(estadoCommand); }
public static Estado ToDomainModel(EstadoCommand estadoCommand) { if (estadoCommand == null) { return(null); } var estado = new Estado( estadoCommand.UF, estadoCommand.Nome, estadoCommand.IdEstado); return(estado); }
public async Task <ActionResult <EstadoViewModel> > Post([FromBody] EstadoCommand estado) { try { if (!ModelState.IsValid) { return(BadRequest()); } db.Estado.Add(_mapper.Map <Estado>(estado)); await db.SaveChangesAsync(); return(Ok(estado)); } catch (System.Exception e) { return(BadRequest(e.Message)); } }