Пример #1
0
        public async Task <IActionResult> AddSportEvent([FromBody] SportEvent sportEvent)
        {
            if (!TryValidateModel(sportEvent))
            {
                return(BadRequest(ModelState));
            }

            SportEvent sportEventToAdd = sportEvent;
            var        authId          = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
            User       loggedInUser    = await _sportEventRepository.GetUserFromAuthId(authId);

            sportEventToAdd.Admins = new List <SportEventAdmins>();
            sportEventToAdd.Admins.Add(new SportEventAdmins {
                User = loggedInUser
            });
            sportEventToAdd.Participants = new List <SportEventParticipants>();
            sportEventToAdd.Participants.Add(new SportEventParticipants {
                User = loggedInUser
            });


            _sportEventRepository.AddSportEvent(sportEventToAdd);

            return(Created(Request.Path, sportEvent));
        }
Пример #2
0
        public bool AddSportEvent(SportEvent sportEvent)
        {
            if (sportEvent.SportEventId != 0)
            {
                return(false);
            }

            _repository.AddSportEvent(sportEvent);
            return(true);
        }