public bool SaveSala(SalaAtendimento entity) { using (var context = new DatabaseContext()) { bool isNew = entity.IdSalaAtendimento == 0; if (isNew) { entity.IdUsuarioCadastro = GetLoggedUser().IdUsuario; entity.IdUsuarioAlteracao = GetLoggedUser().IdUsuario; entity.IdClinica = GetLoggedUser().IdClinica; entity.Status = (byte)DefaultStatusEnum.Ativo; context.Set <SalaAtendimento>().Add(entity); } else { entity.IdUsuarioAlteracao = GetLoggedUser().IdUsuario; context.Entry(entity).State = EntityState.Modified; entity.IdClinica = GetLoggedUser().IdClinica; } var result = context.SaveChanges() > 0; if (result) { RegistrarLogAtividade(entity, GERENCIAR_SALAS_PERMISSAO, isNew ? "Cadastro" : "Alteração"); } return(result); } }
public IHttpActionResult SaveSala([FromBody] SalaAtendimento model) { using (var repository = new GradeSalasRepository()) { try { return(Ok(CreateResponse(true, "Sala salva com sucesso", repository.SaveSala(model)))); } catch (System.Exception ex) { return(Content(HttpStatusCode.BadRequest, CreateResponse(false, "Erro ao salvar a sala", ex.Message))); } } }