Beispiel #1
0
        public async Task <TripDTO> AddMemberToTrip(int tripId, int memberId, bool IsTeam)
        {
            using (_unitOfWork)
            {
                Trip trip = await _unitOfWork.TripRepository.GetTripWithItemsAndMembers(tripId);

                Member member;
                if (IsTeam)
                {
                    member = await _unitOfWork.TeamRepository.GetTeamWithMembers(memberId);
                }
                else
                {
                    member = await _unitOfWork.UserRepository.FindByID(memberId);
                }

                if (trip.Travelers == null)
                {
                    trip.Travelers = new List <User>();
                }

                foreach (User user in member.GetUsers())
                {
                    if (!trip.Travelers.Contains(user))
                    {
                        trip.Travelers.Add(user);
                        if (user.MyTrips == null)
                        {
                            user.MyTrips = new List <Trip>();
                        }
                        user.MyTrips.Add(trip);
                        _unitOfWork.UserRepository.Update(user);
                        Notification notification = new Notification()
                        {
                            Seen = false,
                            RelatedObjectName = trip.Name,
                            Type   = NotificationType.NewTrip,
                            User   = user,
                            UserId = user.UserId
                        };
                        await _unitOfWork.NotificationRepository.Create(notification);

                        NotificationTripDTO notificationTrip = new NotificationTripDTO()
                        {
                            Notification = _mapper.Map <Notification, NotificationDTO>(notification),
                            Trip         = _mapper.Map <Trip, TripDTO>(trip)
                        };
                        await _messageControllerService.SendNotification(user.UserId, "AddToTripNotification", notificationTrip);
                    }
                }
                _unitOfWork.TripRepository.Update(trip);
                await _unitOfWork.Save();

                await _messageControllerService.NotifyOnTripChanges(trip.TripId, "AddMemberToTrip",
                                                                    member.GetUsers().Select(user => _mapper.Map <User, UserBasicDTO>(user)));

                TripDTO retTrip = _mapper.Map <Trip, TripDTO>(trip);
                return(retTrip);
            }
        }
Beispiel #2
0
        public async Task <ItemDTO> CreateItem(ItemCreateDTO newItem)
        {
            using (_unitOfWork)
            {
                Item item = _mapper.Map <ItemCreateDTO, Item>(newItem);
                User user = await _unitOfWork.UserRepository.GetUserWithItems(newItem.UserId);

                Trip trip = await _unitOfWork.TripRepository.GetTripWithItemsAndMembers(newItem.TripId);

                if (!trip.Travelers.Contains(user))
                {
                    return(null);
                }

                item.User = user;
                item.Trip = trip;

                if (user.MyItems == null)
                {
                    user.MyItems = new List <Item>();
                }
                user.MyItems.Add(item);

                if (trip.ItemList == null)
                {
                    trip.ItemList = new List <Item>();
                }
                trip.ItemList.Add(item);

                await _unitOfWork.ItemRepository.Create(item);

                _unitOfWork.UserRepository.Update(user);
                _unitOfWork.TripRepository.Update(trip);

                Notification notification = new Notification();
                notification.Seen = false;
                notification.RelatedObjectName = item.Name;
                notification.Type   = NotificationType.AddedItem;
                notification.User   = user;
                notification.UserId = user.UserId;
                await _unitOfWork.NotificationRepository.Create(notification);

                await _unitOfWork.Save();

                ItemDTO retItem = _mapper.Map <Item, ItemDTO>(item);
                await _messageControllerService.NotifyOnTripChanges(newItem.TripId, "AddItem", retItem);

                NotificationItemDTO notificationItem = new NotificationItemDTO()
                {
                    Notification = _mapper.Map <Notification, NotificationDTO>(notification),
                    Item         = retItem
                };
                await _messageControllerService.SendNotification(newItem.UserId, "AddItemNotification", notificationItem);

                return(retItem);
            }
        }
Beispiel #3
0
        public async Task <TeamDTO> AddMemberToTeam(int teamId, int memberId, bool IsTeam)
        {
            using (_unitOfWork)
            {
                Team team = await _unitOfWork.TeamRepository.GetTeamWithMembers(teamId);

                Member member;
                if (IsTeam)
                {
                    member = await _unitOfWork.TeamRepository.GetTeamWithMembers(memberId);
                }
                else
                {
                    member = await _unitOfWork.UserRepository.FindByID(memberId);
                }

                if (team.Members == null)
                {
                    team.Members = new List <User>();
                }

                foreach (User user in member.GetUsers())
                {
                    if (!team.Members.Contains(user))
                    {
                        team.Members.Add(user);
                        if (user.MyTeams == null)
                        {
                            user.MyTeams = new List <Team>();
                        }
                        user.MyTeams.Add(team);
                        _unitOfWork.UserRepository.Update(user);
                        await _messageControllerService.SendNotification(user.UserId, "AddToTeamNotification", _mapper.Map <Team, TeamDTO>(team));
                    }
                }
                _unitOfWork.TeamRepository.Update(team);
                await _unitOfWork.Save();

                TeamDTO         retTeam   = _mapper.Map <Team, TeamDTO>(team);
                TeamUserListDTO notifyDTO = new TeamUserListDTO()
                {
                    TeamId = teamId,
                    Users  = team.Members.Select(user => _mapper.Map <User, UserBasicDTO>(user))
                };
                await _messageControllerService.NotifyOnTeamChanges(teamId, "AddMemberToTeam", notifyDTO);

                return(retTeam);
            }
        }
Beispiel #4
0
        public async Task ReleaseTripEdit(int tripId)
        {
            using (_unitOfWork)
            {
                string nextUserIdString = await _unitOfWork.EditRightsRepository.GetNextRightHolder(tripId);

                if (!string.IsNullOrEmpty(nextUserIdString))
                {
                    await _unitOfWork.EditRightsRepository.SetEditRightHolder(tripId, int.Parse(nextUserIdString));

                    await _unitOfWork.EditRightsRepository.SetEditRightsExpiration(tripId, _redisAppSettings.InitialEditRightsTTL);

                    await _messageControllerService.SendNotification(int.Parse(nextUserIdString), "EditRightsNotification", tripId);
                }
            }
        }