public UserModel GetUser(int userId) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { return(unitOfWork.Users.Find(user => user.Id == userId)); } }
public IEnumerable <AlbumModel> GetAvailableAlbums(int userId) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { return(GetAvailableAlbums(userId, unitOfWork)); } }
public UserModel GetUser(string userEmail) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { return(GetUser(userEmail, unitOfWork)); } }
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)); }
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)); }
public IEnumerable <UserModel> GetUnactivatedUsers() { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { return(unitOfWork.Users.Filter(user => !user.IsActivated)); } }
public PhotoCommentModel GetPhotoComment(int commentId) { using (var unitOfWork = WorkFactory.GetUnitOfWork()) { return unitOfWork.PhotoComments.Find(commentId); } }
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); }
public int GetUserId(string userEmail) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { return(unitOfWork.Users.Find(user => user.Email == userEmail).Id); } }
//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); } } }
public AlbumModel GetAlbum(int albumId) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { return(GetAlbum(albumId, unitOfWork)); } }
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(); } }
public int AlbumsCount(int userId) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { return(unitOfWork.Albums.Filter(model => model.OwnerId == userId && !model.IsDeleted).Sum(model => 1)); } }
public IEnumerable <AlbumTagModel> GetTags(int albumId) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { return(unitOfWork.AlbumTags.Filter(tag => tag.Id == albumId).ToList()); } }
/// <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); } }
public void Update(UserModel userModel) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { unitOfWork.Users.Update(userModel); unitOfWork.SaveChanges(); } }
//todo Shall refactor and delete. Soon ..) public PhotoModel GetPhotoWithoutRightsCheck(int photoId) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { PhotoModel photoModel = unitOfWork.Photos.Find(photoId); return(photoModel); } }
public bool IsUserExist(int userId) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { IUserRepository userRepository = unitOfWork.Users; return(userRepository.Contains(model => model.Id == userId && model.IsActivated)); } }
public bool IsUserExist(string userEmail) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { IUserRepository userRepository = unitOfWork.Users; return(userRepository.Contains(model => model.Email == userEmail && model.IsActivated)); } }
public IEnumerable <AlbumModel> GetAllAlbums(int userId) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { UserModel user = GetUser(userId, unitOfWork); return(user.Albums.Where(model => !model.IsDeleted).ToList()); } }
public IEnumerable <AlbumTagModel> GetAlbumTags(int albumId) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { AlbumModel album = GetAlbum(albumId, unitOfWork); return(album.Tags.ToList()); } }
public PhotoModel UpdatePhoto(PhotoModel photoModel) { using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { unitOfWork.Photos.Update(photoModel); unitOfWork.SaveChanges(); return(photoModel); } }
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()); } }
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(); } }
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); } }
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)); } }
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()); } }
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))); } }
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(); } }
/// <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))); } }