Esempio n. 1
0
 private void FillOlympiads()
 {
     Olympiads.Clear();
     foreach (var item in db.Olympiads.ToList())
     {
         Olympiads.Add(item);
     }
     OlympiadCount = Olympiads.Count;
 }
        public void PopulateDropdown()
        {
            Olympiads.Clear();
            var context = DataEntitiesProvider.Provide();

            foreach (var o in context.Olympiad_Infoes.OrderByDescending(x => x.StartDate))
            {
                Olympiads.Add(new OlympiadVm {
                    Text = o.FullTitle(), Id = o.Id
                });
            }

            OlympiadId = Olympiads.First().Id;
        }
        public void PopulateOlympiadDropdown()
        {
            Olympiads.Clear();
            var context = DataEntitiesProvider.Provide();

            foreach (var c in context.Olympiad_Infoes
                     .OrderByDescending(x => x.StartDate))
            {
                Olympiads.Add(new OlympiadVm {
                    Text = c.FullTitle(), Value = c.Id
                });
            }
            CurrentOlympiadId = Olympiads.First().Value;
        }
        public void PopulateEvents()
        {
            Events.Clear();
            if (ContestantId == null)
            {
                return;
            }

            EditingThePast = (CurrentOlympiadId != Olympiads.First().Value);

            var context    = DataEntitiesProvider.Provide();
            var olympiadId = CurrentOlympiadId;
            var olympiad   = context.Olympiad_Infoes.First(x => x.Id == CurrentOlympiadId);

            IsJuniorForOlympiad = Contestant.IsJuniorForOlympiad(DateOfBirth, olympiad);
            var contestantId = int.Parse(ContestantId);
            var entrants     = context.Entrants
                               .Where(x => x.Event.OlympiadId == olympiadId && x.Mind_Sport_ID == contestantId)
                               .OrderBy(x => x.Event.Code).ToList();

            var allFees = context.Fees.ToList();
            var fees    = (IsJuniorForOlympiad)
                ? allFees.ToDictionary(x => x.Code, x => x.Concession)
                : allFees.ToDictionary(x => x.Code, x => x.Adult);

            foreach (var e in entrants)
            {
                // TODO: this is really an EntrantVm not an EventVm
                Events.Add(new EventVm()
                {
                    EventId          = e.EventId.Value,
                    Absent           = e.Absent,
                    EventCode        = e.Event.Code,
                    EventName        = e.Event.Mind_Sport,
                    Fee              = e.Fee,
                    StandardFee      = (e.Event.Entry_Fee != null) ? fees[e.Event.Entry_Fee].Value : 0,
                    IncludedInMaxFee = (e.Event.incMaxFee.HasValue && e.Event.incMaxFee.Value),
                    IsEvent          = (e.Event.Number > 0),
                    Medal            = e.Medal ?? "",
                    JuniorMedal      = e.JuniorMedal ?? "",
                    Partner          = e.Partner ?? "",
                    Penta            = e.Penta_Score.HasValue ? e.Penta_Score.Value.ToString() : "",
                    Rank             = e.Rank.HasValue ? e.Rank.Value : 0,
                    Receipt          = e.Receipt.Value,
                    TieBreak         = e.Tie_break ?? "",
                    Date             = e.Event.Start
                });
            }
        }
