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);
        }
        public async Task CreatInvoice(NewBillDTO dto)
        {
            var user = await ServiceUnitOfWork.AccountRepository.FindAsync(dto.UserBill.Id);

            var trainings = new List <DAL.App.DTO.Training>();
            var bill      = new Bill()
            {
                AppUserId = dto.UserBill.Id,
                Deadline  = dto.Deadline,
                Total     = dto.Total,
            };

            bill = ServiceRepository.AddNewBill(bill);
            await ServiceUnitOfWork.SaveChangesAsync();

            foreach (var trainingdto in dto.Trainings)
            {
                var trainingInBill = new TrainingInBill()
                {
                    BillId     = bill.Id,
                    TrainingId = trainingdto.Id
                };
                await ServiceUnitOfWork.TrainingInBillRepository.AddNewTrainingInBill(trainingInBill);

                var training = await ServiceUnitOfWork.TrainingRepository.FindAsync(trainingdto.Id);

                trainings.Add(training);
            }


            await ServiceUnitOfWork.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task AnswerNotification(NotificationAnswerDTO notificationAnswerDto)
        {
            var notificationAnswer = new DAL.App.DTO.NotificationAnswer
            {
                Attending      = notificationAnswerDto.Coming,
                Content        = notificationAnswerDto.Content,
                NotificationId = Guid.Parse(notificationAnswerDto.NotificationId),
            };
            await ServiceRepository.AddNewAnswer(notificationAnswer);

            await ServiceUnitOfWork.SaveChangesAsync();

            var notification = await ServiceUnitOfWork.NotificationRepository.FirstOrDefaultAsync(Guid.Parse(notificationAnswerDto.NotificationId));

            await ServiceUnitOfWork.NotificationRepository.UpdateNotification(notification);

            await ServiceUnitOfWork.SaveChangesAsync();

            var userInTraining =
                await ServiceUnitOfWork.UsersInTrainingRepository.FindByAppUserIdAndTrainingId(Guid.Parse(notificationAnswerDto.AppUserId),
                                                                                               Guid.Parse(notificationAnswerDto.TrainingId));

            if (notificationAnswerDto.Coming)
            {
                userInTraining.AttendingTraining = true;
                ServiceUnitOfWork.UsersInTrainingRepository.UpdateUserInTraining(userInTraining);
            }
            await ServiceUnitOfWork.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task RemovePlayerFromTeam(UserDTO dto)
        {
            var appUserToRemove = await ServiceRepository.FirstOrDefaultAsync(dto.Id);

            appUserToRemove.Team   = null;
            appUserToRemove.TeamId = null;
            ServiceRepository.Update(appUserToRemove);
            await ServiceUnitOfWork.SaveChangesAsync();
        }
        public async Task AddTeam(NewTeamDTO dto)
        {
            var team = new DAL.App.DTO.Team();

            team.Description = dto.Description;
            team.Name        = dto.Name;
            ServiceRepository.Add(team);
            await ServiceUnitOfWork.SaveChangesAsync();
        }
        public async Task AddPosition(string position, Guid userId)
        {
            var playerPostion = new DAL.App.DTO.PlayerPosition()
            {
                AppUserId      = userId,
                PersonPosition = position
            };

            ServiceRepository.Add(playerPostion);
            await ServiceUnitOfWork.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public async Task AddNewComment(CommentDTO dto)
        {
            var dal = new DAL.App.DTO.Comment()
            {
                AppUserId  = dto.UserId,
                TrainingId = dto.TrainingId,
                Content    = dto.Content,
            };

            ServiceRepository.Add(dal);
            await ServiceUnitOfWork.SaveChangesAsync();
        }
        public async Task SaveUserFeedBack(NewFeedBackDTO feedbackDto)
        {
            var feedbackDalDto = new Feedback()
            {
                AppUserId = feedbackDto.AppUserId,
                Content   = feedbackDto.Feedback,
                Rating    = feedbackDto.Rating
            };
            await ServiceRepository.AddNewFeedback(feedbackDalDto);

            await ServiceUnitOfWork.SaveChangesAsync();
        }
        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 SendOutCustomNotification(NewNotificationDTO dto)
        {
            foreach (var user in dto.Players)
            {
                var notification = new DAL.App.DTO.Notification
                {
                    Title            = dto.Title,
                    Content          = dto.Content,
                    AppUserId        = user.Id,
                    NotificationType = "View",
                    TrainingId       = null
                };
                notification = ServiceRepository.AddNewNotification(notification);
                sendOutNotification(notification, user);
            }

            await ServiceUnitOfWork.SaveChangesAsync();
        }
        public async Task SendOutNewTrainingNotifications(ICollection <UserDTO> users, string content, Training training)
        {
            foreach (var user in users)
            {
                var notification = new Notification
                {
                    Title            = "New training invitation",
                    Content          = "You have been invited to training",
                    AppUserId        = user.Id,
                    Recived          = false,
                    NotificationType = "Training Invitation",
                    TrainingId       = training.Id
                };
                sendOutNotification(notification, user);
                ServiceRepository.AddNewNotification(notification);
            }

            await ServiceUnitOfWork.SaveChangesAsync();
        }
Exemplo n.º 12
0
        public async Task ChangeAnswer(NotificationAnswerDTO notificationAnswerDto)
        {
            var previousAnswer = await ServiceRepository.FirstOrDefaultAsync(notificationAnswerDto.id);


            previousAnswer.Attending = notificationAnswerDto.Coming;
            previousAnswer.Content   = notificationAnswerDto.Content;
            var userInTraining =
                await ServiceUnitOfWork.UsersInTrainingRepository.FindByAppUserIdAndTrainingId(
                    Guid.Parse(notificationAnswerDto.AppUserId),
                    Guid.Parse(notificationAnswerDto.TrainingId));

            if (notificationAnswerDto.Coming)
            {
                userInTraining.AttendingTraining = true;
            }
            ServiceRepository.Add(previousAnswer);
            await ServiceUnitOfWork.SaveChangesAsync();
        }
Exemplo n.º 13
0
        public async Task <UserDTO> Register(RegisterDTO model)
        {
            var user   = CreateAppUserFromModel(model);
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                AddPositionsToPlayer(model, user.Id);
                await AddAppRoleToUser(model, user);

                var jwt = await CreateJwtTokenForUser(user);

                var userDto = await MapToAppUserToUserDto(model, user, jwt);

                await ServiceUnitOfWork.SaveChangesAsync();

                return(userDto);
            }

            return(null);
        }
        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 RemoveTrainingPlace(Guid id)
 {
     ServiceRepository.Remove(id);
     await ServiceUnitOfWork.SaveChangesAsync();
 }
 public void RemoveNotification(Guid id)
 {
     ServiceRepository.Remove(id);
     ServiceUnitOfWork.SaveChangesAsync();
 }
 public async Task DeleteFeedBack(Guid id)
 {
     ServiceRepository.Remove(id);
     await ServiceUnitOfWork.SaveChangesAsync();
 }
Exemplo n.º 18
0
 public async Task RemoveNotificationAnswer(Guid id)
 {
     ServiceRepository.Remove(id);
     await ServiceUnitOfWork.SaveChangesAsync();
 }
Exemplo n.º 19
0
 public async void RemoveComment(Guid id)
 {
     ServiceRepository.Remove(id);
     await ServiceUnitOfWork.SaveChangesAsync();
 }
Exemplo n.º 20
0
 public async Task RemoveBill(Guid Id)
 {
     ServiceRepository.Remove(Id);
     await ServiceUnitOfWork.SaveChangesAsync();
 }
Exemplo n.º 21
0
 public void RemoveTeam(Guid id)
 {
     ServiceRepository.Remove(id);
     ServiceUnitOfWork.SaveChangesAsync();
 }