Esempio n. 1
0
        public async Task <ActionResult> Post([FromBody] TrainingAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var coach = await _coachRepository.GetAsync(model.CoachId);

            if (coach == null)
            {
                return(BadRequest($"No coach was found with Id:{model.CoachId}"));
            }

            var hall = await _hallRepository.GetAsync(model.HallId);

            if (hall == null)
            {
                return(BadRequest($"No hall was found with Id:{model.HallId}"));
            }

            var dateFrom = model.StartTime.AddHours(-1);
            var dateTo   = model.StartTime.AddHours(1);

            var conflictingTraining = _repository
                                      .GetForRange(dateFrom, dateTo)
                                      .Where(t => t.CoachId == model.CoachId ||
                                             t.HallId == model.HallId);

            if (conflictingTraining.Any())
            {
                return(BadRequest($"Cannot add training for this time" +
                                  $" (Coach or hall busy for this time)"));
            }

            var entity = new Training()
            {
                Title        = model.Title,
                TrainingType = model.TrainingType,
                CoachId      = model.CoachId,
                HallId       = model.HallId,
                StartTime    = model.StartTime
            };

            // try
            //  {
            _repository.Create(entity);
            await _repository.SaveChangesAsync();

            //   }
            //    catch (Exception e)
            //   {
            //       return BadRequest();
            //    }

            return(Created(string.Empty, entity));
        }
Esempio n. 2
0
        public async Task <List <Comment> > GetCoachCommentsAsync(int coachId, CancellationToken ct = default)
        {
            var coach = await _coachRepository.GetAsync(coachId, ct);

            return(coach.Comments);
        }
Esempio n. 3
0
        public async Task <List <GameProfile> > GetAllAsync(int coachId, CancellationToken ct = default)
        {
            var coach = await _coachRepository.GetAsync(coachId, ct);

            return(coach.GameProfiles);
        }
 public async Task <ActionResult <IEnumerable <Coach> > > Get()
 {
     return(Ok(await _repository.GetAsync()));
 }
Esempio n. 5
0
 public Task <Coach> GetAsync(int id, CancellationToken ct = default)
 {
     return(_coachRepository.GetAsync(id, ct));
 }