示例#1
0
        public IHttpActionResult RemoveFitnessProgramFromUser(string userId, int fitnessProgramId)
        {
            var user    = this.usersService.GetById(userId);
            var isValid = ValidateUser.IsUsersValid(user.UserName, this.User.Identity.Name);

            if (!isValid)
            {
                return(this.BadRequest(MessageConstants.InvalidUser));
            }

            var fitnessProgram = this.fitnessProgramsService
                                 .GetById(fitnessProgramId)
                                 .FirstOrDefault();

            if (fitnessProgram == null)
            {
                return(this.BadRequest(string.Format(MessageConstants.FitnessProgramWithIdDoesNotExists, fitnessProgramId)));
            }

            var userDeletedProgram = this.usersService.RemoveFitnessProgramFromUserPrograms(user, fitnessProgram);

            return(this.Ok(Mapper.Map <UserResponseModel>(userDeletedProgram)));
        }