Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="auto"></param>
        public void AddPost(string text, bool auto = false)
        {
            var Post = new Board()
            {
                Author = auto ? "POL-2018" : Helpers.UserName(), PostDate = DateTime.Now, Text = text
            };

            db.Board.Add(Post);
            db.SaveChanges();
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rank"></param>
        public void AddToArchive(List <Rank> rank)
        {
            var RankArch = db.RankArch.ToList();

            int RN = 1;

            if (RankArch != null)
            {
                RN = RankArch.Count + 1;
            }

            var matches = db.Match.ToList();

            var Ranks       = new List <Ranks>();
            var matchesArch = new List <MatchArched>();

            foreach (var r in rank)
            {
                var rankA = new Ranks()
                {
                    Goals     = r.Goals,
                    Lost      = r.Lost,
                    LostGoals = r.LostGoals,
                    Played    = r.Played,
                    Points    = r.Points,
                    Position  = r.Position,
                    Uname     = r.Uname,
                    Won       = r.Won
                };
                Ranks.Add(rankA);
            }
            foreach (var m in matches)
            {
                var match = new MatchArched()
                {
                    Team1      = m.Team1,
                    Team2      = m.Team2,
                    Team1Score = m.Team1Score,
                    Team2Score = m.Team2Score,
                    Date       = m.Date
                };
                matchesArch.Add(match);
            }
            var RA = new RankArch()
            {
                RoundNumber = RN,
                Ranks       = Ranks,
                MatchArched = matchesArch,
                From        = matches.Min(m => m.Date),
                To          = db.RoundDate.SingleOrDefault().RoundEndDatetime
            };

            db.RankArch.Add(RA);
            db.SaveChanges();
        }
Example #3
0
        public IActionResult Create([FromBody] Rank rank)
        {
            if (rank == null)
            {
                return(BadRequest());
            }

            _context.Ranks.Add(rank);
            _context.SaveChanges();

            return(CreatedAtRoute("GetRanks", new { id = rank.Id }, rank));
        }
Example #4
0
        public ActionResult AddCaptainToMember()
        {
            var users = db.Users.Where(u => u.IsAdmin == false).ToList();

            foreach (var u in users)
            {
                u.Members.Add(new Member()
                {
                    IsCaptain = true, MName = u.Captain
                });
            }
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Example #5
0
        private static void AddWeeklyRanking(RankContext context, Guild guild, DateTime?rankingDate = null)
        {
            rankingDate = GetRankingUpdatedDate(rankingDate);

            List <Rank> currentWeekRanks = new List <Rank>();

            foreach (var characterId in guild.Characters.Where(C => C.IsActivated).Select(C => C.Id))
            {
                var character = context.Characters.Include("Guild").Include("Ranks")
                                .FirstOrDefault(C => C.Id == characterId);

                var currentWeekRank = character.Ranks.FirstOrDefault(R => R.Date.GetValueOrDefault() == rankingDate);
                if (currentWeekRank != null)
                {
                    currentWeekRanks.Add(currentWeekRank);
                }
            }

            currentWeekRanks = currentWeekRanks.OrderBy(R => R.Ranking).ToList();

            for (int i = 1; i <= currentWeekRanks.Count; i++)
            {
                var rank       = currentWeekRanks[i - 1];
                var weeklyRank = new WeeklyRank {
                    CharacterId = rank.CharacterId, GuildId = guild.Id, Ranking = i, Date = rankingDate
                };
                context.WeeklyRanks.Add(weeklyRank);
                context.SaveChanges();
            }
        }
Example #6
0
        private static Character CreateCharacter(RankContext context, string characterName, Guild guild, string guildPositionDisplay)
        {
            var character     = context.Characters.Include("Guild").Include("Ranks").FirstOrDefault(C => C.Name == characterName);
            var guildPosition = EnumHelper.ParseDisplayToEnum <GuildPositions>(guildPositionDisplay);

            if (character == null)
            {
                character = new Character {
                    Name = characterName, GuildId = guild.Id, GuildPosition = guildPosition
                };
                context.Characters.Add(character);
            }

            if (character.GuildId != guild.Id)
            {
                character.GuildId = guild.Id;
            }

            if (character.GuildPosition != guildPosition)
            {
                character.GuildPosition = guildPosition;
            }

            context.SaveChanges();

            return(character);
        }
Example #7
0
        private static int UpdateGuildWeeklyRanking(RankContext context, DateTime?rankingDate = null)
        {
            rankingDate = GetRankingUpdatedDate(rankingDate);

            foreach (var guild in context.Characters.Include(C => C.Guild)
                     .Include(C => C.Ranks)
                     .Where(C => C.IsActivated && C.GuildId != null)
                     .GroupBy(C => C.GuildId))
            {
                var currentWeekRanks = guild.Select(C => new { C.Id, C.Name, Rank = C.Ranks?.FirstOrDefault(R => R.Date.GetValueOrDefault() == rankingDate) })
                                       .Where(CWR => CWR.Rank != null)
                                       .OrderBy(CWR => CWR.Rank.Ranking)
                                       .ToList();

                for (int i = 1; i <= currentWeekRanks.Count; i++)
                {
                    var rank = currentWeekRanks[i - 1];
                    if (context.WeeklyRanks.Any(WR => WR.CharacterId == rank.Id && WR.Date == rankingDate))
                    {
                        continue;
                    }

                    var weeklyRank = new WeeklyRank {
                        CharacterId = rank.Id, GuildId = guild.Key, Ranking = i, Date = rankingDate
                    };
                    context.WeeklyRanks.Add(weeklyRank);
                }
            }

            return(context.SaveChanges());
        }
Example #8
0
        private static Character GetOrCreateCharacter(RankContext context, string characterName, Guid?guildId, string guildPositionDisplay)
        {
            var            character     = context.Characters.FirstOrDefault(C => C.Name == characterName);
            GuildPositions?guildPosition = null;

            if (String.IsNullOrWhiteSpace(guildPositionDisplay) != true)
            {
                guildPosition = EnumHelper.ParseDisplayToEnum <GuildPositions>(guildPositionDisplay);
            }

            if (character == null)
            {
                character = new Character {
                    Name = characterName, GuildId = guildId, GuildPosition = guildPosition
                };
                context.Characters.Add(character);
            }
            else
            {
                if (character.GuildId != guildId)
                {
                    character.GuildId = guildId;
                }
                if (character.GuildPosition != guildPosition)
                {
                    character.GuildPosition = guildPosition;
                }
            }

            context.SaveChanges();

            return(character);
        }
Example #9
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var sha256 = Crypto.SHA256(model.Password);

                var name = Helpers.UserName();

                var user = db.Users.Where(u => u.Name == name).Single();

                user.Password       = sha256;
                user.ForgotPassword = false;
                db.SaveChanges();

                accountManager.DeleteResetPasswordToken(user.UserId);

                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }
Example #10
0
        public RankController(RankContext context)
        {
            _context = context;

            if (_context.Ranks.Count() == 0)
            {
                _context.Ranks.Add(new Rank {
                    Name = "White"
                });
                _context.SaveChanges();
            }
        }
Example #11
0
        private static Guild CreateGuild(RankContext context, string guildName)
        {
            var guild = context.Guilds.Include("Characters").FirstOrDefault(G => G.Name == guildName);

            if (guild == null)
            {
                guild = new Guild {
                    Name = guildName
                };
                context.Guilds.Add(guild);
                context.SaveChanges();
            }

            return(guild);
        }
Example #12
0
        private static Rank UpdateRanking(RankContext context, Character member, string ranking, DateTime rankingDate)
        {
            var rank = member.Ranks?.FirstOrDefault(R => R.Date.Value == rankingDate);

            if (rank == null)
            {
                rank = new Rank {
                    CharacterId = member.Id, Ranking = Int32.Parse(ranking), Date = rankingDate
                };
                context.Ranks.Add(rank);
                context.SaveChanges();

                Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}] Updated the Ranking. Name={member.Name}, Rank={ranking}");
            }

            return(rank);
        }
