Beispiel #1
0
        public async Task <IActionResult> DeductPointsFromUser(int id, int amount)
        {
            if (amount < 0)
            {
                return(BadRequest());
            }

            var user = await _userService.GetAsync(id);

            if (user == null)
            {
                return(NotFound());
            }

            if (user.Points.Sum(s => s.Amount) < amount)
            {
                return(BadRequest());
            }

            var newPoints = await _pointService.DeductPointsFromUser(id, amount);

            var resource = _mapper.Map <IEnumerable <Point>, IEnumerable <PointResource> >(newPoints);

            return(Ok(resource));
        }