public async Task <SvcSingleResponse <bool> > DeleteAsync(int pId) { var response = new SvcSingleResponse <bool>(); try { var entity = await _uow.GetRepository <Competidor>().GetByIdAsync(pId); if (entity == null) { HandleSVCException(response, "No se pudo realizar la operación."); return(response); } await _uow.GetRepository <Competidor>().DeleteAsync(entity); response.Data = await _uow.CommitAsync(); } catch (Exception ex) { HandleSVCException(response, ex); } return(response); }
public async Task <SvcSingleResponse <bool> > UpdateAsync(CompetidorDto pDto) { var response = new SvcSingleResponse <bool>(); try { var entity = _mapper.MapToEntity(pDto); //https://github.com/aspnet/EntityFrameworkCore/issues/9803#issue-257405136 //to avoid fix at nested object updating await _uow.GetRepository <Marca>().UpdateAsync(entity.Marca); await _uow.GetRepository <ZonaDePrecio>().UpdateAsync(entity.ZonaDePrecio); await _uow.GetRepository <Competidor>().UpdateAsync(entity); response.Data = await _uow.CommitAsync(); } catch (Exception ex) { HandleSVCException(response, ex); } return(response); }
public static IActionResult ToHttpResponse <TModel>(this SvcSingleResponse <TModel> response) { var status = HttpStatusCode.OK; if (response.HasError) { status = HttpStatusCode.InternalServerError; } else if (response.Data == null) { status = HttpStatusCode.NotFound; } response.ResponseCode = status; return(new ObjectResult(response) { StatusCode = (int)HttpStatusCode.OK }); }
public async Task <SvcSingleResponse <CompetidorDto> > GetByIdAsync(int pId) { var response = new SvcSingleResponse <CompetidorDto>(); try { var svcResul = await _uow.GetRepository <Competidor>().FindAsync( c => c.Id == pId, x => x.Include(c => c.Marca), x => x.Include(c => c.ZonaDePrecio)); response.Data = _mapper.MapToDto(svcResul); } catch (Exception ex) { HandleSVCException(response, ex); } return(response); }
public async Task <SvcSingleResponse <CompetidorDto> > CreateAsync(CompetidorDto pDto) { var response = new SvcSingleResponse <CompetidorDto>(); try { var entity = _mapper.MapToEntity(pDto); var svcResul = await _uow.GetRepository <Competidor>().InsertAsync(entity); if (!await _uow.CommitAsync()) { HandleSVCException(response, "No se pudo realizar la operación."); return(response); } response.Data = _mapper.MapToDto(svcResul); } catch (Exception ex) { HandleSVCException(response, ex); } return(response); }