public async Task <bool> UpdateGasto(int id, GastoCreacionDto gastoEdicionDto) { //if (gastoEdicionDto.Descripcion.IndexOf("sexo", StringComparison.CurrentCultureIgnoreCase) >= 0) if (gastoEdicionDto.Descripcion.Contains("Sexo") || gastoEdicionDto.Descripcion.Contains("sexo")) { //throw new AppApiException("Contenido no permitido en la descripcion"); throw new BusinessException("Contenido no permitido en la descripcion"); } var existingGasto = await _unitOfWork.GastoRepository.GetByIdAsync(id); if (existingGasto == null) { throw new BusinessException("No se encuentra la entidad a modificar"); } var gasto = _mapper.Map <Gasto>(gastoEdicionDto); //existingGasto.ImporteTotal = gasto.GastosCreditos.Sum(x=>x.Importe); existingGasto.Descripcion = gasto.Descripcion; existingGasto.FrecuenciaId = gasto.FrecuenciaId; existingGasto.GastoTipoId = gasto.GastoTipoId; existingGasto.MesId = gasto.MesId; _unitOfWork.GastoRepository.Update(existingGasto); await _unitOfWork.SaveChangesAsync(); return(true); }
public async Task <GastoDto> InsertGasto(GastoCreacionDto gastoCreacionDto) { if (gastoCreacionDto.Descripcion.Contains("Sexo") || gastoCreacionDto.Descripcion.Contains("sexo")) { throw new BusinessException("Contenido no permitido en la descripcion"); //throw new ApiException("Contenido no permitido"); } var gasto = _mapper.Map <Gasto>(gastoCreacionDto); gasto.Activo = true; //gasto.ImporteTotal = gasto.GastosCreditos.Sum(x => x.Importe); await _unitOfWork.GastoRepository.Add(gasto); await _unitOfWork.SaveChangesAsync(); return(_mapper.Map <GastoDto>(gasto)); //var user = await _unitOfWork.UserRepository.GetById(gasto.UserId); //if (user == null) //{ // throw new BusinessException("User doesn't exist"); //} //var userGasto = await _unitOfWork.GastoRepository.GetGastosByUser(gasto.UserId); //Regla de validacion //if (userGasto.Count() < 10) //{ // var lastGasto = userGasto.OrderByDescending(x => x.FechaCreacion).FirstOrDefault(); // if ((DateTime.Now - lastGasto.FechaCreacion).TotalDays < 7) // { // throw new BusinessException("No puedes publicar la publicación"); // } //} }
//[HttpOptions] public async Task <IActionResult> Put(int id, GastoCreacionDto gastoDto) => Ok(new ApiResponse <bool>(await _gastoService.UpdateGasto(id, gastoDto)));
public async Task <IActionResult> Post(GastoCreacionDto gastoCreacionDto) => Ok(new ApiResponse <GastoDto>(await _gastoService.InsertGasto(gastoCreacionDto)));