public ActionResult Create([Bind(Include = "ClubId,ClubName,CreationDate,adminID")] Club club)
        {
            if (ModelState.IsValid)
            {
                db.Clubs.Add(club);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(club));
        }
Exemple #2
0
 public ActionResult Create(Country country)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _context.Add(country);
             _context.SaveChanges();
             return(RedirectToAction(nameof(Index)));
         }
         return(View(country));
     }
     catch
     {
         return(View(country));
     }
 }
        private void SeedStudentMembers(ClubsContext context)
        {
            List <Club> clubs = context.Clubs.ToList();

            foreach (var club in clubs)
            {
                //takes all the student ID's from the student table and associates a Random Guid with it
                var randomStudentSet = context.Students
                                       .Select(s => new { s.StudentID, r = Guid.NewGuid() });

                //takes in the set of student Ids and sorts it based on the Guid. Because Guids are random this will give us a random list of students
                List <string> subset = randomStudentSet
                                       .OrderBy(s => s.r)
                                       .Select(s => s.StudentID)
                                       .Take(10)
                                       .ToList();

                List <Student> selectedStudents = new List <Student>();

                foreach (string s in subset)
                {
                    selectedStudents.Add(context.Students.First(st => st.StudentID == s));
                }

                foreach (Student s in selectedStudents)
                {
                    context.Members.AddOrUpdate(m => m.StudentID,
                                                new Member
                    {
                        AssociatedClub = club.ClubId,
                        StudentID      = s.StudentID
                    });
                    context.SaveChanges();
                }

                context.SaveChanges();
            }
        }
Exemple #4
0
        public async Task PlaySeason(string season)
        {
            var s = new Season()
            {
                Name = season
            };
            ClubsContext dbContext = new ClubsContext();

            dbContext.Entry(s).State = EntityState.Added;
            dbContext.SaveChanges();
            MainController mainController = new MainController(dbContext);

            mainController.SeasonPlay(s);

            await Clients.All.SendAsync("PlaySeason", "Season is played look at stats");
        }
Exemple #5
0
        public string Register([FromBody] User userF)
        {
            var  login    = userF.Login;
            var  password = SecurePasswordHasher.Hash(userF.Password);
            var  token    = SecurePasswordHasher.Hash(login + password);
            User user     = new User()
            {
                Login    = login,
                Password = password,
                Token    = token
            };

            _dbContext.Add(user);
            _dbContext.SaveChanges();
            return("Done");
        }
Exemple #6
0
        public async Task <IActionResult> AddClubAction(IFormCollection data)
        {
            int count = _dbContext.Clubs.OrderBy(c => - c.Id).Take(1).ToList()[0].Id;

            Console.WriteLine(count);
            var club = new Club()
            {
                Id       = count + 1,
                Name     = data["Name"],
                Logo     = data["Logo"],
                LeagueId = Int32.Parse(data["LeagueId"])
            };

            _dbContext.Add(club);
            _dbContext.SaveChanges();

            for (int i = 1; i <= 11; i++)
            {
                var player = new Player()
                {
                    Name     = data["PlayerName_" + i],
                    Age      = 22,
                    Photo    = "",
                    Nation   = "USSR",
                    Flag     = "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Flag_of_the_Soviet_Union.svg/800px-Flag_of_the_Soviet_Union.svg.png",
                    Score    = Int32.Parse(data["PlayerScore_" + i]),
                    Position = data["PlayerPosition_" + i],
                    Number   = Int32.Parse(data["PlayerNumber_" + i]),
                    ClubId   = club.Id
                };
                _dbContext.Entry(player).State = EntityState.Added;
                _dbContext.SaveChanges();
            }

            return(View());
        }