コード例 #1
0
        public async Task <IActionResult> UpdatePublicDeckStatus(int id, BoolValueRequestModel valueRqModel)
        {
            var user = await userManager.GetUser(User);

            var userIsAdmin = await userManager.CheckAdminRole(user);

            if (!userIsAdmin)
            {
                return(Forbid());
            }

            var notApprovedDeck = await repository.Deck
                                  .QueryByIdAndBeingNotApproved(id)
                                  .FirstOrDefaultAsync();

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

            notApprovedDeck.Approved = valueRqModel.Value;
            notApprovedDeck.Public   = valueRqModel.Value;
            await repository.SaveChangesAsync();

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> UpdateStatus(int id, BoolValueRequestModel valueRqModel)
        {
            var user = await UserUtil.GetUser(userManager, User);

            var deck = await repository.Deck
                       .QueryById(user.Id, id)
                       .FirstOrDefaultAsync();

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

            var userIsAdmin = await userManager.IsInRoleAsync(user, Roles.Administrator);

            deck.Public   = valueRqModel.Value;
            deck.Approved = valueRqModel.Value && (userIsAdmin || deck.Approved);

            await repository.SaveChangesAsync();

            return(NoContent());
        }