public override async Task <IdentityResult> UpdateAsync(ApplicationUser user)
        {
            var profileImage = user.ProfileImage;
            var headerImage  = user.HeaderImage;

            var result = await base.UpdateAsync(user);

            if (result.Succeeded && profileImage != null && profileImage != user.ProfileImage)
            {
                user.ProfileImage = profileImage;
                _db.Images.Attach(profileImage);
                _db.Users.Attach(user);

                user.ConcurrencyStamp = Guid.NewGuid().ToString();

                _db.Update(user);

                try
                {
                    await _db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    result = IdentityResult.Failed(new IdentityError {
                        Code = nameof(e), Description = e.Message
                    });
                }
            }

            if (result.Succeeded && headerImage != null && headerImage != user.HeaderImage)
            {
                user.HeaderImage = headerImage;
                _db.Images.Attach(headerImage);
                _db.Users.Attach(user);

                user.ConcurrencyStamp = Guid.NewGuid().ToString();

                _db.Update(user);

                try
                {
                    await _db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    result = IdentityResult.Failed(new IdentityError {
                        Code = nameof(e), Description = e.Message
                    });
                }
            }

            return(result);
        }
        public async Task <Player> UpdatePlayerAsync(Profile profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException(nameof(profile));
            }

            if (string.IsNullOrEmpty(profile.Username))
            {
                throw new ArgumentException("profile must have a valid username");
            }

            var player = await _db.Players
                         .Include(x => x.User)
                         .SingleOrDefaultAsync(x => x.User.UserName == profile.Username);

            if (player == null)
            {
                throw new ArgumentException($"No player found with username {profile.Username}");
            }

            player.PreferredRole  = profile.PreferredRoles;
            player.LookingForTeam = profile.LookingForTeam;

            _db.Update(player);
            await _db.SaveChangesAsync();

            return(player);
        }
Beispiel #3
0
        public async Task CreateDefaultImageForTeamAsync(Team team)
        {
            var image = await GetDefaultImageAsync(Defaults.TeamImage);

            team.TeamImage = image;

            _db.Update(team);

            await _db.SaveChangesAsync();
        }
        public async Task <Notification> ReadAsync(DataTransferObjects.Notification note, string username)
        {
            var user = await EnsureGetUserAsync(username);

            var entity = await _db.Notifications.SingleOrDefaultAsync(x => x.NotificationId == note.NotificationId);

            if (entity != null)
            {
                entity.Read = true;
                _db.Update(entity);
                await _db.SaveChangesAsync();
            }

            return(entity);
        }
        public async Task CreateNewTeamRankingAsync(Team team, Season season)
        {
            if (team == null)
            {
                throw new ArgumentNullException(nameof(team));
            }
            if (season == null)
            {
                throw new ArgumentNullException(nameof(season));
            }

            // Find the worst rank in the basic bracket
            var neverLucky = await _db.RankBrackets
                             .Include(x => x.Season)
                             .SingleOrDefaultAsync(x => x.Type == RankBrackets.NeverLucky && x.Season.SeasonId == season.SeasonId);

            if (neverLucky == null)
            {
                throw new InvalidProgramException("Unable to load baseline bracket for new team");
            }

            var rank = new Rank
            {
                RankBracket = neverLucky,
                Rating      = new Rating {
                    MatchMakingRating = 1500
                }
            };

            team.Rank = rank;

            _db.Add(rank);
            _db.Add(rank.Rating);
            _db.Update(team);

            await _db.SaveChangesAsync();
        }