Ejemplo n.º 1
0
        public ClientDTO GetCreator(int albumID)
        {
            if (albumID < 1)
            {
                throw new ArgumentOutOfRangeException("Album service - GetCreator(...) albumID cannot be lesser than 1");
            }

            using (UnitOfWorkProvider.Create())
            {
                var album = albumRepository.GetByID(albumID);
                if (album == null)
                {
                    throw new NullReferenceException("Album service - GetCreator(...) album cannot be null(could not be found)");
                }
                return(Mapper.Map <ClientDTO>(album.Creator));
            }
        }
Ejemplo n.º 2
0
 public CustomerListQueryResultDTO ListAllCustomers(int requestedPage = 1)
 {
     using (UnitOfWorkProvider.Create())
     {
         var query = customerListAllQuery;
         query.ClearSortCriterias();
         query.Skip = Math.Max(0, requestedPage - 1) * CustomerPageSize;
         query.Take = CustomerPageSize;
         query.AddSortCriteria(customer => customer.LastName, SortDirection.Ascending);
         return(new CustomerListQueryResultDTO
         {
             RequestedPage = requestedPage,
             TotalResultCount = query.GetTotalRowCount(),
             ResultsPage = query.Execute()
         });
     }
 }
Ejemplo n.º 3
0
        public void EditAlbum(AlbumDTO albumDTO, int artistId, List <int> albumReviewIds, List <int> songIDs)
        {
            if (albumDTO == null)
            {
                throw new ArgumentNullException("Album service - EditAlbum(...) albumDTO cannot be null");
            }
            if (artistId < 1)
            {
                throw new ArgumentOutOfRangeException("Album service - EditAlbum(...) artistId cannot be lesser than 1");
            }

            using (var uow = UnitOfWorkProvider.Create())
            {
                var album = albumRepository.GetByID(albumDTO.ID);
                Mapper.Map(albumDTO, album);

                album.Artist = GetAlbumArtist(artistId);

                if (albumReviewIds != null && albumReviewIds.Any())
                {
                    var albumReviews = albumReviewRepository.GetByIDs(albumReviewIds);
                    album.Reviews.RemoveAll(review => !albumReviews.Contains(review));
                    album.Reviews.AddRange(
                        albumReviews.Where(review => !album.Reviews.Contains(review)));
                }
                else
                {
                    album.Reviews.Clear();
                }

                if (songIDs != null && songIDs.Any())
                {
                    var albumSongs = songRepository.GetByIDs(songIDs);
                    album.Songs.RemoveAll(song => !albumSongs.Contains(song));
                    album.Songs.AddRange(
                        albumSongs.Where(song => !album.Songs.Contains(song)));
                }
                else
                {
                    album.Songs.Clear();
                }

                albumRepository.Update(album);
                uow.Commit();
            }
        }
