Beispiel #1
0
        public BookManagementForm(
            IRepository <Book> repository,
            Book entity,
            ObservableCollection <Genre> genres,
            ObservableCollection <Author> authors,
            ObservableCollection <ActivityVM> genreCheckBoxFilter,
            ObservableCollection <ActivityVM> authorCheckBoxFilter
            ) : this(repository, genres, authors, genreCheckBoxFilter, authorCheckBoxFilter, "Edit book")
        {
            FormType = ManagmentType.UPDATE;
            Entity   = new Book()
            {
                Id            = entity.Id,
                Title         = entity.Title,
                Description   = entity.Description,
                Damaged       = entity.Damaged,
                Authors       = entity.Authors,
                Genres        = entity.Genres,
                PictureName   = entity.PictureName,
                PublisingDate = entity.PublisingDate
            };

            Entity.Genres.Foreach(genre =>
            {
                GenreCheckBoxFilter.SingleOrDefault(it => it.EntityID == genre.Id).IsSelected = true;
            });

            Entity.Authors.Foreach(author =>
            {
                AuthorCheckBoxFilter.SingleOrDefault(it => it.EntityID == author.Id).IsSelected = true;
            });
        }
Beispiel #2
0
        public override void ActionExecute()
        {
            var addedItemGenre =
                Genres
                .Where(genre => GenreCheckBoxFilter
                       .Where(checkbox => checkbox.IsSelected).Any(checkbox => checkbox.EntityID == genre.Id))
                .ToObservableCollection();



            Entity.Genres.AddItems(addedItemGenre.Where(item => Entity.Genres.Any(it => it.Id != item.Id)));


            //var removedGenre =
            //     Genres
            //     .Where(genre => GenreCheckBoxFilter
            //     .Where(checkbox => !checkbox.IsSelected).Any(checkbox => checkbox.EntityID == genre.Id))
            //     .Where(genre => Entity.Genres.Any(entity => entity.Id == genre.Id)).ToObservableCollection();

            //if (removedGenre.Count > 0)
            //    Entity.Genres.RemoveItems(removedGenre);


            //var addedItemGenre =
            //    Genres.Where(
            //        genre =>
            //        GenreCheckBoxFilter
            //        .Where(checkbox => checkbox.IsSelected)
            //        .Any(checkbox => genre.Id == checkbox.EntityID)
            //        ).Where(it => !Entity.Genres.Contains(it)).ToObservableCollection();

            ////addedItemGenre = addedItemGenre.Where(genre => !Entity.Genres.Contains(genre)).ToObservableCollection();

            //if(addedItemGenre.Count > 0)
            //    Entity.Genres.AddItems(addedItemGenre);


            //var addedItemAuthor =
            //    Authors.Where(
            //        author =>
            //        AuthorCheckBoxFilter
            //        .Where(checkbox => checkbox.IsSelected)
            //        .Any(checkbox => checkbox.EntityID == author.Id)
            //        ).ToObservableCollection();

            //addedItemAuthor = addedItemAuthor.Where(author => !Entity.Authors.Contains(author)).ToObservableCollection();

            //if (addedItemAuthor.Count > 0)
            //    Entity.Authors.AddItems(addedItemAuthor);

            //var removedItemGenre =
            //  Entity.Genres.Where(
            //      genre =>
            //          GenreCheckBoxFilter
            //          .Where(checkbox => !checkbox.IsSelected)
            //          .Any(checkbox => checkbox.EntityID == genre.Id)
            //      ).ToObservableCollection();


            //if (removedItemGenre.Count > 0)
            //    Entity.Genres.RemoveItems(removedItemGenre);

            //var removedItemAuthor =
            // Entity.Authors.Where(
            //     author =>
            //         AuthorCheckBoxFilter
            //         .Where(checkbox => !checkbox.IsSelected)
            //         .Any(checkbox => checkbox.EntityID == author.Id)
            //     ).ToObservableCollection();

            //if (removedItemAuthor.Count > 0)
            //    Entity.Authors.RemoveItems(removedItemAuthor);


            if (_imageFile != null)
            {
                var hash      = new ImageHash().GetHash(_imageFile.FullName);
                var hashImage = hash + ".jpg";
                var fpname    = AppData.PathResourceImages + hashImage;

                if (!File.Exists(fpname))
                {
                    _imageFile.CopyTo(fpname);
                }

                Entity.PictureName = hashImage;
            }

            base.ActionExecute();
        }