Пример #1
0
        //[Authorize(Roles = "Trainer")]
        public IActionResult DeleteActivity(int activityId)
        {
            var activityEntity = _sportRepository.GetActivity(activityId);

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

            if (!User.IsInRole("Trainer"))
            {
                return(StatusCode(403));
            }

            var trainerId = User.Claims.FirstOrDefault(c => c.Type == "sub").Value;

            if (!(trainerId == activityEntity.TrainerId))
            {
                return(Unauthorized());
            }

            _sportRepository.DeleteActivity(activityEntity);

            if (!_sportRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(NoContent());
        }