Esempio n. 5
0
        protected override void FillCard()
        {
            if (_Id == null)
            {
                return;
            }

            try
            {
                using (PriemEntities context = new PriemEntities())
                {
                    Olympiads olymp = (from ec in context.Olympiads
                                       where ec.Id == GuidId
                                       select ec).FirstOrDefault();

                    if (olymp == null)
                    {
                        return;
                    }

                    OlympTypeId = olymp.OlympTypeId;
                    if (OlympTypeId != 1 || OlympTypeId != 2)
                    {
                        OlympNameId = olymp.OlympNameId;
                    }
                    OlympSubjectId = olymp.OlympSubjectId;
                    if (OlympTypeId != 1 || OlympTypeId != 2)
                    {
                        OlympLevelId = olymp.OlympLevelId;
                    }
                    OlympValueId = olymp.OlympValueId;
                    OriginDoc    = olymp.OriginDoc;

                    DocumentSeries = olymp.DocumentSeries;
                    DocumentNumber = olymp.DocumentNumber;
                    DocumentDate   = olymp.DocumentDate;
                }
            }
            catch (DataException de)
            {
                WinFormsServ.Error("Ошибка при заполнении формы " + de.Message);
            }
        }
        public void Save()
        {
            var           context = DataEntitiesProvider.Provide();
            var           id      = OlympiadId;
            Olympiad_Info o;

            if (id == 0)
            {
                o = new Olympiad_Info()
                {
                    YearOf     = int.Parse(this.YearOf),
                    Number     = this.Number,
                    Title      = this.Title,
                    Venue      = this.Venue,
                    StartDate  = this.StartDate,
                    FinishDate = this.FinishDate,
                    MaxFee     = decimal.Parse(this.MaxFee),
                    MaxCon     = decimal.Parse(this.MaxCon),
                    AgeDate    = this.AgeDate,
                    JnrAge     = int.Parse(this.JnrAge),
                    SnrAge     = int.Parse(this.SnrAge),
                    PentaLong  = int.Parse(this.PentaLong),
                    PentaTotal = int.Parse(this.PentaTotal),
                    Events     = new List <Event>(),
                    Current    = false, // will be sorted out later
                };
                context.Olympiad_Infoes.Add(o);
                context.SaveChanges();
                // So we don't have to do a full refresh of the combo
                Olympiads.RemoveAt(0);
                Olympiads.Insert(0, new OlympiadVm()
                {
                    Text = o.FullTitle(), Id = o.Id
                });
                id = o.Id;
            }
            else
            {
                o            = context.Olympiad_Infoes.FirstOrDefault(x => x.Id == id);
                o.YearOf     = int.Parse(this.YearOf);
                o.Number     = this.Number;
                o.Title      = this.Title;
                o.Venue      = this.Venue;
                o.StartDate  = this.StartDate;
                o.FinishDate = this.FinishDate;
                o.MaxFee     = decimal.Parse(this.MaxFee);
                o.MaxCon     = decimal.Parse(this.MaxCon);
                o.AgeDate    = this.AgeDate;
                o.JnrAge     = int.Parse(this.JnrAge);
                o.SnrAge     = int.Parse(this.SnrAge);
                o.PentaLong  = int.Parse(this.PentaLong);
                o.PentaTotal = int.Parse(this.PentaTotal);
                o.Current    = false;   // will be sorted out later
            }
            context.SaveChanges();
            // Now update the events and locations. Need to do here to have the reference back to the Olympiad
            foreach (var existingEvent in o.Events.ToList())
            {
                if (!Events.Any(x => x.Id == existingEvent.EIN))
                {
                    o.Events.Remove(existingEvent);
                    context.Events.Remove(existingEvent);
                }
            }
            foreach (var existingLocation in o.Locations.ToList())
            {
                if (!Locations.Any(x => x.Id == existingLocation.Id))
                {
                    o.Locations.Remove(existingLocation);
                    context.Locations.Remove(existingLocation);
                }
            }
            foreach (var evm in Events)
            {
                if (evm.Id == 0)
                {
                    var game = context.Games.FirstOrDefault(x => evm.Code.StartsWith(x.Code));
                    if (game == null)
                    {
                        throw new ArgumentOutOfRangeException("No Game for code " + evm.Code);
                    }

                    var evt = new Event()
                    {
                        Mind_Sport    = evm.Name,
                        Code          = evm.Code,
                        Olympiad_Info = o,
                        Game          = game,
                        MAX_Number    = 70,
                        ConsistentWithBoardability = true,
                        PentamindFactor            = 1.0f
                                                     // TODO more stuff here
                    };
                    o.Events.Add(evt);
                }
                else
                {
                    var evt = context.Events.Find(evm.Id);
                    // We're not doing any update here?
                }
            }
            foreach (var loc in Locations)
            {
                if (loc.Id == 0)
                {
                    o.Locations.Add(new Location()
                    {
                        Location1 = loc.Name, Olympiad_Info = o, YEAR = o.YearOf
                    });
                }
                // Not doing updates here
            }
            context.SaveChanges();

            // Make sure Current is set properly
            var oldCurrents = context.Olympiad_Infoes.Where(x => x.Current).ToList();

            oldCurrents.ForEach(ol => ol.Current = false);
            var newCurrent = context.Olympiad_Infoes.OrderByDescending(x => x.StartDate).First();

            newCurrent.Current = true;
            context.SaveChanges();

            var eventIndexer = new EventIndexer();

            eventIndexer.IndexEvents(id);

            IsDirty    = false;
            OlympiadId = id;
        }
        public void PopulateDropdown(string eventCode = null, int olympiadId = -1)
        {
            Events.Clear();
            var context = DataEntitiesProvider.Provide();

            Olympiad_Info currentOlympiad;

            if (olympiadId < 1)
            {
                currentOlympiad = context.Olympiad_Infoes.OrderByDescending(x => x.StartDate).First();
            }
            else
            {
                currentOlympiad = context.Olympiad_Infoes.First(x => x.Id == olympiadId);
            }
            CurrentOlympiadId = currentOlympiad.Id;

            foreach (var e in currentOlympiad.Events.Where(x => !x.Code.StartsWith("ZZ"))
                     .OrderBy(x => x.Code))
            {
                Events.Add(new EventVm {
                    Text = e.Code + " " + e.Mind_Sport, Value = e.Code
                });
            }

            if (eventCode == null)
            {
                EventCode = (Events.Any()) ? Events.First().Value : null;
            }
            else
            {
                EventCode = eventCode;
            }

            Types.Clear();
            Types.Add(new TypeVm()
            {
                Value = null, Text = "(normal)"
            });
            Types.Add(new TypeVm()
            {
                Value = "Beginners'", Text = "Beginners'"
            });

            Fees.Clear();
            Fees.Add(new EntryFeeVm()
            {
                Value = null, Text = "(none)"
            });
            foreach (var f in context.Fees.OrderBy(x => x.Code))
            {
                Fees.Add(new EntryFeeVm()
                {
                    Value = f.Code, Text = f.DropdownText
                });
            }

            Locations.Clear();
            Locations.Add(new LocationVm()
            {
                Value = null, Text = "(no location)"
            });
            foreach (var l in currentOlympiad.Locations.OrderBy(x => x.Location1))
            {
                Locations.Add(new LocationVm()
                {
                    Value = l.Location1, Text = l.Location1
                });
            }

            Olympiads.Clear();
            foreach (var o in context.Olympiad_Infoes.OrderByDescending(x => x.StartDate))
            {
                Olympiads.Add(new OlympiadVm {
                    Text = o.FullTitle(), Id = o.Id
                });
            }
        }