コード例 #1
0
 public UserModel GetUser(int userId)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return(unitOfWork.Users.Find(user => user.Id == userId));
     }
 }
コード例 #2
0
ファイル: AlbumService.cs プロジェクト: Maaak/academy13
 public IEnumerable <AlbumModel> GetAvailableAlbums(int userId)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return(GetAvailableAlbums(userId, unitOfWork));
     }
 }
コード例 #3
0
 public UserModel GetUser(string userEmail)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return(GetUser(userEmail, unitOfWork));
     }
 }
コード例 #4
0
ファイル: PhotoSearchService.cs プロジェクト: Maaak/academy13
        public IEnumerable <IFound> Search(SearchArguments searchArguments)
        {
            var result = new List <PhotoFound>();

            IEnumerable <string> searchWords = searchArguments.SearchQuery.SplitSearchString();

            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                IEnumerable <AlbumModel> avialableAlbums = _secureService.GetAvailableAlbums(searchArguments.UserId,
                                                                                             unitOfWork);

                if (searchArguments.IsSearchPhotosByDescription)
                {
                    IEnumerable <PhotoFound> found = SearchByDescription(avialableAlbums, searchWords);

                    result.AddRange(found);
                }

                if (searchArguments.IsSearchPhotosByTags)
                {
                    IEnumerable <PhotoFound> found = SearchByTags(avialableAlbums, searchWords);

                    result.AddRange(found);
                }
            }

            return(Group(result));
        }
コード例 #5
0
ファイル: UserSearchService.cs プロジェクト: Maaak/academy13
        public IEnumerable <IFound> Search(SearchArguments searchArguments)
        {
            var result = new List <UserFound>();

            IEnumerable <string> searchWords = searchArguments.SearchQuery.SplitSearchString();

            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                if (searchArguments.IsSearchUsersByName)
                {
                    IEnumerable <UserFound> found = SearchByCondition(searchWords,
                                                                      model =>
                                                                      searchWords.Any(
                                                                          searchWord =>
                                                                          model.FirstName.Contains(searchWord) || model.LastName.Contains(searchWord)),
                                                                      GetRelevanceByName, unitOfWork);

                    result.AddRange(found);
                }

                if (searchArguments.IsSearchUserByDepartment)
                {
                    IEnumerable <UserFound> found = SearchByCondition(searchWords,
                                                                      model => searchWords.Any(searchWord => model.Department.Contains(searchWord)),
                                                                      GetRelevanceByDepartment,
                                                                      unitOfWork);

                    result.AddRange(found);
                }
            }

            return(Group(result));
        }
コード例 #6
0
 public IEnumerable <UserModel> GetUnactivatedUsers()
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return(unitOfWork.Users.Filter(user => !user.IsActivated));
     }
 }
コード例 #7
0
 public PhotoCommentModel GetPhotoComment(int commentId)
 {
     using (var unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return unitOfWork.PhotoComments.Find(commentId);
     }
 }
コード例 #8
0
        public string CreateUser(string userEmail, string userFirstName, string userLastName)
        {
            if (IsUserExist(userEmail))
            {
                throw new UserAlreadyExistException(userEmail);
            }

            var userModel = new UserModel
            {
                Email       = userEmail,
                FirstName   = userFirstName,
                LastName    = userLastName,
                IsAdmin     = false,
                IsActivated = false,
                // Here is our HASH for activating link
                Salt = Randomizer.GetString(16),
                // Empty password field is not good
                UserPassword =
                    _cryptoProvider.CreateHashForPassword(Randomizer.GetString(16), _cryptoProvider.GetNewSalt())
            };

            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                unitOfWork.Users.Add(userModel);
                unitOfWork.SaveChanges();

                int userId = unitOfWork.Users.Find(user => user.Email == userEmail).Id;
                _albumService.CreateSystemAlbums(userId);
            }

            return(userModel.Salt);
        }
コード例 #9
0
 public int GetUserId(string userEmail)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return(unitOfWork.Users.Find(user => user.Email == userEmail).Id);
     }
 }
