public async Task Update(FactorInnovacion model) { try { var _model = await dbGI.DbSetFactorInnovacion.FirstOrDefaultAsync(e => e.Id == model.Id); if (_model != null) { if (!model.ExisteEn(dbGI.DbSetFactorInnovacion.Where(e => e.Id != model.Id).Select(e => e.Descripcion).ToList())) { dbGI.Entry(_model).CurrentValues.SetValues(model); await dbGI.SaveChangesAsync(); } else { throw new ApplicationException("Ya existe un registro con ese nombre."); } } } catch (ApplicationException e) { throw new ApplicationException(e.Message, e); } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task Create(FactorInnovacion model) { try { dbGI.DbSetFactorInnovacion.Add(model); await dbGI.SaveChangesAsync(); } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <IHttpActionResult> Create([FromBody] FactorInnovacion model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _repo.Create(model); return(Ok("Registro creado exitosamente!")); } catch (Exception e) { return(InternalServerError(e)); } }