Exemplo n.º 1
0
        public async Task AddUserAsync(UserContainer user)
        {
            await _dataContext.Sessions.AddAsync(new SessionEntity()
            {
                Fight       = user.Fight,
                UserId      = user.Id,
                UserName    = user.Name,
                LastTouched = DateTimeOffset.UtcNow
            });

            await _dataContext.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task Command(string fight, string userName, string command)
        {
            if (!Guid.TryParseExact(fight, "N", out var fightGuid) && !Guid.TryParse(fight, out fightGuid))
            {
                return;
            }

            await _usersStorage.TouchAsync(fightGuid, Context.ConnectionId);

            await _dataContext.Commands.AddAsync(new CommandEntity()
            {
                UserName    = userName,
                DateCreated = DateTimeOffset.UtcNow,
                Fight       = fightGuid,
                Body        = command
            });

            await _dataContext.SaveChangesAsync();

            await Clients.OthersInGroup(fight).SendAsync("command", new CommandData()
            {
                Body   = command,
                UserId = Context.ConnectionId
            });
        }
Exemplo n.º 3
0
        public async Task <IActionResult> SaveBoss([FromBody] BossData request)
        {
            var nameClaim = CurrentUserName;

            if (nameClaim == null)
            {
                return(Unauthorized());
            }

            if (!Guid.TryParse(request.Id, out var guid))
            {
                guid = Guid.Empty;
            }
            var boss = await _dataContext.Bosses.FirstOrDefaultAsync(entity => entity.Identifier == guid).ConfigureAwait(false);

            if (boss != null)
            {
                if (boss.UserName != nameClaim)
                {
                    return(Unauthorized());
                }
                boss.Data      = request.Data;
                boss.IsPrivate = request.IsPrivate;
            }
            else
            {
                boss = new BossEntity()
                {
                    Identifier = Guid.NewGuid(),
                    Name       = request.Name,
                    UserName   = request.UserName,
                    IsPrivate  = request.IsPrivate,
                    Data       = request.Data,
                    Reference  = request.Reference,
                    CreateDate = DateTimeOffset.UtcNow,
                    Game       = request.Game
                };
                await _dataContext.Bosses.AddAsync(boss);
            }
            boss.ModifiedDate = DateTimeOffset.UtcNow;

            await _dataContext.SaveChangesAsync().ConfigureAwait(false);

            return(Json(new BossData()
            {
                Id = boss.Identifier.ToString("N"),
                Name = boss.Name,
                UserName = boss.UserName,
                Data = "",
                IsPrivate = boss.IsPrivate,
                Reference = boss.Reference.GetValueOrDefault(),
                CreateDate = boss.CreateDate.GetValueOrDefault(),
                ModifiedDate = boss.ModifiedDate.GetValueOrDefault(),
                Game = boss.Game
            }));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateUser([FromBody] RegisterUserModel model)
        {
            if (await _dataContext.Users.AnyAsync(entity => entity.Name == model.Username))
            {
                return(BadRequest());
            }

            var userEntity = new UserEntity
            {
                Name     = model.Username,
                Password = model.Password
            };
            await _dataContext.Users.AddAsync(userEntity);

            await _dataContext.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> CreateUser([FromBody] RegisterUserModel model)
        {
            _logger.LogInformation("Creating user for {User}", model.Username);
            if (await _dataContext.Users.AnyAsync(entity => entity.Name == model.Username))
            {
                _logger.LogInformation("Duplicate user found for user {User}", model.Username);
                return(BadRequest());
            }

            var userEntity = new UserEntity
            {
                Name     = model.Username,
                Password = model.Password
            };
            await _dataContext.Users.AddAsync(userEntity);

            var inserted = await _dataContext.SaveChangesAsync();

            _logger.LogInformation("User {User} created with status: {Status}", model.Username, inserted > 0);

            return(new JsonResult(new { created = inserted > 0 }));
        }