Пример #1
0
        public IActionResult Create([FromBody] Athlete item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (athleteRepository.GetByEmail(item.Email) != null)
                {
                    return(BadRequest("Email is already in use: " + item.Email));
                }

                item.Id     = 0;
                item.Status = AthleteStatusType.Regular;
                athleteRepository.Add(item);
                athleteRepository.SaveChanges();

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(500, new { error = e.Message }));
            }
        }
Пример #2
0
        public IActionResult Create([FromBody] CreateAthleteDto item)
        {
            try
            {
                Result <AthleteName> athleteNameRequest = AthleteName.Create(item.Name);
                Result <Email>       emailRequest       = Email.Create(item.Email);
                Result result = Result.Combine(athleteNameRequest, emailRequest);
                if (result.IsFailure)
                {
                    return(BadRequest(result.Error));
                }

                if (athleteRepository.GetByEmail(emailRequest.Value) != null)
                {
                    return(BadRequest("Email is already in use: " + item.Email));
                }

                var athlete = new Athlete(athleteNameRequest.Value, emailRequest.Value);
                athleteRepository.Add(athlete);
                athleteRepository.SaveChanges();

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(500, new { error = e.Message }));
            }
        }
Пример #3
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var isNew = _athlete.Id == 0;

            if (isNew)
            {
                _athleteRepository.Add(_athlete);
            }
            else
            {
                _athleteRepository.Edit(_athlete, _athlete.Id);
            }

            _athleteRepository.Save();

            if (isNew)
            {
                _athleteManager.Athletes.Add(_athlete);
            }
            else
            {
                var index = _athleteManager.Athletes.IndexOf(_athlete);//get its location in list
                _athleteManager.Athletes[index] = _athlete;
            }

            this.Close();
        }
Пример #4
0
        private void dgAthletes_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {
                // Athlete athlete = (Athlete)dgAthletes.SelectedItem;

                Athlete athlete = e.Row.DataContext as Athlete;
                if (athlete.Id > 0)
                {
                    _athleteRepository.Edit(athlete, athlete.Id);
                }
                else
                {
                    _athleteRepository.Add(athlete);
                }
                _athleteRepository.Save();
            }
        }
Пример #5
0
 public IActionResult Add(Athlete athlete)
 {
     _athleteRepository.Add(athlete);
     return(RedirectToAction("Index"));
 }
Пример #6
0
        private void AssignTag(Split split)
        {
            Athlete nextAthlete;

            //_athleteRepository.GetAll();

            if (Athletes.Any())
            {
                if (Athletes.Any(x => x.TagId == split.Epc && x.Bib > 0))
                {
                    var athelete = Athletes.FirstOrDefault(x => x.TagId == split.Epc);
                    Message =
                        $"Tag {split.Epc} already assigned to {athelete.Bib} {athelete.FirstName} {athelete.LastName}";
                    return;
                }


                if (AutoAssign)
                {
                    int maxBib = _athleteRepository.GetMaxBib();

                    NextBib = ++maxBib;
                }

                nextAthlete = Athletes.SingleOrDefault(x => x.Bib == NextBib && string.IsNullOrEmpty(x.TagId));
                if (nextAthlete != null)
                {
                    nextAthlete.TagId = split.Epc;
                    _athleteRepository.Edit(nextAthlete, nextAthlete.Id);
                    _athleteRepository.Save();
                }
                else
                {
                    nextAthlete = Athletes.FirstOrDefault(x => x.Bib == 0);
                    if (nextAthlete != null)
                    {
                        nextAthlete.Bib   = NextBib;
                        nextAthlete.TagId = split.Epc;
                        _athleteRepository.Edit(nextAthlete, nextAthlete.Id);
                        _athleteRepository.Save();
                        Message =
                            $"Tag {split.Epc} assigned to { nextAthlete.Bib}";
                    }
                    else if (Athletes.Any(x => x.Bib == NextBib) == false)
                    {
                        nextAthlete = new Athlete
                        {
                            Bib   = NextBib,
                            TagId = split.Epc
                        };
                        _athleteRepository.Add(nextAthlete);
                        _athleteRepository.Save();

                        Application.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            Athletes.Insert(0, nextAthlete);
                        }));
                        Message =
                            $"Tag {split.Epc} assigned to { nextAthlete.Bib}";
                    }

                    return;
                }
            }
            else
            {
                if (Athletes.Any(x => x.Bib == NextBib))
                {
                    var athelete = Athletes.FirstOrDefault(x => x.Bib == NextBib);
                    Message =
                        $"Tag {split.Epc} already assigned to {athelete.Bib} {athelete.FirstName} {athelete.LastName}";
                    return;
                }

                nextAthlete = new Athlete
                {
                    Bib   = NextBib,
                    TagId = split.Epc
                };

                Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    Athletes.Insert(0, nextAthlete);
                }));

                _athleteRepository.Add(nextAthlete);
                _athleteRepository.Save();


                Message =
                    $"Tag {split.Epc} assigned to {nextAthlete.Bib} with no athlete name";
            }

            if (AutoAssign)
            {
                NextBib++;
            }
        }