public IActionResult Create([Bind("TimeTableID,GroupID,Time_visits,Days_of_the_week")] TimeTable timeTable)
 {
     if (ModelState.IsValid)
     {
         _context.Add(timeTable);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["GroupID"] = new SelectList(_context.Groups, "GroupID", "GroupID", timeTable.GroupID);
     return(View(timeTable));
 }
Esempio n. 2
0
 public IActionResult Create([Bind("GroupID,InstructorID,Name,Count_of_visitor")] Group @group)
 {
     if (ModelState.IsValid)
     {
         _context.Add(@group);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["InstructorID"] = new SelectList(_context.Instructors, "InstructorID", "InstructorID", @group.InstructorID);
     return(View(@group));
 }
 public IActionResult Create([Bind("VisitorID,GroupID,Name,Surname,Midname,Passport")] Visitor visitor)
 {
     if (ModelState.IsValid)
     {
         _context.Add(visitor);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["GroupID"] = new SelectList(_context.Groups, "GroupID", "GroupID", visitor.GroupID);
     return(View(visitor));
 }
        public ActionResult Create([Bind(Include = "SportsmanID,SurName,Name,BirthDay")] Sportsman sportsman)
        {
            if (ModelState.IsValid)
            {
                db.Sportsmans.Add(sportsman);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sportsman));
        }
        public IActionResult Create([FromBody] Sport item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _context.Sports.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetSport", new { id = item.Id }, item));
        }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "HobbyID,Name,TypeOfSportID,ClientID,RowVersion")] Hobby hobby)
        {
            if (ModelState.IsValid)
            {
                db.Hobbies.Add(hobby);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ClientID      = new SelectList(db.Clients, "ClientID", "ClientID", hobby.ClientID);
            ViewBag.TypeOfSportID = new SelectList(db.TypesOfSports, "TypeOfSportID", "TypeOfSportID", hobby.TypeOfSportID);
            return(View(hobby));
        }
        public ActionResult Create([Bind(Include = "DeliveryID,DisciplineID,SportsmanID")] Delivery delivery)
        {
            if (ModelState.IsValid)
            {
                db.Deliveries.Add(delivery);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DisciplineID = new SelectList(db.Disciplines, "DisciplineID", "Name", delivery.DisciplineID);
            ViewBag.SportsmanID  = new SelectList(db.Sportsmans, "SportsmanID", "SurName", delivery.SportsmanID);
            return(View(delivery));
        }
Esempio n. 8
0
        public IActionResult AddVisitors(Visitor visitor)
        {
            CookieOptions cookie = new CookieOptions();

            cookie.Expires = DateTime.Now.AddMinutes(1);

            if (Request.Cookies["coockiesVisitors"] == null)
            {
                string value = JsonConvert.SerializeObject(visitor);
                Response.Cookies.Append("coockiesVisitors", value);
            }

            _context.Visitors.Add(visitor);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 9
0
 public static void AddSports(List <Sport> teams)
 {
     using (SportContext sc = new SportContext())
     {
         sc.Sports.AddRange(teams);
         sc.SaveChanges();
     }
 }
Esempio n. 10
0
 public static void AddPlayers(List <Player> players)
 {
     using (SportContext sc = new SportContext())
     {
         sc.Players.AddRange(players);
         sc.SaveChanges();
     }
 }
Esempio n. 11
0
        public UserOption GetAbout(User user)
        {
            var about = GetUserOptionByKey(user, "about").FirstOrDefault();

            if (about == null)
            {
                string defaultValue = "...";
                about = new UserOption
                {
                    UserId = user.UserId,
                    Key    = "about",
                    Value  = defaultValue
                };

                _context.UsersOptions.Add(about);
                _context.SaveChanges();
            }
            return(about);
        }
        public ActionResult Create(AddAndEditPlayerModel model)
        {
            if (model.FirstName != null && model.LastName != null)
            {
                var player = new Player();
                player.FirstName = model.FirstName;
                player.LastName  = model.LastName;
                player           = db.Players.Add(player);
                if (model.SelctedTeamIds != null)
                {
                    var contracts = model.SelctedTeamIds.Select(idTeam => new Contract
                    {
                        TeamId   = idTeam,
                        PlayerId = model.PlayerId
                    });
                    db.Contracts.AddRange(contracts);
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Esempio n. 13
0
        private static void AddSports(List <SportDTO> sports)
        {
            using (SportContext context = new SportContext())
            {
                foreach (var sport in sports)
                {
                    context.Sports.Add(new Sport()
                    {
                        Id   = sport.Id,
                        Name = sport.Name
                    });
                }

                context.SaveChanges();
            }
        }
 private static void AddSports(List <SportDTO> sports)
 {
     using (SportContext context = new SportContext())
     {
         var list = new List <Sport>(sports.Count);
         foreach (var sport in sports)
         {
             list.Add(new Sport()
             {
                 Id   = sport.Id,
                 Name = sport.Name
             });
         }
         context.Sports.AddRange(list);
         context.SaveChanges();
     }
 }
Esempio n. 15
0
        private static void AddTeams(List <TeamDTO> teams)
        {
            using (SportContext context = new SportContext())
            {
                foreach (var team in teams)
                {
                    context.Teams.Add(new Team()
                    {
                        Name         = team.Name,
                        Id           = team.Id,
                        SportId      = team.SportId,
                        FoundingDate = team.FoundingDate
                    });
                }

                context.SaveChanges();
            }
        }
Esempio n. 16
0
        private static void AddPlayers(List <PlayerDTO> players)
        {
            using (SportContext context = new SportContext())
            {
                foreach (var player in players)
                {
                    context.Players.Add(new Player()
                    {
                        FirstName   = player.FirstName,
                        LastName    = player.LastName,
                        DateOfBirth = player.DateOfBirth,
                        TeamId      = player.TeamId,
                        Id          = player.Id
                    });
                }

                context.SaveChanges();
            }
        }
Esempio n. 17
0
        static void Print()
        {
            using (SportContext context = new SportContext())
            {
                sportsman sportsman = new sportsman();

                String a;
                Console.WriteLine("Введите имя:");
                a = Console.ReadLine();
                sportsman.Name = a;
                Console.WriteLine("Введите Фамилию:");
                a = Console.ReadLine();
                sportsman.Surname = a;
                Console.WriteLine("Введите название игры:");
                a = Console.ReadLine();
                sportsman.Namesport = a;

                context.sportsmens.Add(sportsman);
                context.SaveChanges();
            }
        }
Esempio n. 18
0
        public static void EnsureSeedDataForContext(this SportContext context)
        {
            if (context.Activities.Any())
            {
                return;
            }

            var activities = new List <Activity>()
            {
                new Activity()
                {
                    Name      = "Yoga",
                    Beginning = new DateTime(2017, 12, 3, 15, 0, 0),
                    Ending    = new DateTime(2017, 12, 3, 16, 0, 0),
                    TrainerId = "1"
                }
            };

            context.Activities.AddRange(activities);
            context.SaveChanges();
        }
        private static void AddKids(List <KidDTO> kids)
        {
            using (SportContext context = new SportContext())
            {
                var list = new List <Kid>(kids.Count);

                foreach (var kid in kids)
                {
                    list.Add(new Kid()
                    {
                        FirstName   = kid.FirstName,
                        LastName    = kid.LastName,
                        DateOfBirth = kid.DateOfBirth,
                        PlayerId    = kid.PlayerId,
                        Id          = kid.Id,
                    });
                }
                context.Kids.AddRange(list);
                context.SaveChanges();
            }
        }
        private static void AddPlayers(List <PlayerDTO> players)
        {
            using (SportContext context = new SportContext())
            {
                var list = new List <Player>(players.Count);

                foreach (var player in players)
                {
                    var teamIds = player.Teams.Select(x => x.Id).ToList();
                    list.Add(new Player()
                    {
                        FirstName   = player.FirstName,
                        LastName    = player.LastName,
                        DateOfBirth = player.DateOfBirth,
                        Id          = player.Id,
                        Teams       = context.Teams.Where(y => teamIds.Contains(y.Id)).ToList()
                    });
                }
                context.Players.AddRange(list);
                context.SaveChanges();
            }
        }
Esempio n. 21
0
        private void ProcessSport(Sport sport)
        {
            // If the language does not exist and machine translator exit, use it to translate the sport to that language.
            var targetSportLanguage = sport.Languages.Find(m => m.Language == Language);

            if ((targetSportLanguage == null) && (machineTranslator != null) && (sport.Languages.Count > 0))
            {
                // Find the English sport to be used as the original language.
                var originalSportLanguage = sport.Languages.Find(m => m.Language == "en");

                // If not found take the first sport.
                if (originalSportLanguage == null)
                {
                    originalSportLanguage = sport.Languages[0];
                }

                // Create a new language specific sport using the machine translated properties
                targetSportLanguage = new SportLanguage
                {
                    Language          = Language,
                    MachineTranslated = true,
                    Name        = machineTranslator.Translate(originalSportLanguage.Name, originalSportLanguage.Language, Language),
                    Origin      = machineTranslator.Translate(originalSportLanguage.Origin, originalSportLanguage.Language, Language),
                    Description = machineTranslator.Translate(originalSportLanguage.Description, originalSportLanguage.Language, Language)
                };

                // If the machine translation succeeded add the sport language to the list and sav it to the DB
                if (!string.IsNullOrEmpty(targetSportLanguage.Name) && !string.IsNullOrEmpty(targetSportLanguage.Origin) && !string.IsNullOrEmpty(targetSportLanguage.Description))
                {
                    sport.AddLanguage(targetSportLanguage);
                    context.SaveChanges();
                }
            }

            // Move the active language to the first in the list
            sport.MoveDefaultLanguateToTop(Language);
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            using (SportContext db = new SportContext())
            {
                DbInitializer.Initialize(db);
                Console.WriteLine("1");
                Print("Выборка данных из таблицы Инструкторы", db.Instructors.ToArray());
                Console.WriteLine("\n2\n");

                Print("Выборка данных с заданным условием из таблицы Инструкторы", db.Instructors.Where(a => a.Name == "Александр").ToArray());
                Console.WriteLine("\n3\n");

                var query1 = from o in db.Groups
                             group o.Count_of_visitor by o.GroupID into gr
                             select new
                {
                    groupsId           = gr.Key,
                    Количество_занятий = gr.Sum()
                };
                Print("Выборка данных из таблицы стоящей на стороне 'многие':", query1.ToArray());
                Console.WriteLine("\n4\n");

                var query2 = from o in db.Instructors
                             join c in db.Groups
                             on o.InstructorID equals c.InstructorID
                             orderby c.Name descending
                             select new
                {
                    Имя       = o.Name,
                    Фамилия   = o.Surname,
                    Отчество  = o.Midname,
                    Id_группы = c.GroupID,
                    Количество_посетителей = c.Count_of_visitor,
                };

                Print("Выборка данных из двух таблиц стоящих на стороне 'один-ко-многим':", query2.ToArray());
                Console.WriteLine("\n5\n");

                int count  = 16;
                var query3 = from i in db.Instructors
                             join g in db.Groups
                             on i.InstructorID equals g.InstructorID
                             where (g.Count_of_visitor >= count)
                             orderby g.Name descending
                             select new
                {
                    Имя       = i.Name,
                    Фамилия   = i.Surname,
                    Отчество  = i.Midname,
                    Id_группы = g.GroupID,
                    Количество_посетителей = g.Count_of_visitor,
                };

                Print("Выборка данных с условием по полям двух таблиц стоящих на стороне 'один-ко-многим':", query3.ToArray());
                Console.WriteLine("\n6\n");


                Instructor ins = new Instructor
                {
                    Name       = "Василий",
                    Surname    = "Александров",
                    Midname    = "Андреевич",
                    Aducation  = "Среднее",
                    Experience = 10
                };
                db.Instructors.Add(ins);
                db.SaveChanges();
                Print("Таблица инструкторы после добавления записи: ", db.Instructors.ToArray());
                Console.WriteLine("\n7\n");

                Group group = new Group
                {
                    InstructorID     = 5,
                    Name             = "6666",
                    Count_of_visitor = 20,
                };
                db.Groups.Add(group);
                db.SaveChanges();
                Print("Таблица группы после добавления записи: ", db.Groups.ToArray());
                Console.WriteLine("\n8\n");

                var del = db.Instructors.Where(i => i.InstructorID == 8);
                db.Instructors.RemoveRange(del);
                db.SaveChanges();
                Print("Таблица инструкторы после удаления записи: ", db.Instructors.ToArray());

                Console.WriteLine("\n9\n");

                db.Groups.Remove(db.Groups.ToArray()[5]);
                db.SaveChanges();
                Print("Таблица группы после удаления записи: ", db.Groups.ToArray());

                Console.WriteLine("\n10\n");
                db.Instructors.SingleOrDefault(o => o.InstructorID == db.Instructors.First().InstructorID).Experience = 5;
                db.SaveChanges();
                Print("Обновлённая таблица инструкторы", db.Instructors.ToArray());
            }
        }
Esempio n. 23
0
 public bool Save()
 {
     return(_context.SaveChanges() >= 0);
 }
Esempio n. 24
0
        private static void AddTestData(SportContext context)
        {
            try
            {
                using (StreamReader sr = new StreamReader("api_data_source.txt"))
                {
                    String s = "";

                    while ((s = sr.ReadLine()) != null)
                    {
                        if (s == "Teams:")
                        {
                            while ((s = sr.ReadLine()) != "")
                            {
                                Team t = JsonConvert.DeserializeObject <Team>(s.TrimEnd(','));
                                context.Teams.Add(t);
                            }
                        }
                        else if (s == "Players:")
                        {
                            while ((s = sr.ReadLine()) != "")
                            {
                                Player p = JsonConvert.DeserializeObject <Player>(s.TrimEnd(','));
                                context.Players.Add(p);
                            }
                        }
                        else if (s == "Games:")
                        {
                            while ((s = sr.ReadLine()) != "")
                            {
                                Game g = JsonConvert.DeserializeObject <Game>(s.TrimEnd(','));
                                context.Games.Add(g);
                            }
                        }
                        else if (s == "Player Stats:")
                        {
                            while ((s = sr.ReadLine()) != "")
                            {
                                PlayerStat ps = JsonConvert.DeserializeObject <PlayerStat>(s.TrimEnd(','));
                                context.PlayerStats.Add(ps);
                            }
                        }
                        else if (s == "Game State:")
                        {
                            while ((s = sr.ReadLine()) != "")
                            {
                                GameState gs = JsonConvert.DeserializeObject <GameState>(s.TrimEnd(','));
                                context.GameStates.Add(gs);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            finally {
                context.SaveChanges();
            }


            // var testUser1 = new Models.Player
            // {
            //     id = 1,
            //     name = "Jin",
            //     team_id = 1
            // };

            // context.Players.Add(testUser1);

            // var testPost1 = new Models.Team
            // {
            //     Id = "def234",
            //     UserId = testUser1.Id,
            //     Content = "What a piece of junk!"
            // };

            // context.Posts.Add(testPost1);
        }
Esempio n. 25
0
        public void UpdateStatsCategory(StatsCategory cat)
        {
            _context.StatsCategories.Update(cat);

            _context.SaveChanges();
        }
Esempio n. 26
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using var context = new SportContext(
                      serviceProvider.GetRequiredService <
                          DbContextOptions <SportContext> >());

            // Look for any contestants.
            if (context.Contestants.Any())
            {
                return;   // DB has been seeded
            }

            context.Contestants.AddRange(

                new Contestant {
                FirstName = "Carson", LastName = "Alexander", Age = 15
            },
                new Contestant {
                FirstName = "vojce", LastName = "Gruevski", Age = 21
            },
                new Contestant {
                FirstName = "John", LastName = "rown", Age = 16
            },
                new Contestant {
                FirstName = "Ivan", LastName = "Dzogani", Age = 25
            },
                new Contestant {
                FirstName = "Alexa", LastName = "Google", Age = 17
            },
                new Contestant {
                FirstName = "Sean", LastName = "Stalone", Age = 11
            },
                new Contestant {
                FirstName = "Dime", LastName = "Abramovic", Age = 19
            }

                );

            context.SaveChanges();

            // Look for any sports.
            if (context.Sports.Any())
            {
                return;   // DB has been seeded
            }

            context.Sports.AddRange(
                new Sport {
                SportID = 1, SportTitle = "Football", Description = "This is description for Football"
            },
                new Sport {
                SportID = 2, SportTitle = "Rugby", Description = "This is description for Rugby"
            },
                new Sport {
                SportID = 3, SportTitle = "Basketball", Description = "This is description for Basketball"
            },
                new Sport {
                SportID = 4, SportTitle = "Tennis", Description = "This is description for Tennis"
            }


                );

            context.SaveChanges();
        }
Esempio n. 27
0
 public void Save()
 {
     _context.SaveChanges();
 }