Example #1
0
        public async Task <ActionResult <object> > Ban([FromBody] BanUserRequest request)
        {
            if (string.IsNullOrWhiteSpace(request.Sender))
            {
                throw new ArgumentNullException("Sender");
            }

            if (string.IsNullOrWhiteSpace(request.BanUser))
            {
                throw new ArgumentNullException("BanUser");
            }

            var senderPlatformId = BitcornUtils.GetPlatformId(request.Sender);
            var senderUser       = await BitcornUtils.GetUserForPlatform(senderPlatformId, _dbContext).FirstOrDefaultAsync();

            if (senderUser != null && senderUser.Level == "5000")
            {
                var banPlatformId = BitcornUtils.GetPlatformId(request.BanUser);
                var primaryKey    = -1;

                var banUser = await BitcornUtils.GetUserForPlatform(banPlatformId, _dbContext).FirstOrDefaultAsync();

                if (banUser != null)
                {
                    primaryKey       = banUser.UserId;
                    banUser.IsBanned = true;
                    _dbContext.Update(banUser);

                    await _dbContext.SaveAsync();
                }
                var users = await UserReflection.GetColumns(_dbContext, new string[] { "*" }, new[] { primaryKey });

                if (users.Count > 0)
                {
                    return(users.First());
                }
                return(null);
            }
            else
            {
                return(StatusCode((int)HttpStatusCode.Forbidden));
            }
        }