コード例 #10
0
        //todo: add check permission for deleting group event
        public void Delete(int ownerId, int groupId)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                try
                {
                    GroupModel group = GetGroup(groupId);
                    UserModel  owner = GetUser(ownerId, unitOfWork);

                    if (IsGroupSystem(group))
                    {
                        throw new GroupAlreadyExistException(group.GroupName);
                    }

                    if (group.OwnerId == ownerId || owner.IsAdmin)
                    {
                        unitOfWork.Groups.Delete(group);
                        unitOfWork.SaveChanges();
                    }
                }
                catch (Exception exception)
                {
                    throw new Exception(exception.Message, exception);
                }
            }
        }
コード例 #11
0
ファイル: AlbumService.cs プロジェクト: Maaak/academy13
 public AlbumModel GetAlbum(int albumId)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return(GetAlbum(albumId, unitOfWork));
     }
 }
コード例 #12
0
        public void ActivateUser(string userEmail, string userPassword, string invite)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                UserModel userModel = GetUser(userEmail, unitOfWork);

                if (userModel.IsActivated)
                {
                    throw new UserAlreadyExistException(string.Format("User {0} already activated", userEmail));
                }

                if (userModel.Salt != invite)
                {
                    throw new UserNotFoundException(string.Format("User with email {0} not found in activation list",
                                                                  userEmail));
                }

                userModel.Salt = _cryptoProvider.GetNewSalt();

                userModel.UserPassword = _cryptoProvider.CreateHashForPassword(userPassword, userModel.Salt);
                userModel.IsActivated  = true;


                unitOfWork.Users.Update(userModel);
                unitOfWork.SaveChanges();
            }
        }
コード例 #13
0
ファイル: AlbumService.cs プロジェクト: Maaak/academy13
 public int AlbumsCount(int userId)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return(unitOfWork.Albums.Filter(model => model.OwnerId == userId && !model.IsDeleted).Sum(model => 1));
     }
 }
コード例 #14
0
ファイル: AlbumService.cs プロジェクト: Maaak/academy13
 public IEnumerable <AlbumTagModel> GetTags(int albumId)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return(unitOfWork.AlbumTags.Filter(tag => tag.Id == albumId).ToList());
     }
 }
コード例 #15
0
        /// <summary>
        ///     Checks if user take a part in even one group, that have enough permissions to do some action
        /// </summary>
        private bool CanUserDoAction(int userId, int albumId, Predicate <AvailableGroupModel> predicate)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                bool canUser;

                UserModel  user  = GetUser(userId, unitOfWork);
                AlbumModel album = GetAlbum(albumId, unitOfWork);


                if (user.IsAdmin || (album.OwnerId == userId))
                {
                    canUser = true;
                }
                else
                {
                    List <AvailableGroupModel> availableGropusCanDo =
                        unitOfWork.Albums.Find(albumId).AvailableGroups.ToList().FindAll(predicate);


                    GroupModel userGroups = unitOfWork.Users.Find(userId).Groups.ToList()
                                            .Find(
                        group =>
                        availableGropusCanDo.Find(x => x.GroupId == @group.Id) != null);

                    canUser = userGroups != null;
                }

                return(canUser);
            }
        }
コード例 #16
0
 public void Update(UserModel userModel)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         unitOfWork.Users.Update(userModel);
         unitOfWork.SaveChanges();
     }
 }
コード例 #17
0
 //todo Shall refactor and delete. Soon ..)
 public PhotoModel GetPhotoWithoutRightsCheck(int photoId)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         PhotoModel photoModel = unitOfWork.Photos.Find(photoId);
         return(photoModel);
     }
 }
コード例 #18
0
        public bool IsUserExist(int userId)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                IUserRepository userRepository = unitOfWork.Users;

                return(userRepository.Contains(model => model.Id == userId && model.IsActivated));
            }
        }
コード例 #19
0
        public bool IsUserExist(string userEmail)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                IUserRepository userRepository = unitOfWork.Users;

                return(userRepository.Contains(model => model.Email == userEmail && model.IsActivated));
            }
        }
