コード例 #1
0
        public async Task <bool> EditChipInHeatAsync(ChipInHeat c)
        {
            var result = _db.ChipsInHeats.Update(c) != null;
            await _db.SaveChangesAsync();

            return(result);
        }
コード例 #2
0
        public async Task <bool> RemoveChipInHeatAsync(ChipInHeat c)
        {
            bool result = _db.ChipsInHeats.Remove(c) != null;
            await _db.SaveChangesAsync();

            return(result);
        }
コード例 #3
0
        public bool EditChipInHeat(ChipInHeat c)
        {
            var result = _db.ChipsInHeats.Update(c) != null;

            _db.SaveChanges();
            return(result);
        }
コード例 #4
0
        public bool AssignChipToUserInHeat(ChipInHeat c)
        {
            var result = _db.ChipsInHeats.Add(c) != null;

            _db.SaveChanges();
            return(result);
        }
コード例 #5
0
        public bool RemoveChipInHeat(ChipInHeat c)
        {
            bool result = _db.ChipsInHeats.Remove(c) != null;

            _db.SaveChanges();
            return(result);
        }
コード例 #6
0
        public async Task <IActionResult> AddContestant(List <AddContestantViewModel> model, int competitionInstanceId, int competitionId, string userId)
        {
            if (ModelState.IsValid)
            {
                foreach (var item in model)
                {
                    if (item.Add)
                    {
                        var contestantInHeat = new ContestantInHeat
                        {
                            Bib      = item.Bib,
                            HeatId   = item.HeatId,
                            Modified = DateTime.Now,
                            Team     = item.Team,
                            UserId   = item.UserId
                        };
                        await _heatService.AddAsyncContestantInHeat(contestantInHeat);

                        if (item.ChipNumber > 0)
                        {
                            var chip = await _chipService.GetChipByNumberAsync(item.ChipNumber);

                            if (chip == null)
                            {
                                await _heatService.RemoveAsyncContestantInHeat(contestantInHeat);

                                return(Json("There exists no chip with the chip number " + item.ChipNumber));
                            }
                            var chipinHeat = new ChipInHeat
                            {
                                ChipCode = chip.Code,
                                HeatId   = item.HeatId,
                                UserId   = item.UserId,
                                Valid    = true
                            };
                            try
                            {
                                await _chipService.AssignChipToUserInHeatAsync(chipinHeat);
                            }
                            catch (Exception e)
                            {
                                await _heatService.RemoveAsyncContestantInHeat(contestantInHeat);

                                return(Json(e.Message));
                            }
                        }
                    }
                }

                return(RedirectToAction("Contestants", "CompetitionInstance", new { @competitionId = competitionId, @competitionInstanceId = competitionInstanceId }));
            }
            var user = await _adminService.GetUserByIdAsync(userId);

            ViewBag.UserName = user.FirstName + " " + user.MiddleName + " " + user.LastName;
            return(View(model));
        }
コード例 #7
0
        public async Task <bool> UpdateChipStory(ChipInHeat c)
        {
            Chip chip = await GetChipByCodeAsync(c.ChipCode);

            chip.LastCompetitionInstanceId = await _repo.GetInstanceIdForHeat(c.HeatId);

            chip.LastSeen   = DateTime.Now;
            chip.LastUserId = c.UserId;
            return(await _repo.EditChipAsync(chip));
        }
