public void UpdateOlympicEvent(OlympicEvent olympicEvent)
        {
            using (var context = new OfficeOlympicsDbEntities())
            {
                var existingEvent = context.OlympicEvents.SingleOrDefault(obj => obj.Id == olympicEvent.Id);

                if (existingEvent == null)
                {
                    throw new InvalidOperationException($"Olympic Event '{olympicEvent.EventName}' doesn't exist.");
                }

                if (olympicEvent.Icon != null)
                {
                    Func <string> generateIconPath = () => Path.Combine(_iconPath, existingEvent.IconFileName);
                    File.Delete(generateIconPath());
                    existingEvent.IconFileName = $"{Path.GetFileNameWithoutExtension(existingEvent.IconFileName)}{Path.GetExtension(olympicEvent.Icon.UploadedFileName)}";
                    File.WriteAllBytes(generateIconPath(), olympicEvent.Icon.Bytes);
                }

                existingEvent.EventName     = olympicEvent.EventName;
                existingEvent.EventTypeId   = olympicEvent.EventTypeId;
                existingEvent.Description   = olympicEvent.Description;
                existingEvent.Specification = olympicEvent.Specification;
                existingEvent.IsActive      = olympicEvent.IsActive;

                context.SaveChanges();
            }
        }
 public bool NameIsUnique(OlympicEvent olympicEvent)
 {
     using (var context = new OfficeOlympicsDbEntities())
     {
         return(context.OlympicEvents.SingleOrDefault(obj => obj.EventName == olympicEvent.EventName && obj.Id != olympicEvent.Id) == null);
     }
 }
        public static RecordListViewModel Build(IEnumerable <Record> records, OlympicEvent olympicEvent)
        {
            var viewModel = new RecordListViewModel();

            viewModel.Records = RecordViewModel.BuildList(records);
            viewModel.Event   = EventViewModel.Build(olympicEvent);

            return(viewModel);
        }
Ejemplo n.º 4
0
        public static EditEventViewModel Build(OlympicEvent olympicEvent, IEnumerable <EventType> eventTypes)
        {
            var viewModel = new EditEventViewModel();

            viewModel.Event = EventViewModel.Build(olympicEvent);
            viewModel.EventTypeSelectList = new SelectList(eventTypes, nameof(EventType.Id), nameof(EventType.Description));

            return(viewModel);
        }
Ejemplo n.º 5
0
        public static NewRecordViewModel Build(OlympicEvent olympicEvent, IEnumerable <Competitor> competitors)
        {
            var viewModel = new NewRecordViewModel();

            viewModel.Competitors = new SelectList(CompetitorViewModel.BuildList(competitors), nameof(CompetitorViewModel.CompetitorId), nameof(CompetitorViewModel.FullName));
            viewModel.Record      = new RecordViewModel();
            viewModel.Event       = EventViewModel.Build(olympicEvent);

            return(viewModel);
        }
Ejemplo n.º 6
0
    // Selects a new map from event and loads it
    public void LoadEvent(OlympicEvent e)
    {
        currentRound++; // Increment round on new event

        currentEvent = e;

        // Randomly select next map
        string nextMap = e.eventMaps[random.Next(e.eventMaps.Count)];

        this.LoadMap(nextMap);
    }
Ejemplo n.º 7
0
        public static EventBoardEventViewModel Build(OlympicEvent olympicEvent)
        {
            var viewModel = new EventBoardEventViewModel();

            viewModel.EventId       = olympicEvent.Id;
            viewModel.EventTypeId   = olympicEvent.EventTypeId;
            viewModel.EventName     = olympicEvent.EventName;
            viewModel.Description   = olympicEvent.Description;
            viewModel.Specification = olympicEvent.Specification;
            viewModel.IconFileName  = olympicEvent.IconFileName;
            viewModel.Records       = EventBoardRecordViewModel.BuildList(olympicEvent.Records);

            return(viewModel);
        }
Ejemplo n.º 8
0
        public OlympicEvent Map()
        {
            var olympicEvent = new OlympicEvent();

            olympicEvent.Id            = EventId;
            olympicEvent.EventName     = EventName.AsProperNoun();
            olympicEvent.EventTypeId   = EventTypeId;
            olympicEvent.Description   = Description?.Trim() ?? string.Empty;
            olympicEvent.Specification = Specification?.Trim() ?? string.Empty;
            olympicEvent.DateAdded     = EventId == 0 ? DateTime.Now : DateAdded;
            olympicEvent.IsActive      = IsActive;

            return(olympicEvent);
        }
Ejemplo n.º 9
0
        private void ExplicitLoadOlympicEvent(OfficeOlympicsDbEntities context, OlympicEvent olympicEvent)
        {
            (from record in context.Entry(olympicEvent).Collection(e => e.Records).Query()
             where record.Competitor.IsActive
             group record by record.CompetitorId into groupedRecords
             select groupedRecords.OrderByDescending(record => record.Score).FirstOrDefault() into record
             orderby record.Score descending
             select record).Take(3).Load();

            context.Entry(olympicEvent).Reference(obj => obj.EventType).Load();

            foreach (var record in olympicEvent.Records)
            {
                context.Entry(record).Reference(obj => obj.Competitor).Load();
            }
        }
Ejemplo n.º 10
0
        public void DeleteOlympicEvent(OlympicEvent olympicEvent)
        {
            using (var context = new OfficeOlympicsDbEntities())
            {
                var existingEvent = context.OlympicEvents.SingleOrDefault(obj => obj.Id == olympicEvent.Id);

                if (existingEvent == null)
                {
                    throw new InvalidOperationException($"Olympic Event '{olympicEvent.EventName}' doesn't exist.");
                }

                existingEvent.IsActive = false;

                context.SaveChanges();
            }
        }
Ejemplo n.º 11
0
        public static EventViewModel Build(OlympicEvent olympicEvent)
        {
            var viewModel = new EventViewModel();

            viewModel.EventId       = olympicEvent.Id;
            viewModel.EventName     = olympicEvent.EventName;
            viewModel.EventType     = olympicEvent.EventType.Description;
            viewModel.EventTypeId   = olympicEvent.EventType.Id;
            viewModel.Description   = olympicEvent.Description;
            viewModel.Specification = olympicEvent.Specification;
            viewModel.DateAdded     = olympicEvent.DateAdded;
            viewModel.IsActive      = olympicEvent.IsActive;
            viewModel.IconFileName  = olympicEvent.IconFileName;

            return(viewModel);
        }
Ejemplo n.º 12
0
        public void InsertOlympicEvent(OlympicEvent olympicEvent)
        {
            using (var context = new OfficeOlympicsDbEntities())
            {
                Guid iconFileNameGuid = Guid.NewGuid();
                olympicEvent.IconFileName = $"{iconFileNameGuid}{Path.GetExtension(olympicEvent.Icon?.UploadedFileName ?? "default.png")}";

                if (olympicEvent.Icon != null)
                {
                    File.WriteAllBytes(Path.Combine(_iconPath, olympicEvent.IconFileName), olympicEvent.Icon.Bytes);
                }

                context.OlympicEvents.Add(olympicEvent);

                context.SaveChanges();
            }
        }