예제 #1
0
        public async Task <ActionResult <InviteRole> > PutInviteRole([FromBody] InviteRole inviteRole,
                                                                     [FromHeader(Name = "Authorization")] string inputToken,
                                                                     [FromRoute] int id)
        {
            if (tokenCheck.TokenChecking(inputToken))
            {
                if (id == inviteRole.Id)
                {
                    if (permissionCheck.IsAllowed(inputToken, "root"))
                    {
                        var oldInviteRole = await _context.InviteRoles.FindAsync(id);

                        if (oldInviteRole == null)
                        {
                            throw new ArgumentNullException();
                        }

                        inviteRole.CreatedAt = oldInviteRole.CreatedAt;
                        _context.Entry(oldInviteRole).State = EntityState.Detached;

                        _context.InviteRoles.Update(inviteRole);
                        await _context.SaveChangesAsync();

                        _context.Entry(inviteRole).State = EntityState.Detached;
                        return(await _context.InviteRoles
                               .Include(x => x.Role)
                               .Include(x => x.Invite)
                               .Where(x => x.Id == id)
                               .FirstAsync());
                    }
                }
            }
            throw new ArgumentNullException();
        }
예제 #2
0
        public async Task <ActionResult <InviteRole> > PostInviteRole([FromBody] InviteRole inviteRole, [FromHeader(Name = "Authorization")] string inputToken)
        {
            if (tokenCheck.TokenChecking(inputToken))
            {
                if (inviteRole != null)
                {
                    if (permissionCheck.IsAllowed(inputToken, "root"))
                    {
                        _context.InviteRoles.Add(inviteRole);
                        await _context.SaveChangesAsync();

                        _context.Entry(inviteRole).State = EntityState.Detached;

                        return(await _context.InviteRoles
                               .Include(x => x.Role)
                               .Include(x => x.Invite)
                               .Where(x => x.Id == inviteRole.Id)
                               .FirstAsync());
                    }
                }
            }
            throw new ArgumentNullException();
        }