Ejemplo n.º 4
0
        public ClientDTO GetCreator(int artistID)
        {
            if (artistID < 1)
            {
                throw new ArgumentOutOfRangeException("Artist service - GetCreator(...) artistID cannot be lesser than 1");
            }

            using (UnitOfWorkProvider.Create())
            {
                var artist = artistRepository.GetByID(artistID);
                if (artist == null)
                {
                    throw new NullReferenceException("Artist service - GetCreator(...) artist or creator is null");
                }
                return(Mapper.Map <ClientDTO>(artist.Creator));
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Method which sets image of specific station
 /// </summary>
 /// <param name="stationId"></param>
 /// <returns>true, if image does not existed before</returns>
 public bool SetImageOfStation(int stationId, string pathToPhoto)
 {
     using (var uow = UnitOfWorkProvider.Create())
     {
         var station    = stationRepository.GetById(stationId, s => s.RouteStations);
         var stationDTO = Mapper.Map <StationDTO>(station);
         if (stationDTO.ImagePath != null)
         {
             return(false);
         }
         stationDTO.ImagePath = pathToPhoto;
         Mapper.Map(stationDTO, station);
         stationRepository.Update(station);
         uow.Commit();
         return(true);
     }
 }
Ejemplo n.º 6
0
        public void CreateSpecificRoute(int routeId, DateTime departTime, int vehicleId)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                var route = routeRepository.GetById(routeId, r => r.RouteStations);
                createSpecificRouteQuery.RouteId = routeId;
                var routeStationsTemplates = createSpecificRouteQuery.Execute().ToList();
                var seatDTOs = ListSeatsOfVehicle(vehicleId);

                foreach (var routeStationTemplate in routeStationsTemplates)
                {
                    var routeStation = new RouteStation();
                    Mapper.Map(routeStationTemplate, routeStation);
                    routeStation.DepartFromFirstStation = departTime;
                    var routeStationForGettingStation = routeStationRepository.GetById(routeStationTemplate.ID, routeStationTemplat => routeStationTemplat.Station);

                    var station = stationRepository.GetById(routeStationForGettingStation.Station.ID, s => s.RouteStations);

                    routeStation.Route = route;
                    route.RouteStations.Add(routeStation);

                    routeStation.Station = station;
                    station.RouteStations.Add(routeStation);

                    if (seatDTOs != null)
                    {
                        foreach (var seatDTO in seatDTOs)
                        {
                            var seat    = seatRepository.GetById(seatDTO.ID, s => s.Programs);
                            var program = new Program
                            {
                                IsSeatOccupied = false,
                                RouteStation   = routeStation,
                                Seat           = seat
                            };
                            seat.Programs.Add(program);
                            programRepository.Insert(program);
                            routeStation.Programs.Add(program);
                        }
                    }
                    routeStationRepository.Insert(routeStation);
                }
                uow.Commit();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Deletes the review
        /// </summary>
        /// <param name="reviewID">ID of review to delete</param>
        public void DeleteSongReview(int reviewID)
        {
            if (reviewID < 1)
            {
                throw new ArgumentOutOfRangeException("Song review service - DeleteReview(...) the reviewID cannot be lesser than 1");
            }

            using (var uow = UnitOfWorkProvider.Create())
            {
                var review = songReviewRepository.GetByID(reviewID);
                if (review == null)
                {
                    throw new NullReferenceException("Song review service - DeleteReview(...) the review to be deleted is null");
                }
                songReviewRepository.Delete(review);
                uow.Commit();
            }
        }
Ejemplo n.º 8
0
        public void CreateSong_Songlist(Song_SonglistDTO song_songlistDTO)
        {
            if (song_songlistDTO == null)
            {
                throw new ArgumentNullException("Song_Songlist Service - CreateSong_Songlist(...) song_songlistDTO cannot be null");
            }

            using (var uow = UnitOfWorkProvider.Create())
            {
                var song_songlist = Mapper.Map <Song_Songlist>(song_songlistDTO);
                song_songlist.Songlist = GetSongSonglist(song_songlistDTO.SonglistID);
                song_songlist.Song     = GetSonglistSong(song_songlistDTO.SongID);
                song_songlist.Creator  = GetSong_SonglistCreator(song_songlistDTO.CreatorID);

                song_songlistRepository.Insert(song_songlist);
                uow.Commit();
            }
        }
        public int CreatePlayer(Guid userAccountId)
        {
            Player player;

            using (var uow = UnitOfWorkProvider.Create())
            {
                var playerAccount = userRepository.GetById(userAccountId);

                player = new Player {
                    Account = playerAccount
                };

                playerRepository.Insert(player);

                uow.Commit();
            }
            return(player.ID);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Performs account registration
        /// </summary>
        /// <param name="registrationDto">Account registration details</param>
        /// <returns>Registered account ID</returns>
        public async Task <Guid> RegisterAccount(AccountCreateDto registrationDto)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                try
                {
                    var id = await _accountService.RegisterAccountAsync(registrationDto);

                    await uow.Commit();

                    return(id);
                }
                catch (ArgumentException)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 11
0
        public async Task <BasicUserDto> GetBasicUserWithGroups(int userId)
        {
            using (UnitOfWorkProvider.Create())
            {
                var groups = await _getUserGroupsService.GetGroupsByUserIdAsync(userId, true);

                var groupsInvitedInto = await _getUserGroupsService.GetGroupsByUserIdAsync(userId, false);

                var user = await _basicUsersService.GetAsync(userId);

                var groupDtos = groups.ToList();
                groupDtos.AddRange(groupsInvitedInto);

                user.Groups = groupDtos;

                return(user);
            }
        }
Ejemplo n.º 12
0
        public async Task <int> RegisterCorporation(UserCreateCorporationDTO userDto)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                try
                {
                    var id = await userService.RegisterCorporationUserAsync(userDto);

                    await uow.Commit();

                    return(id);
                }
                catch (ArgumentException)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 13
0
        public ClientListQueryResultDTO ListAllClients(int requiredPage = 1)
        {
            using (UnitOfWorkProvider.Create())
            {
                var query = GetClientQuery();
                query.Skip = Math.Max(0, requiredPage - 1) * ClientPageSize;
                query.Take = ClientPageSize;
                query.AddSortCriteria(client => client.LastName);


                return(new ClientListQueryResultDTO
                {
                    RequestedPage = requiredPage,
                    TotalResultCount = query.GetTotalRowCount(),
                    ResultsPage = query.Execute(),
                });
            }
        }
Ejemplo n.º 14
0
        public async Task <BasicUserDto> GetBasicUserWithFriends(int userId)
        {
            using (UnitOfWorkProvider.Create())
            {
                var friendships = await _friendshipService.GetFriendshipsByUserIdAsync(userId, true);

                var friendshipsNotYet = await _friendshipService.GetFriendshipsByUserIdAsync(userId, false);

                var user = await _basicUsersService.GetAsync(userId);

                var friendshipDtos = friendships.ToList();
                friendshipDtos.AddRange(friendshipsNotYet);

                user.Friends = friendshipDtos;

                return(user);
            }
        }
        private async Task RemoveVote(ImageDto image, VoteDto vote)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                if (vote.Type == VoteType.Like)
                {
                    image.LikesCount--;
                }
                else
                {
                    image.DislikesCount--;
                }
                await imageService.Update(image);

                voteService.Delete(vote.Id);
                await uow.Commit();
            }
        }
Ejemplo n.º 16
0
        public void DeleteSong_Songlist(int song_songlistId)
        {
            if (song_songlistId < 1)
            {
                throw new ArgumentOutOfRangeException("Song_Songlist Service - DeleteSong_Songlist(...) song_songlistId cannot be lesser than 1");
            }

            using (var uow = UnitOfWorkProvider.Create())
            {
                var s_s = song_songlistRepository.GetByID(song_songlistId);
                if (s_s == null)
                {
                    throw new NullReferenceException("Songlist review service - DeleteReview(...) songlist to be deleted is null");
                }
                song_songlistRepository.Delete(s_s);
                uow.Commit();
            };
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Updates review
 /// </summary>
 /// <param name="reviewDTO">Update details</param>
 public void EditAlbumReview(AlbumReviewDTO reviewDTO)
 {
     if (reviewDTO == null)
     {
         throw new ArgumentNullException("Album review service - EditAlbumReview(...) reviewDTO cannot be null");
     }
     using (var uow = UnitOfWorkProvider.Create())
     {
         var review = albumReviewRepository.GetByID(reviewDTO.ID, albumReview => albumReview.Album);
         if (review == null)
         {
             throw new NullReferenceException("Album review service - EditReview(...) the review cannot be null");
         }
         Mapper.Map(reviewDTO, review);
         albumReviewRepository.Update(review);
         uow.Commit();
     }
 }
Ejemplo n.º 18
0
        public async Task <bool> CanSendFriendshipRequest(UserDto applicant, UserDto recipient)
        {
            using (UnitOfWorkProvider.Create())
            {
                var filter = new FriendshipFilterDto
                {
                    // We can swap those, doesn't really matter the order
                    UserA = applicant.Id,
                    UserB = recipient.Id
                };
                var allFriendships = await friendshipService.ListFriendshipAsync(filter);

                filter.IsConfirmed = false;
                var allFriendshipRequests = await friendshipService.ListFriendshipAsync(filter);

                return(allFriendships.TotalItemsCount == 0 && allFriendshipRequests.TotalItemsCount == 0);
            }
        }
Ejemplo n.º 19
0
        public async Task <Guid> RegisterUser(UserCreateDto userCreate)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                try
                {
                    var id = await userService.RegisterUserAsync(userCreate);

                    await uow.Commit();

                    return(id);
                }
                catch (ArgumentException)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 20
0
        public async Task ChangePassword(ChangePasswordDTO data)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                using (var manager = AppUserManagerFactory())
                {
                    var user = await manager.FindByIdAsync(CurrentUser.Id.ToString());

                    var result = await manager.ChangePasswordAsync(user, data.OldPassword, data.NewPassword);

                    if (!result.Succeeded)
                    {
                        throw new UIException("Změna hesla se nezdařila.");
                    }
                    await uow.CommitAsync();
                }
            }
        }
