Exemplo n.º 1
0
        private void OlympiadTreeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            GetPropForSelectedService service = new GetPropForSelectedService();

            DateTime currOlympDate = new DateTime();

            foreach (var o in service.GetOlympiads())
            {
                string bufName;
                string gettingOlympName;

                bufName          = ((sender as TreeView).SelectedItem as TreeViewItem).Header.ToString();
                gettingOlympName = $"{o.Type.Name} olympiad in {o.Country.Name} {String.Format("{0:y}", o.Date)}";

                if (bufName == gettingOlympName)
                {
                    currOlympDate = o.Date;
                }
            }

            if (CurrentOlympaid != null)
            {
                if (CurrentOlympaid.Date == currOlympDate)
                {
                    return;
                }
            }

            CurrentOlympaid = service.GetOlympiads().FirstOrDefault(x => x.Date == currOlympDate);

            MainStackPanel.Visibility = Visibility.Visible;
            InitContentUI();
        }
Exemplo n.º 2
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            if (DatePicker.DisplayDate == null)
            {
                MessageBox.Show("Date can`t be null.");
                return;
            }

            Olympiad newType = new Olympiad();

            GetPropForSelectedService getService = new GetPropForSelectedService();

            newType.Date    = DatePicker.SelectedDate.Value;
            newType.Type    = getService.GetOlympTypes().FirstOrDefault(x => x.Name == (OlympTypeComboBox.SelectedItem as OlympType).Name);
            newType.Country = getService.GetCountry().FirstOrDefault(x => x.Name == (CountryComboBox.SelectedValue as Country).Name);


            foreach (var o in getService.GetOlympiads())
            {
                if (o.Date == newType.Date)
                {
                    MessageBox.Show($"Olympiads in {o.Date.ToString("0:d")} alredy exists.");
                }
            }

            AddingService addService = new AddingService();

            addService.AddOlympiad(newType);
            MessageBox.Show("Olympiad adding");
        }
Exemplo n.º 3
0
        public void DeleteItem(int id)
        {
            Olympiad olympiadToDelete = new Olympiad()
            {
                OlympiadID = id
            };

            _database.Olympiads.Delete(olympiadToDelete.OlympiadID);
            _database.Save();
        }
Exemplo n.º 4
0
        public OlympiadDTO GetItem(int?id)
        {
            Olympiad item = _database.Olympiads.Get(id);

            return(new OlympiadDTO
            {
                OlympiadID = item.OlympiadID,
                OlympiadName = item.OlympiadName,
                OlympiadLevel = item.OlympiadLevel,
                OlympiadStartDate = item.OlympiadStartDate,
                OlympiadEndDate = item.OlympiadEndDate,
                OlympiadDirection = item.OlympiadDirection,
                OlympiadType = item.OlympiadType,
                UniversityID = item.UniversityID
            });
        }
Exemplo n.º 5
0
        public void UpdateItem(OlympiadDTO item)
        {
            Olympiad olympiad = new Olympiad
            {
                OlympiadID        = item.OlympiadID,
                OlympiadName      = item.OlympiadName,
                OlympiadLevel     = item.OlympiadLevel,
                OlympiadStartDate = item.OlympiadStartDate,
                OlympiadEndDate   = item.OlympiadEndDate,
                OlympiadDirection = item.OlympiadDirection,
                OlympiadType      = item.OlympiadType,
                UniversityID      = item.UniversityID
            };

            _database.Olympiads.Update(olympiad);
            _database.Save();
        }
Exemplo n.º 6
0
        public Task UpdateOlympiad(Olympiad olympiad)
        {
            var foundOlympiad = GetOlympiad(olympiad.Id).Result;

            if (foundOlympiad == null)
            {
                AddOlympiad(olympiad);
            }
            else
            {
                if (foundOlympiad != olympiad)
                {
                    _olympiads.Remove(foundOlympiad);
                    _olympiads.Add(olympiad);
                }
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 7
0
        private bool AddOlympiadCommandCanExecute(object arg)
        {
            if (string.IsNullOrEmpty(NewOlympiadYear) || string.IsNullOrEmpty(NewOlympiadCity) || NewOlympiadCountry == null)
            {
                return(false);
            }

            try
            {
                var year = int.Parse(NewOlympiadYear);
                if (!Olympiad.IsValidYear(year) || db.Olympiads.ToList().Any(o => o.Year == year))
                {
                    return(false);
                }
            }
            catch (Exception) { return(false); }

            return(true);
        }
Exemplo n.º 8
0
        private void AddOlympiadCommandExecute(object obj)
        {
            string imagePath = string.IsNullOrEmpty(NewOlympiadImage) ? @"C:\Users\ibrah\source\repos\Olympics\Olympics\Images\Olympiads\Default.png"
                : NewOlympiadImage;

            var olymp = new Olympiad(
                int.Parse(NewOlympiadYear),
                IsSummerOlympiad ? Season.Summer : Season.Winter,
                NewOlympiadCountry, NewOlympiadCity, imagePath);

            db.Olympiads.Add(olymp);
            db.SaveChanges();

            FillOlympiads();

            NewOlympiadYear    = string.Empty;
            NewOlympiadCity    = string.Empty;
            NewOlympiadImage   = string.Empty;
            NewOlympiadCountry = null;
            IsSummerOlympiad   = true;

            systemClass.ShowMessageBox("Info", "Olympiad has been added!");
        }
Exemplo n.º 9
0
 public void AddOlympiad(Olympiad olympiad)
 {
     db.Olympiads.Add(olympiad);
     db.SaveChanges();
 }
Exemplo n.º 10
0
 public Task RemoveOlympiad(Olympiad olympiad)
 {
     _olympiads.Remove(olympiad);
     return(Task.CompletedTask);
 }
Exemplo n.º 11
0
 public Task AddOlympiad(Olympiad olympiad)
 {
     _olympiads.Add(olympiad);
     return(Task.CompletedTask);
 }