Example #13
0
        private static Guild GetOrCreateGuild(RankContext context, string guildName)
        {
            if (String.IsNullOrWhiteSpace(guildName))
            {
                throw new ArgumentException("The guild name is invalid.", nameof(guildName));
            }

            var guild = context.Guilds.FirstOrDefault(G => G.Name == guildName);

            if (guild == null)
            {
                guild = new Guild {
                    Name = guildName
                };
                context.Guilds.Add(guild);
                context.SaveChanges();
            }

            return(guild);
        }
Example #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="match"></param>
        public void AddMatch(Match match)
        {
            match.NotAddedBy = Helpers.UserName() == match.Team1 ? match.Team2 : match.Team1;
            match.Date       = DateTime.Now;
            if (match.Colour == "niebieska")
            {
                string tempName = "";
                string tempMembersGoalsSplitTeam1 = "";
                int    tempScore;
                tempName  = match.Team1;
                tempScore = match.Team1Score;
                tempMembersGoalsSplitTeam1 = match.MembersGoalsSplitTeam1;

                match.Team1                  = match.Team2;
                match.Team1Score             = match.Team2Score;
                match.Team2                  = tempName;
                match.Team2Score             = tempScore;
                match.MembersGoalsSplitTeam1 = match.MembersGoalsSplitTeam2;
                match.MembersGoalsSplitTeam2 = tempMembersGoalsSplitTeam1;
            }
            db.Match.Add(match);
            db.SaveChanges();
        }
Example #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="user"></param>
 public void AddUser(IUser user)
 {
     user.stat = Status.Registration;
     if (user is Users)
     {
         Users u = user as Users;
         db.Users.Add(u);
     }
     else if (user is Fans)
     {
         db.Fans.Add(user as Fans);
     }
     db.SaveChanges();
 }