Ejemplo n.º 21
0
        public List <DateTime> GetRouteDepartTimes(int routeId)
        {
            var routeStations = GetRouteStationsByRoute(routeId);

            using (UnitOfWorkProvider.Create())
            {
                var result = new List <DateTime>();
                foreach (var routeStation in routeStations)
                {
                    if (routeStation.DepartFromFirstStation != null && !result.Contains(routeStation.DepartFromFirstStation.GetValueOrDefault()))
                    {
                        result.Add(routeStation.DepartFromFirstStation.GetValueOrDefault());
                    }
                }
                result.Sort();
                return(result);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Remove account according to accountId
        /// </summary>
        /// <param name="accountId"></param>
        /// <returns>true if account was removed</returns>
        public async Task <bool> RemoveAccountAsync(Guid accountId)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                if (_accountService.GetAsync(accountId).Result == null)
                {
                    return(false);
                }
                _accountService.Delete(accountId);
                await uow.Commit();

                if (_accountService.GetAsync(accountId).Result != null)
                {
                    return(false);
                }
                return(true);
            }
        }
Ejemplo n.º 23
0
        public async Task DeletePost(int postId)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                var comments = await _commentService.GetCommentsByPostIdAsync(postId);

                while (!comments.IsNullOrEmpty())
                {
                    var comment = comments.First();
                    _commentService.Delete(comment.Id);
                    comments.Remove(comment);
                }

                _postService.Delete(postId);

                await uow.Commit();
            }
        }
