Esempio n. 1
0
        public IActionResult CompetitionInstance(int competitionId, int competitionInstanceId)
        {
            var instanceTask = _competitionService.GetCompetitionInstanceByIdAsync(competitionInstanceId);

            instanceTask.Wait();

            var instance = new CompetitionsInstanceViewModel
            {
                Id            = instanceTask.Result.Id,
                CompetitionId = instanceTask.Result.CompetitionId,
                DateFrom      = instanceTask.Result.DateFrom,
                DateTo        = instanceTask.Result.DateTo,
                Location      = instanceTask.Result.Location,
                CountryId     = instanceTask.Result.CountryId,
                Name          = instanceTask.Result.Name,
                Status        = instanceTask.Result.Status,
                Deleted       = instanceTask.Result.Deleted
            };

            var events      = _eventService.GetEventsByCompetitionInstanceId(competitionInstanceId);
            var competition = _competitionService.GetCompetitionByIdAsync(competitionId);

            competition.Wait();

            var instanceDto = new CompetitionInstanceDTO
            {
                Competition         = competition.Result,
                CompetitionInstance = instance,
                Events = events
            };

            return(View(instanceDto));
        }
 public async Task <IActionResult> Create(CompetitionsInstanceViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             await _competitionService.AddInstanceAsync(model);
         }
         catch (Exception e)
         {
             return(Json(e.Message));
         }
         return(RedirectToAction("Competition", "Admin", new { @competitionId = model.CompetitionId }));
     }
     return(View(model));
 }
        public async Task <IActionResult> Create(int competitionId)
        {
            ViewBag.CompId         = competitionId;
            ViewBag.CompetitionIds = _competitionService.GetAllCompetitions();
            ViewBag.Nations        = _accountService.GetNationsListItems();
            var competition = await _competitionService.GetCompetitionByIdAsync(competitionId);

            var model = new CompetitionsInstanceViewModel
            {
                DateFrom = DateTime.Now.Date,
                DateTo   = DateTime.Now.Date,
                Name     = competition.Name + " " + DateTime.Now.Year.ToString()
            };

            return(View(model));
        }
Esempio n. 4
0
        /// <summary>
        /// Function to add an instance of a competition.
        /// </summary>
        /// <param name="model"></param>
        /// <returns>The created instance</returns>
        public async Task <CompetitionInstance> AddInstanceAsync(CompetitionsInstanceViewModel model)
        {
            var newInstance = new CompetitionInstance
            {
                CompetitionId = model.CompetitionId,
                DateFrom      = model.DateFrom,
                DateTo        = model.DateTo,
                Location      = model.Location,
                CountryId     = model.CountryId,
                Name          = model.Name,
                Status        = model.Status,
                Deleted       = false
            };

            await _repo.InsertInstanceAsync(newInstance);

            return(newInstance);
        }
Esempio n. 5
0
        public IActionResult Instance(string search, int competitionId, int instanceId)
        {
            var instanceTask = _competitionService.GetCompetitionInstanceByIdAsync(instanceId);

            instanceTask.Wait();

            var instance = new CompetitionsInstanceViewModel
            {
                Id            = instanceTask.Result.Id,
                CompetitionId = instanceTask.Result.CompetitionId,
                DateFrom      = instanceTask.Result.DateFrom,
                DateTo        = instanceTask.Result.DateTo,
                Location      = instanceTask.Result.Location,
                CountryId     = instanceTask.Result.CountryId,
                Name          = instanceTask.Result.Name,
                Status        = instanceTask.Result.Status,
                Deleted       = instanceTask.Result.Deleted
            };

            var events = _eventService.GetEventsByCompetitionInstanceId(instanceId);

            if (!String.IsNullOrEmpty(search))
            {
                var searchToUpper = search.ToUpper();
                events = events.Where(u => u.Name.ToUpper().Contains(searchToUpper));
            }

            var competition = _competitionService.GetCompetitionByIdAsync(competitionId);

            competition.Wait();

            events = events.OrderByDescending(x => x.DateFrom);

            var instanceDto = new CompetitionInstanceDTO
            {
                Competition         = competition.Result,
                CompetitionInstance = instance,
                Events = events
            };

            return(View(instanceDto));
        }
Esempio n. 6
0
        /// <summary>
        /// Function to edit an instance of a competition.
        /// </summary>
        /// <param name="compInstance"></param>
        /// <param name="model"></param>
        /// <returns>Edited instance</returns>
        public async Task <CompetitionInstance> EditInstanceAsync(CompetitionInstance compInstance, CompetitionsInstanceViewModel model)
        {
            compInstance.CountryId = model.CountryId;
            compInstance.DateFrom  = model.DateFrom;
            compInstance.DateTo    = model.DateTo;
            compInstance.Location  = model.Location;
            compInstance.Name      = model.Name;
            compInstance.Status    = model.Status;
            await _repo.EditInstanceAsync(compInstance);

            return(compInstance);
        }
        public async Task <IActionResult> Edit(int competitionId, int competitionInstanceId, CompetitionsInstanceViewModel model)
        {
            if (competitionInstanceId != model.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                var compInstance = await _competitionService.GetCompetitionInstanceByIdAsync(model.Id);

                await _competitionService.EditInstanceAsync(compInstance, model);

                return(RedirectToAction("Competition", "Admin", new { @competitionId = compInstance.CompetitionId }));
            }
            return(View(model));
        }