public async Task UpdateEstado(Aliado model) { try { var _model = await _db.Aliado.FirstOrDefaultAsync(e => e.AliadoId == model.AliadoId); if (_model != null) { _model.Estado = model.Estado; await _db.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task Update(Aliado model) { try { var _model = await _db.Aliado.FirstOrDefaultAsync(e => e.AliadoId == model.AliadoId); if (_model != null) { _db.Entry(_model).CurrentValues.SetValues(model); await _db.SaveChangesAsync(); if (model.listaContactos != null) { var listaContactosViejos = await _db.ContactorPorAliados.Where(e => e.aliadoId == model.AliadoId).ToListAsync(); foreach (var contacto in listaContactosViejos) { var x = await _db.ContactorPorAliados.FirstOrDefaultAsync(e => e.id == contacto.id); if (x != null) { _db.ContactorPorAliados.Remove(x); await _db.SaveChangesAsync(); } } ContactosPorAliados nuevoContacto = new ContactosPorAliados(); foreach (var c in model.listaContactos) { nuevoContacto.aliadoId = model.AliadoId; nuevoContacto.ContactoId = c.ContactoId; nuevoContacto.fechaRegistro = DateTime.Now; _db.ContactorPorAliados.Add(nuevoContacto); await _db.SaveChangesAsync(); } } } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <IHttpActionResult> CreateConvenio(Aliado model) { try { log.Info(new MDCSet(this.ControllerContext.RouteData)); await _entityRepo.CreateConvenio(model); return(Ok("Registro creado exitosamente!")); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); //if (e.Message.Substring(0, 44) == "An error occurred while updating the entries") //{ // return BadRequest("Ya existe un registro con ese nombre"); //} return(InternalServerError(e)); } }
private async Task insertaAdjuntoConvenio(Aliado model, long IdAdjunto, int ConvenioId) { try { AdjuntoPorConvenio obj = new AdjuntoPorConvenio(); obj.Autor = model.Autor; obj.FechaRegistro = DateTime.Now; obj.Estado = true; obj.AdjuntoId = IdAdjunto; obj.ConvenioId = ConvenioId; var entities = _db.AdjuntoPorConvenio.Add(obj); await _db.SaveChangesAsync(); } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <IHttpActionResult> Update([FromBody] Aliado model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { log.Info(new MDCSet(this.ControllerContext.RouteData)); await _entityRepo.Update(model); return(Ok("Registro actualizado exitosamente!")); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); return(InternalServerError(e)); } }
public async Task <IHttpActionResult> CreateActividad([FromBody] Aliado model) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} try { log.Info(new MDCSet(this.ControllerContext.RouteData)); await _entityRepo.CreateActividad(model); return(Ok("Registro creado exitosamente!")); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); return(InternalServerError(e)); } }
public async Task <IHttpActionResult> Create([FromBody] Aliado model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { log.Info(new MDCSet(this.ControllerContext.RouteData)); await _entityRepo.Create(model); return(Ok("Registro creado exitosamente!")); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); if (e.Message.Substring(0, 44) == "An error occurred while updating the entries") { return(BadRequest("Ya existe un registro con ese nombre")); } return(InternalServerError(e)); } }
public void setUnidad(Aliado aliado) { this.unidad = aliado; }