コード例 #20
0
ファイル: AlbumService.cs プロジェクト: Maaak/academy13
        public IEnumerable <AlbumModel> GetAllAlbums(int userId)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                UserModel user = GetUser(userId, unitOfWork);

                return(user.Albums.Where(model => !model.IsDeleted).ToList());
            }
        }
コード例 #21
0
        public IEnumerable <AlbumTagModel> GetAlbumTags(int albumId)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                AlbumModel album = GetAlbum(albumId, unitOfWork);

                return(album.Tags.ToList());
            }
        }
コード例 #22
0
        public PhotoModel UpdatePhoto(PhotoModel photoModel)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                unitOfWork.Photos.Update(photoModel);

                unitOfWork.SaveChanges();

                return(photoModel);
            }
        }
コード例 #23
0
 public IEnumerable <PhotoModel> GetLastPhotos(int userId, int skipCount, int takeCount)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return(unitOfWork.Photos.Filter(model => model.OwnerId == userId)
                .OrderByDescending(model => model.DateOfCreation)
                .Skip(skipCount)
                .Take(takeCount)
                .ToList());
     }
 }
コード例 #24
0
        public void SetAlbumTags(int albumId, ICollection <AlbumTagModel> tags)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                AlbumModel album = GetAlbum(albumId, unitOfWork);

                album.Tags = tags;

                unitOfWork.Albums.Update(album);
                unitOfWork.SaveChanges();
            }
        }
コード例 #25
0
        public void AddLike(int userId, int photoId)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                UserModel user = GetUser(userId, unitOfWork);

                unitOfWork.Photos.Find(photoId).Likes.Add(user);
                unitOfWork.SaveChanges();

                _eventsAggregator.PushLikeToPhotoAddedEvent(user, photoId);
            }
        }
コード例 #26
0
        public bool CanUserDeletePhoto(int userId, int photoId)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                UserModel  user  = unitOfWork.Users.Find(userId);
                PhotoModel photo = unitOfWork.Photos.Find(photoId);
                AlbumModel album = unitOfWork.Albums.Find(photo.AlbumId);

                // if user is album owner OR user is photo owner OR user is admin
                return((album.OwnerId == userId) || (photo.OwnerId == userId) || (user.IsAdmin));
            }
        }
コード例 #27
0
ファイル: AlbumService.cs プロジェクト: Maaak/academy13
 public IEnumerable <AlbumModel> GetAlbumsRange(int userId, int skipCount, int takeCount)
 {
     using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
     {
         return
             (unitOfWork.Albums.Filter(model => model.OwnerId == userId && !model.IsDeleted)
              .OrderByDescending(model => model.DateOfCreation)
              .Skip(skipCount)
              .Take(takeCount)
              .ToList());
     }
 }
コード例 #28
0
        public IEnumerable <IFound> Search(SearchArguments searchArguments)
        {
            IEnumerable <string> searchWords = searchArguments.SearchQuery.SplitSearchString();

            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                IEnumerable <AlbumModel> avialableAlbums = secureService.GetAvailableAlbums(searchArguments.UserId,
                                                                                            unitOfWork);

                return(Group(SearchByText(avialableAlbums, searchWords)));
            }
        }
コード例 #29
0
        public void LetGroupViewComments(int userId, int groupId, int albumId, bool let)
        {
            //todo: add try-catch
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                AvailableGroupModel availableGroup = GetAvailableGroup(userId, groupId, albumId, unitOfWork);

                availableGroup.CanSeeComments = let;

                unitOfWork.AvailableGroups.Update(availableGroup);
                unitOfWork.SaveChanges();
            }
        }
コード例 #30
0
        /// <summary>
        ///     Checks if there is a user with given token
        /// </summary>
        /// <param name="authProvider">[facebook][google]</param>
        /// <param name="token">Token for authorization</param>
        public bool IsUserExist(string authProvider, string token)
        {
            using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork())
            {
                IAuthInfoRepository authInfoRepository = unitOfWork.AuthInfos;

                return
                    (authInfoRepository.Contains(
                         model =>
                         string.Equals(model.AuthProvider, authProvider) &&
                         string.Equals(model.AuthProviderToken, token)));
            }
        }