Esempio n. 1
0
        public IActionResult GetActivity(int activityId)
        {
            var activity = _sportRepository.GetActivity(activityId);

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

            var activityResult = Mapper.Map <Model.Activity>(activity);

            return(Ok(activityResult));
        }
Esempio n. 2
0
        public IActionResult DeleteClientActivity(int activityId /*int clientActivityId*/)
        {
            var ActivityEntity = _sportRepository.GetActivity(activityId);
            IEnumerable <Entities.ClientActivity> ClientActivities = ActivityEntity.ClientActivities;

            var clientId             = User.Claims.FirstOrDefault(c => c.Type == "sub").Value;
            var clientActivityEntity = new Entities.ClientActivity();

            foreach (var item in ClientActivities)
            {
                if (item.ClientId == clientId)
                {
                    clientActivityEntity = _sportRepository.GetClientActivity(item.Id);
                }
            }

            //var clientActivityEntity = _sportRepository.GetClientActivity(clientActivityId);
            //var clientId = User.Claims.FirstOrDefault(c => c.Type == "sub").Value;

            if (!(clientId == clientActivityEntity.ClientId))
            {
                return(Unauthorized());
            }

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

            _sportRepository.DeleteClientActivity(clientActivityEntity);

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

            return(NoContent());
        }