public async Task AddNewTraining(NewTrainingDTO newTrainingDto)
        {
            var training = new DAL.App.DTO.Training()
            {
                Description     = newTrainingDto.Description,
                Duration        = newTrainingDto.Duration,
                TrainingPlaceId = newTrainingDto.TrainingPlaceId,
                Start           = DateTime.Parse(newTrainingDto.Start),
                StartTime       = TimeSpan.Parse(newTrainingDto.StartTime),
                TrainingStatus  = CreatedTrainingStatus,
                CreatorId       = newTrainingDto.CreatedBy.Id
            };

            var trainingwithId = ServiceRepository.AddNew(training);
            await ServiceUnitOfWork.SaveChangesAsync();

            var users = newTrainingDto.PeopleInvited;

            foreach (var user in users)
            {
                var usrInTraining = new DAL.App.DTO.UserInTraining()
                {
                    AppUserId         = user.Id,
                    TrainingId        = trainingwithId.Id,
                    AttendingTraining = false
                };
                ServiceUnitOfWork.UsersInTrainingRepository.AddNewUserInTraining(usrInTraining);
            }
            await ServiceUnitOfWork.SaveChangesAsync();

            await NotificationService.SendOutNewTrainingNotifications(users, newTrainingDto.NotificationContent,
                                                                      trainingwithId);
        }
Пример #2
0
        public IActionResult Post([FromBody] ServicePost service)
        {
            if (service == null)
            {
                return(new BadRequestObjectResult(service));
            }

            int insertedId = serviceRepository.AddNew(service);

            if (insertedId >= 0)
            {
                return(new OkObjectResult(insertedId));
            }
            else
            {
                return(new BadRequestResult());
            }
        }