예제 #1
0
        private User UserSignup(string email, string password, string[] reports, string name)
        {
            if (_context.Users.Any(u => u.Email == email))
            {
                return(null);
            }
            var user = new User
            {
                Email    = email,
                Password = password,
                Player   = new Player
                {
                    Likes = new Collection <Like>()
                }
            };

            if (reports != null)
            {
                user.Customer = new Customer
                {
                    Name    = name,
                    Reports = reports.ToList().Select(url => new Report
                    {
                        ReportUrl = url
                    }).ToList(),
                    User = user
                };
            }
            _context.Users.Add(user);
            _context.SaveChanges();
            return(user);
        }
예제 #2
0
        public IActionResult PlayerSignup([FromBody] PlayerSignupRequest request)
        {
            if (_context.Users.Any(u => u.Email == request.Email))
            {
                return(BadRequest());
            }

            var user = Ackbar.Models.User.MakePlayer(request.Email, request.Password, request.AvatarUrl,
                                                     request.CollectionSize, request.WeeklyPlayTime);

            _context.Users.Add(user);
            _context.SaveChanges();
            var tokenString = _jwt.GenerateJwt(user.Id);

            return(Ok(new UserDto {
                Token = tokenString
            }));
        }
예제 #3
0
        public IActionResult LoadGames([FromBody] GameListDataDto listDto)
        {
            var games = _context.Games
                        .Include(g => g.Likes)
                        .Include(g => g.Views)
                        .Include(g => g.Ownerships)
                        .Include(g => g.Profile)
                        .ThenInclude(g => g.Agency)
                        .Include(g => g.Profile)
                        .ThenInclude(g => g.Appearance)
                        .Include(g => g.Profile)
                        .ThenInclude(g => g.Conflict)
                        .Include(g => g.Profile)
                        .ThenInclude(g => g.Investment)
                        .Include(g => g.Profile)
                        .ThenInclude(g => g.Rules);

            foreach (var game in games)
            {
                foreach (var like in game.Likes)
                {
                    _context.Remove(like);
                }

                foreach (var ownership in game.Ownerships)
                {
                    _context.Remove(ownership);
                }

                foreach (var view in game.Views)
                {
                    _context.Remove(view);
                }

                if (game.Profile != null)
                {
                    var profile = game.Profile;
                    _context.Remove(profile.Agency);
                    _context.Remove(profile.Appearance);
                    _context.Remove(profile.Conflict);
                    _context.Remove(profile.Investment);
                    _context.Remove(profile.Rules);
                    _context.Remove(profile);
                }
                _context.Remove(game);
            }

            foreach (var gameDto in listDto.Games)
            {
                var newAgency = new Agency
                {
                    Gradation     = gameDto.Gradation,
                    Participation = gameDto.Participation,
                    Result        = gameDto.Result
                };
                var newAppearance = new Appearance
                {
                    Quality        = gameDto.Quality,
                    Theme          = gameDto.Theme,
                    Transmediality = gameDto.Transmediality,
                    VisualIdentity = gameDto.VisualIdentity
                };
                var newConflict = new Conflict
                {
                    Competitivity    = gameDto.Competitivity,
                    Economy          = gameDto.Economy,
                    Feedback         = gameDto.Feedback,
                    Interaction      = gameDto.Interaction,
                    Structure        = gameDto.Structure,
                    Symmetry         = gameDto.Symmetry,
                    CognitiveAbility = gameDto.CognitiveAbility,
                    MentalAbility    = gameDto.MentalAbility,
                    PhysicalAbility  = gameDto.PhysicalAbility,
                    SocialAbility    = gameDto.SocialAbility
                };
                var newInvestment = new Investment
                {
                    Duration = gameDto.DurationValue,
                    Monetary = gameDto.Investment,
                    Setup    = gameDto.Preparation,
                    Space    = gameDto.Space
                };
                var newRules = new Rules
                {
                    Actions              = gameDto.Actions,
                    Components           = gameDto.Components,
                    Conditions           = gameDto.Conditions,
                    Randomness           = gameDto.Randomness,
                    Resources            = gameDto.Resources,
                    Variance             = gameDto.Variance,
                    VictoryConditions    = gameDto.VictoryConditions,
                    IdealNumberOfPlayers = gameDto.IdealNumberOfPlayers,
                    RealNumberOfPlayers  = gameDto.RealNumberOfPlayers
                };
                var newProfile = new Profile
                {
                    Appearance = newAppearance,
                    Conflict   = newConflict,
                    Investment = newInvestment,
                    Rules      = newRules,
                    Agency     = newAgency
                };
                var newGame = new Game
                {
                    Name            = gameDto.Name,
                    Year            = gameDto.YearInBrazil,
                    Age             = gameDto.RecommendedAge,
                    Description     = gameDto.Description,
                    Duration        = gameDto.Duration,
                    CoverImage      = gameDto.ImageUrl,
                    NumberOfPlayers = gameDto.NumberOfPlayers,
                    Genre           = gameDto.Genre,
                    Publisher       = gameDto.Publisher,
                    SellingPrice    = gameDto.SellingPrice,
                    Profile         = newProfile
                };
                _context.Games.Add(newGame);
            }

            _context.SaveChanges();

            return(Ok(_context.Games));
        }