Ejemplo n.º 24
0
        public async Task <int> AddUserReviewAsync(ReviewDto review)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                if (await userService.GetAsync(review.ReviewedUserID) == null)
                {
                    throw new ArgumentException("User does not exist.");
                }

                var res  = reviewService.Create(review);
                var user = await userService.GetAsync(review.ReviewedUserID);

                review.ReviewedUser = user;
                await uow.Commit();

                return(res.Id);
            }
        }
        public async Task <Guid> AddImage(ImageCreateDto imageCreateDto)
        {
            var image = new ImageDto
            {
                BinaryImage   = imageCreateDto.BinaryImage,
                PostId        = imageCreateDto.PostId,
                LikesCount    = 0,
                DislikesCount = 0
            };

            using (var uow = UnitOfWorkProvider.Create())
            {
                var id = imageService.Create(image);
                await uow.Commit();

                return(id);
            }
        }
Ejemplo n.º 26
0
        public async Task <int> AddAuctionAsync(CreateAuction auction)
        {
            if (auction == null)
            {
                return(0);
            }
            using (var uow = UnitOfWorkProvider.Create())
            {
                if (await userService.GetAsync(auction.UserId, false) == null)
                {
                    return(0);
                }

                var res = auctionService.Create(auctionService.MapToBase(auction));
                await uow.Commit();

                return(res.Id);
            }
        }
Ejemplo n.º 27
0
        public async Task <bool> DeleteItemCategory(int itemCategoryId)
        {
            if (itemCategoryId == 0)
            {
                return(false);
            }
            using (var uow = UnitOfWorkProvider.Create())
            {
                if (await itemCategoryService.GetAsync(itemCategoryId) == null)
                {
                    return(false);
                }

                itemCategoryService.Delete(itemCategoryId);
                await uow.Commit();

                return(true);
            }
        }
Ejemplo n.º 28
0
        public async Task <bool> DeleteRaiseAsync(int raiseID)
        {
            if (raiseID == 0)
            {
                return(false);
            }
            using (var uow = UnitOfWorkProvider.Create())
            {
                if (await raiseService.GetAsync(raiseID) == null)
                {
                    return(false);
                }

                raiseService.Delete(raiseID);
                await uow.Commit();

                return(true);
            }
        }
Ejemplo n.º 29
0
 public ClaimsIdentity Login(string email, string password)
 {
     using (var uow = UnitOfWorkProvider.Create())
     {
         using (var userManager = UserManagerFactory())
         {
             ApplicationUser user;
             try
             {
                 user = userManager.Find(email, password);
             }
             catch (Exception ex)
             {
                 throw;
             }
             return(userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie));
         }
     }
 }
 public async Task AddReplyToPost(Guid postId, Guid userId, string reply)
 {
     using (var uow = UnitOfWorkProvider.Create())
     {
         if (reply.Length < MinimalPostReplyLength)
         {
             throw new ArgumentException($"Comment must have atleast {MinimalPostReplyLength} characters");
         }
         var comment = new PostReplyDto
         {
             PostId = postId,
             UserId = userId,
             Text   = reply,
             Time   = DateTime.Now,
         };
         postReplyService.Create(comment);
         await uow.Commit();
     }
 }