public async Task <IActionResult> RejectedOrRemoveUser([FromBody] ManageUserTeamViewModel model)
        {
            logger.LogInformation($"POST Request {HttpContext.Request.Headers[":path"]}. Body: {JsonConvert.SerializeObject(model)}");

            if (!await accessChecker.CanManageTeamOrSelfInTeam(model.TeamId, model.UserId))
            {
                throw new HttpStatusException(HttpStatusCode.Forbidden, CommonErrorMessages.Forbidden);
            }

            var team = await context.Teams
                       .Include(t => t.Image)
                       .Include(u => u.UserTeams)
                       .ThenInclude(ut => ut.User)
                       .FirstOrDefaultAsync(u => u.Id == model.TeamId);

            var userTeam = team?.UserTeams.FirstOrDefault(ut => ut.UserId == model.UserId);

            if (userTeam == null)
            {
                throw new HttpStatusException(HttpStatusCode.NotFound, UserErrorMessages.NotFound,
                                              UserErrorMessages.DebugNotFoundUserTeam(model.UserId, model.TeamId));
            }

            userTeam.UserAction = userTeam.UserAction switch
            {
                UserActionEnum.SentRequest => UserActionEnum.RejectedTeamRequest,
                UserActionEnum.JoinedTeam => UserActionEnum.QuitTeam,
                UserActionEnum.ConsideringOffer => UserActionEnum.RejectedTeamRequest,
                _ => throw new HttpStatusException(HttpStatusCode.BadRequest,
                                                   TeamErrorMessages.QuitDeclineTeam,
                                                   TeamErrorMessages.InvalidUserAction(model.UserId, userTeam, team.Id,
                                                                                       UserActionEnum.SentRequest, UserActionEnum.JoinedTeam, UserActionEnum.ConsideringOffer))
            };

            //По этому свойству отображается капитан в команде. А так как капитан может самоустраниться, то нужно менять свойство
            userTeam.IsOwner = false;

            try
            {
                context.Update(userTeam);
                await context.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw new HttpStatusException(HttpStatusCode.InternalServerError, CommonErrorMessages.SaveChanges);
            }

            await RejectedOrRemoveUserNotify(model.UserId, team, userTeam.UserAction);

            return(Json(team));
        }
        public async Task <IActionResult> CancelRequestUser([FromBody] ManageUserTeamViewModel model)
        {
            logger.LogInformation($"POST Request {HttpContext.Request.Headers[":path"]}. Body: {JsonConvert.SerializeObject(model)}");

            var team = await context.Teams
                       .Include(t => t.Image)
                       .Include(u => u.UserTeams)
                       .ThenInclude(ut => ut.User)
                       .FirstOrDefaultAsync(u => u.Id == model.TeamId);

            var userTeam = team?.UserTeams.FirstOrDefault(ut => ut.UserId == model.UserId);

            if (userTeam == null)
            {
                throw new HttpStatusException(HttpStatusCode.BadRequest, UserErrorMessages.NotFoundUserTeam,
                                              UserErrorMessages.DebugNotFoundUserTeam(model.UserId, model.TeamId));
            }

            switch (userTeam.UserAction)
            {
            case UserActionEnum.ConsideringOffer when !await accessChecker.CanManageTeam(model.TeamId):
            case UserActionEnum.SentRequest when !await accessChecker.CanManageTeamOrSelfInTeam(model.TeamId, model.UserId):
                throw new HttpStatusException(HttpStatusCode.Forbidden, CommonErrorMessages.Forbidden);
            }

            if (userTeam.UserAction != UserActionEnum.ConsideringOffer && userTeam.UserAction != UserActionEnum.SentRequest)
            {
                throw new HttpStatusException(HttpStatusCode.BadRequest,
                                              TeamErrorMessages.QuitDeclineTeam,
                                              TeamErrorMessages.InvalidUserAction(model.UserId, userTeam, model.TeamId,
                                                                                  UserActionEnum.ConsideringOffer, UserActionEnum.SentRequest));
            }

            try
            {
                context.Remove(userTeam);
                await context.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw new HttpStatusException(HttpStatusCode.InternalServerError, CommonErrorMessages.SaveChanges);
            }

            return(Json(team));
        }
        //Пользователь сам отменяет заявку в команду (из профиля)
        public async Task <IActionResult> CancelRequestTeam(long teamId)
        {
            logger.LogInformation($"POST Request {HttpContext.Request.Headers[":path"]}");

            if (!accessChecker.IsConfirm(out var profileId))
            {
                throw new HttpStatusException(HttpStatusCode.Forbidden, CommonErrorMessages.Forbidden);
            }

            var user = context.Users
                       .Include(x => x.UserTeams)
                       .ThenInclude(x => x.Team)
                       .ThenInclude(y => y.Event)
                       .FirstOrDefault(x => x.Id == profileId);
            var userTeam = user?.UserTeams.FirstOrDefault(ut => ut.TeamId == teamId);

            if (userTeam == null)
            {
                throw new HttpStatusException(HttpStatusCode.NotFound, UserErrorMessages.NotFound, UserErrorMessages.DebugNotFoundUserTeam(profileId, teamId));
            }

            if (userTeam.UserAction != UserActionEnum.SentRequest)
            {
                var debugMsg = TeamErrorMessages.InvalidUserAction(profileId, userTeam, teamId, UserActionEnum.SentRequest);

                throw new HttpStatusException(HttpStatusCode.NotFound, UserErrorMessages.NotFound, debugMsg);
            }

            try
            {
                context.Remove(userTeam);
                await context.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw new HttpStatusException(HttpStatusCode.NotFound, CommonErrorMessages.SaveChanges);
            }

            var activeUserTeams = user.GetActiveUserTeams();

            if (activeUserTeams.IsNullOrEmpty())
            {
                throw new HttpStatusException(HttpStatusCode.NoContent, "");
            }

            return(Json(activeUserTeams));
        }