コード例 #8
0
ファイル: HeatController.cs プロジェクト: ludvikkemp/timataka
        public async Task <IActionResult> AddContestant(AddContestantToHeatViewModel model, int heatId, int eventId, int competitionId, int competitionInstanceId, string userId)
        {
            if (!ModelState.IsValid)
            {
                var user = await _adminService.GetUserByIdAsync(userId);

                ViewBag.UserName = user.FirstName + " " + user.LastName;
                var heat = await _heatService.GetHeatByIdAsync(heatId);

                ViewBag.HeatId = heat.HeatNumber;
                return(View(model));
            }

            var entity = new ContestantInHeat
            {
                Bib      = model.Bib,
                HeatId   = heatId,
                Modified = DateTime.Now,
                Team     = model.Team,
                UserId   = model.UserId
            };
            await _heatService.AddAsyncContestantInHeat(entity);

            if (model.ChipNumber > 0)
            {
                var chip = await _chipService.GetChipByNumberAsync(model.ChipNumber);

                if (chip == null)
                {
                    await _heatService.RemoveAsyncContestantInHeat(entity);

                    return(Json("There exists no chip with the chip number " + model.ChipNumber));
                }
                var chipinHeat = new ChipInHeat
                {
                    ChipCode = chip.Code,
                    HeatId   = heatId,
                    UserId   = model.UserId,
                    Valid    = true
                };
                try
                {
                    await _chipService.AssignChipToUserInHeatAsync(chipinHeat);
                }
                catch (Exception e)
                {
                    await _heatService.RemoveAsyncContestantInHeat(entity);

                    return(Json(e.Message));
                }
            }
            return(RedirectToAction("Heat", "Admin", new { heatId, eventId, competitionId, competitionInstanceId }));
        }
コード例 #9
0
        public async Task <bool> AssignChipToUserInHeatAsync(ChipInHeat c)
        {
            var exists = (from cih in _db.ChipsInHeats
                          where cih.ChipCode == c.ChipCode && cih.HeatId == c.HeatId
                          select cih).SingleOrDefault();

            if (exists != null)
            {
                throw new Exception("Chip already assigned to a contestant in this heat.");
            }
            await _db.ChipsInHeats.AddAsync(c);

            await _db.SaveChangesAsync();

            return(true);
        }
コード例 #10
0
        public bool AssignChipToUserInHeat(ChipInHeat c)
        {
            var result = true;

            try
            {
                result = _repo.AssignChipToUserInHeat(c);
            }
            catch (Exception e)
            {
                var heat      = _heatService.GetHeatByIdAsync(c.HeatId).Result;
                var thisEvent = _eventService.GetEventById(heat.EventId);
                throw new Exception("Failed to assign chip in heat" + heat.HeatNumber + " in " + thisEvent.Name + ". Please use another chip." + "\r\n" + e.Message);
            }
            UpdateChipStory(c).Wait();
            return(result);
        }
コード例 #11
0
        public async Task <ChipInHeatViewModel> AssignChipToUserInHeatAsync(ChipInHeat c)
        {
            try
            {
                await _repo.AssignChipToUserInHeatAsync(c);
            }
            catch (Exception e)
            {
                var heat = await _heatService.GetHeatByIdAsync(c.HeatId);

                var thisEvent = _eventService.GetEventById(heat.EventId);
                throw new Exception("Failed to assign chip " + c.ChipCode + " in heat " + heat.HeatNumber + " in " + thisEvent.Name + ". Please use another chip." + " " + e.Message);
            }
            await UpdateChipStory(c);

            var result = GetChipInHeatByCodeAndUserId(c.ChipCode, c.UserId, c.HeatId);

            return(result);
        }
コード例 #12
0
 public Boolean EditChipInHeat(ChipInHeat c)
 {
     return(_repo.EditChipInHeat(c));
 }
コード例 #13
0
 public async Task <bool> MarkInvalid(ChipInHeat c)
 {
     c.Valid = false;
     return(await _repo.EditChipInHeatAsync(c));
 }
コード例 #14
0
 public async Task <bool> RemoveChipInHeatAsync(ChipInHeat c)
 {
     return(await _repo.RemoveChipInHeatAsync(c));
 }
コード例 #15
0
 public Boolean RemoveChipInHeat(ChipInHeat c)
 {
     return(_repo.RemoveChipInHeat(c));
 }
