public async Task AddTrainingPlace(TrainingPlaceDTO dto) { var trainingPlace = new DAL.App.DTO.TrainingPlace() { Name = dto.Name, Address = dto.Address, OpeningTime = dto.OpeningTime, ClosingTime = dto.ClosingTime }; ServiceRepository.Add(trainingPlace); await ServiceUnitOfWork.SaveChangesAsync(); }
public async Task <List <TrainingPlaceDTO> > GetAllTrainingPlaces() { var trainingPlaces = await ServiceRepository.AllAsync(); var mappedData = new List <TrainingPlaceDTO>(); foreach (var place in trainingPlaces) { var trainingPlaceDto = new TrainingPlaceDTO() { Id = place.Id, Name = place.Name, Address = place.Address, OpeningTime = place.OpeningTime, ClosingTime = place.ClosingTime }; mappedData.Add(trainingPlaceDto); } return(mappedData); }
public async Task <TrainingDTO> MapTrainingData(Guid Id) { var training = await ServiceRepository.FirstOrDefaultAsync(Id); var creator = await ServiceUnitOfWork.AccountRepository.FirstOrDefaultAsync(training.CreatorId); var usersInThisTraining = await ServiceUnitOfWork.UsersInTrainingRepository.FindByTrainingId(Id); var usersAttending = new List <UserDTO>(); var usersInvited = new List <UserInTrainingDTO>(); foreach (var user in usersInThisTraining) { if (user.AttendingTraining == false) { var appUser = await ServiceUnitOfWork.AccountRepository.FirstOrDefaultAsync(user.AppUserId); var notification = await ServiceUnitOfWork.NotificationRepository.FindByTrainingAndUserId(user.AppUserId, training.Id); if (notification.Recived) { var notificationAnswer = await ServiceUnitOfWork.NotificationAnswerRepository.findbyNotificationId(notification.Id); var usrDTO = new UserInTrainingDTO() { Id = appUser.Id, email = appUser.Email, phoneNumber = appUser.PhoneNumber, userName = appUser.FirstName + " " + appUser.LastName, positions = await MapPlayerPositionDtos(appUser), recived = notification.Recived, answer = new NotificationAnswerDTO() { Coming = notificationAnswer.Attending, Content = notificationAnswer.Content } }; usersInvited.Add(usrDTO); } else { var userDTO = new UserInTrainingDTO() { Id = appUser.Id, email = appUser.Email, phoneNumber = appUser.PhoneNumber, userName = appUser.FirstName + " " + appUser.LastName, positions = await MapPlayerPositionDtos(appUser), recived = notification.Recived, answer = null }; usersInvited.Add(userDTO); } } if (user.AttendingTraining) { var appUser = await ServiceUnitOfWork.AccountRepository.FirstOrDefaultAsync(user.AppUserId); var usrDTO = new UserDTO { Id = appUser.Id, email = appUser.Email, phoneNumber = appUser.PhoneNumber, userName = appUser.FirstName + " " + appUser.LastName, positions = await MapPlayerPositionDtos(appUser) }; usersAttending.Add(usrDTO); } } var trainingPlace = await ServiceUnitOfWork.TrainingPlaceRepository.FirstOrDefaultAsync(training.TrainingPlaceId); var trainingPlaceDto = new TrainingPlaceDTO { Id = trainingPlace.Id, Address = trainingPlace.Address, Name = trainingPlace.Name, ClosingTime = trainingPlace.ClosingTime, OpeningTime = trainingPlace.OpeningTime }; if (usersAttending.Count >= 16) { training.TrainingStatus = ConfirmedTrainingStatus; } await ServiceUnitOfWork.SaveChangesAsync(); var trainingDto = new TrainingDTO { Id = training.Id, TrainingPlace = trainingPlaceDto, TrainingDate = training.Start, Description = training.Description, Duration = training.Duration, TrainingStatus = training.TrainingStatus, PeopleInvited = usersInvited, PeopleAttending = usersAttending, StartTime = training.StartTime, CreatedBy = new UserDTO() { Id = creator.Id, userName = creator.FirstName + " " + creator.LastName, email = creator.Email, phoneNumber = creator.PhoneNumber }, Comments = await CommentService.GetTrainingComments(training.Id) }; return(trainingDto); }
public async Task <OkObjectResult> Edit(TrainingPlaceDTO dto) { await _bll.TrainingPlaceService.AddTrainingPlace(dto); return(Ok("Training place added")); }