public async Task Create(OCSuscripciones model) { try { _db.dbSetOCSuscripciones.Add(model); await _db.SaveChangesAsync(); } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <IEnumerable <OCSuscripciones> > GetAllByEmpleado(OCSuscripciones model) { try { var entities = await _db.dbSetOCSuscripciones.AsNoTracking() .Where(e => e.ClaveEmpleado == model.ClaveEmpleado) .ToListAsync(); return(entities); } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <OCSuscripciones> Get(OCSuscripciones model) { try { var entities = await _db.dbSetOCSuscripciones.AsNoTracking() // .Include(x=> x.FK) .FirstOrDefaultAsync(e => e.ClaveEmpleado == model.ClaveEmpleado && e.OcsId == model.OcsId); return(entities); } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task Delete(OCSuscripciones model) { try { var _model = await _db.dbSetOCSuscripciones.FirstOrDefaultAsync( e => e.ClaveEmpleado == model.ClaveEmpleado && e.OcsId == model.OcsId); if (_model != null) { _db.dbSetOCSuscripciones.Remove(_model); await _db.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <IHttpActionResult> Update(String id, [FromBody] Ocs model) { String clavePersona = id; if (String.IsNullOrEmpty(clavePersona)) { return(BadRequest(ModelState)); } try { log.Info(new MDCSet(this.ControllerContext.RouteData)); OCSuscripciones newSuscripcion = await _entityRepo.GetRowSuscripcionByEmpleadoANDocId(clavePersona, model.OcsId); if (newSuscripcion == null) { OCSuscripciones nuevo = new OCSuscripciones(); nuevo.OcsId = model.OcsId; nuevo.ClaveEmpleado = clavePersona; nuevo.suscrito = model.IsSuscrito; await _entityRepo.Create(nuevo); } else { newSuscripcion.suscrito = model.IsSuscrito; await _entityRepo.Update(newSuscripcion); } return(Ok("Registro actualizado exitosamente!")); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); return(InternalServerError(e)); } }
[Authorize] public async Task <IHttpActionResult> Create([FromBody] OCSuscripciones 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); return(InternalServerError(e)); } }