public async Task <IHttpActionResult> CreateInsertaProducto(ProductoPorCompetidor model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { log.Info(new MDCSet(this.ControllerContext.RouteData)); var result = await _entityRepo.InsertaProductoUpdate(model); return(Ok(result)); } 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 async Task Create(ProductoPorCompetidor model) { try { _db.ProductoPorCompetidor.Add(model); await _db.SaveChangesAsync(); } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <ProductoPorCompetidor> InsertaProductoUpdate(ProductoPorCompetidor model) { try { var entities = _dbComp.ProductoPorCompetidor.Add(model); await _dbComp.SaveChangesAsync(); return(entities); } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task Update(ProductoPorCompetidor model) { try { var _model = await _db.ProductoPorCompetidor.FirstOrDefaultAsync(e => e.ProductoPorCompetidorId == model.ProductoPorCompetidorId); if (_model != null) { _db.Entry(_model).CurrentValues.SetValues(model); await _db.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task UpdateEstado(ProductoPorCompetidor model) { try { var _model = await _db.ProductoPorCompetidor.FirstOrDefaultAsync(e => e.ProductoPorCompetidorId == model.ProductoPorCompetidorId); if (_model != null) { _model.Estado = model.Estado; await _db.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
private async Task insertaProducto(Competidor model) { try { for (int i = 0; i < model.ProductoId.Length; i++) { var Prod = model.ProductoId[i]; ProductoPorCompetidor obj = new ProductoPorCompetidor(); obj.Autor = model.Autor; obj.FechaRegistro = model.FechaRegistro; obj.Estado = true; obj.ProductoId = Prod; obj.CompetidorId = model.CompetidorId; var entities = _dbComp.ProductoPorCompetidor.Add(obj); await _dbComp.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <IHttpActionResult> UpdateEstado([FromBody] ProductoPorCompetidor model) { try { log.Info(new MDCSet(this.ControllerContext.RouteData)); await _entityRepo.UpdateEstado(model); return(Ok()); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); return(InternalServerError(e)); } }
public async Task <IHttpActionResult> Update([FromBody] ProductoPorCompetidor 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)); } }