예제 #1
0
        public IActionResult UpdateOutgoing([FromBody] OutgoingDto outgoingDto)
        {
            try
            {
                var outgoing = _mapper.Map <Outgoing>(outgoingDto);

                if (outgoing == null)
                {
                    throw new AppException("Неверный данные!");
                }

                var userId = Convert.ToInt32(User.Claims.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value);

                //if(outgoing.UserId != userId)
                //  throw new AppException("Вам нельзя обновить расход!");

                _userService.UpdateOutgoing(userId, outgoing);
                return(Ok(new
                {
                    Message = "Расход обновлен!",
                }));
            }
            catch (AppException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"{ex}");
                return(BadRequest("Service error!"));
            }
        }
예제 #2
0
        public IActionResult CreateOutgoing([FromBody] OutgoingDto outgoingDto)
        {
            try
            {
                var outgoing = _mapper.Map <Outgoing>(outgoingDto);

                if (outgoing == null)
                {
                    throw new AppException("Неверный данные!");
                }

                var userId = Convert.ToInt32(User.Claims.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value);
                outgoing.UserId = userId;

                _userService.CreateOutgoing(outgoing);

                _logger.LogInformation($"User #{userId}, CreateOutgoing #{outgoing.Id}");

                var res = _userService.IncomeBonus(userId, _appSettings.BonusTypes.NewOutgoing, _appSettings.Bonuses.NewOutgoing, _appSettings.BonusLimitPerDay.NewOutgoing);

                if (res)
                {
                    _logger.LogInformation($"User #{userId}, {_appSettings.Bonuses.NewOutgoing} bonus incomes");
                }

                return(Ok(new
                {
                    Message = "Расход добавлен!",
                    OutgoingId = outgoing.Id
                }));
            }
            catch (AppException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"{ex}");
                return(BadRequest("Service error!"));
            }
        }