コード例 #16
0
        public async Task <IActionResult> EditContestantInEvent(EditContestantInEventDto model, string userId, int competitionInstanceId, int competitionId, int eventId)
        {
            if (ModelState.IsValid)
            {
                // Get The Chip Contestants in About To Be Connected To
                var chip = await _chipService.GetChipByNumberAsync(model.ChipNumber);

                if (chip == null && model.ChipNumber != 0)
                {
                    return(Json("Chip with this Number does not exist"));
                }

                // Get oldChipInHeat To Remove
                var oldChipInHeat = await _chipService.GetChipInHeatByCodeUserIdAndHeatId(model.OldChipCode, userId, model.OldHeatId);

                if (oldChipInHeat != null)
                {
                    var chipSuccess = await _chipService.RemoveChipInHeatAsync(oldChipInHeat);

                    if (!chipSuccess)
                    {
                        return(Json("chipInHeatToRemove not successfully removed"));
                    }
                }

                if (model.ChipNumber != 0)
                {
                    // Edit Fields in Contestants New Chip
                    chip.LastCompetitionInstanceId = competitionInstanceId;
                    chip.LastUserId = userId;
                    chip.LastSeen   = DateTime.Now;
                    var chipEdit = await _chipService.EditChipAsync(chip);

                    if (chipEdit != true)
                    {
                        return(Json("Edit Chip Failed"));
                    }

                    // Create New ChipInHeat
                    var newChipInHeat = new ChipInHeat
                    {
                        UserId   = userId,
                        ChipCode = chip.Code,
                        HeatId   = model.HeatId,
                        Valid    = true
                    };

                    // Assigning New ChipInHeat To User
                    try
                    {
                        await _chipService.AssignChipToUserInHeatAsync(newChipInHeat);
                    }
                    catch (Exception e)
                    {
                        return(Json(e.Message));
                    }
                }

                // Get ContestantInHeat To Remove
                var contestantInHeat = await _heatService.GetContestantsInHeatByUserIdAndHeatIdAsync(userId, model.OldHeatId);

                if (contestantInHeat == null)
                {
                    return(Json("contestantInHeat does not match this userId and heatId"));
                }

                // Get Old Results to keep track of data before it is deleted
                var oldResult = await _resultService.GetResultAsync(userId, model.OldHeatId);

                if (oldResult == null)
                {
                    return(Json("Result does not match this userId and heatId"));
                }

                // Removes ContestantInHeat and Result
                await _heatService.RemoveAsyncContestantInHeat(contestantInHeat);

                // Create New ContestantIn Heat To Replace The Old One
                // New Result Will Be Created Automatically
                var newContestantInHeat = new ContestantInHeat
                {
                    HeatId   = model.HeatId,
                    UserId   = userId,
                    Bib      = model.Bib,
                    Team     = model.Team,
                    Modified = DateTime.Now
                };

                // Save newContestantInHeat In Database
                await _heatService.AddAsyncContestantInHeat(newContestantInHeat);

                // Get The New Result To Update Its Data
                var newResult = await _resultService.GetResultAsync(userId, newContestantInHeat.HeatId);

                if (newResult == null)
                {
                    return(Json("newResult was not created which means newContestantInHeat was not created"));
                }

                // Edit Field That Came From The Model
                newResult.Modified = DateTime.Now;
                newResult.HeatId   = model.HeatId;
                newResult.Status   = model.Status;
                newResult.Notes    = model.Notes;
                newResult.UserId   = userId;

                // Edit Fields That Came From The Old Result
                newResult.Name        = oldResult.Name;
                newResult.Club        = oldResult.Club;
                newResult.Country     = oldResult.Country;
                newResult.Created     = oldResult.Created;
                newResult.Gender      = oldResult.Gender;
                newResult.FinalTime   = oldResult.FinalTime;
                newResult.Nationality = oldResult.Nationality;

                // Save newResult In Database
                await _resultService.EditAsync(newResult);

                return(RedirectToAction("Contestants", "CompetitionInstance", new { competitionId, competitionInstanceId }));
            }
            return(View(model));
        }