Пример #1
0
        public async Task UpdateShelf(int id, ShelfViewModel viewModel)
        {
            var shelf = _mapper.Map <Shelf>(viewModel);

            _context.Shelves.Update(shelf);
            await _context.SaveChangesAsync();
        }
Пример #2
0
        public async Task CreateShelf(ShelfViewModel viewModel)
        {
            var shelf = _mapper.Map <Shelf>(viewModel);

            _context.Shelves.Add(shelf);
            await _context.SaveChangesAsync();
        }
Пример #3
0
        public IActionResult AllCats()
        {
            ShelfViewModel viewModel = new ShelfViewModel {
                Cats = catService.GetAllCats()
            };

            return(View("Cats", viewModel));
        }
Пример #4
0
        public IActionResult AdoptableCats()
        {
            ShelfViewModel viewModel = new ShelfViewModel {
                Cats = catService.GetAdoptableCats(), OnlyAdoptable = true
            };

            return(View("Cats", viewModel));
        }
Пример #5
0
        public async Task <ShelfViewModel> GetRelatedEntities()
        {
            var viewModel = new ShelfViewModel()
            {
                Sectors = await _context.Sectors.ToListAsync()
            };

            return(viewModel);
        }
Пример #6
0
 /// <summary>
 /// 实时界面数据刷新
 /// </summary>
 private void Page_Frush()
 {
     shelfBase.ShelfList.Clear();
     foreach (var model in ShelfViewModel.GetShelfList())
     {
         shelfBase.ShelfList.Add(model);
     }
     this.ShelfDataGrid.ItemsSource = shelfBase.ShelfList;
 }
Пример #7
0
        public async Task <IActionResult> Detail(int shelfId, string slug = "")
        {
            if (shelfId == 0)
            {
                return(RedirectToAction("Error", "Home"));
            }

            var userId = User.GetUserId();

            var shelf = _unitOfWork.Shelves.GetShelf(shelfId);

            if (shelf == null ||
                shelf.IsDeleted ||
                !shelf.IsPublic && shelf.CreatedById != userId ||
                (!string.IsNullOrEmpty(slug) && shelf.Slug != slug))
            {
                return(RedirectToAction("Error", "Home"));
            }

            var viewModel = new ShelfViewModel
            {
                ShowActions  = User.Identity.IsAuthenticated,
                IsShelfOwner = userId == shelf.CreatedById,
                Shelf        = shelf,
                Items        = new List <ItemViewModel>()
            };

            foreach (var item in shelf.Items)
            {
                var itemViewModel = new ItemViewModel()
                {
                    Item = item
                };

                if (!string.IsNullOrEmpty(item.CoverId))
                {
                    itemViewModel.CoverImageUrl = new Cloudinary().GetResource(item.CoverId)?.SecureUrl;
                }
                else
                {
                    switch (item.Type)
                    {
                    case ItemType.Book:
                        itemViewModel.CoverImageUrl = _unitOfWork.ItemBookDetails.GetBookDetailByItemId(item.Id)?.ImageLink;
                        break;

                    case ItemType.Game:
                        itemViewModel.CoverImageUrl = (await _rawgGamesClient.ReadAsync(item.RawgId.ToString()))?.Background_image.ToString();
                        break;
                    }
                }

                viewModel.Items.Add(itemViewModel);
            }

            return(View(viewModel));
        }
Пример #8
0
        public void SetNumberShouldSetNumberToModel()
        {
            var shelf     = new Shelf();
            var viewModel = new ShelfViewModel(shelf, _eventAggregator);

            viewModel.Number = "4";

            shelf.Number.Should().Be("4");
        }
Пример #9
0
        public async Task <IActionResult> Edit(int id, ShelfViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                await _service.UpdateShelf(id, viewModel);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
Пример #10
0
        public async Task <IActionResult> Create(ShelfViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                await _service.CreateShelf(viewModel);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
Пример #11
0
 public ActionResult <string> InsertShelf([FromBody] ShelfViewModel customer)
 {
     try
     {
         _logger.LogInformation("Received post Shelf request");
         _shelfServices.InsertShelf(_mapper.Map <Shelf>(customer));
         return(Ok("success"));
     }
     catch (Exception exception)
     {
         _logger.LogError(exception, exception.Message);
         return(new StatusCodeResult(500));
     }
 }
Пример #12
0
        public void ConstructorShouldInitializeMember()
        {
            var shelf = new Shelf {
                Number = "1"
            };

            shelf.Parts.Add(new Part {
                Position = 1, Barcode = "barcode"
            });

            var viewModel = new ShelfViewModel(shelf, _eventAggregator);

            viewModel.Number.Should().Be("1");
            viewModel.Parts.Count.Should().Be(1);
        }
Пример #13
0
        public void ReceivingAddPartEventWithWrongShelfShouldNotAddPart()
        {
            var part = new Part {
                Barcode = "expected", Position = 1
            };
            var shelf     = new Shelf();
            var viewModel = new ShelfViewModel(shelf, _eventAggregator);

            var addPartEvent = _eventAggregator.GetEvent <PubSubEvent <AddPartEvent> >();

            addPartEvent.Publish(new AddPartEvent {
                Shelf = new Shelf(), Part = part
            });

            viewModel.Parts.Count.Should().Be(0);
        }
Пример #14
0
        /// <summary>
        /// Adds shelving to one of the view model's collection
        /// </summary>
        /// <param name="shelvingType">
        /// The type of shelving to be added to
        /// </param>
        public void AddShelvingTo(Model.ShelvingType shelvingType)
        {
            switch (shelvingType)
            {
            case Model.ShelvingType.Shelf:
                ShelfViewModel.Add(Room.RoomNumber, IsShelfSameColor ? Room.ShelvingColor : null, IsPanelSameDepth ? Room.ShelvingDepth : null);
                break;

            case Model.ShelvingType.Wire:
                break;

            case Model.ShelvingType.Accessory:
                AccessoryViewModel.Add(Room.RoomNumber);
                break;
            }
        }
Пример #15
0
        public async Task <ShelfViewModel> GetWantToRead(string userId)
        {
            var user = await this.userManager.FindByIdAsync(userId);

            var model = new ShelfViewModel();
            var want  = this.wantRepo.AllAsNoTracking().Where(x => x.UserId == userId).ToList();

            foreach (var map in want)
            {
                var manga = this.mangaRepo.AllAsNoTracking().FirstOrDefault(x => x.Id == map.MangaId);
                model.ShelfItems.Add(new ShelfItemVIewModel {
                    Title = manga.Title, Id = manga.Id
                });
            }

            return(model);
        }
Пример #16
0
        public async Task <ShelfViewModel> GetWantToWatch(string userId)
        {
            var user = await this.userManager.FindByIdAsync(userId);

            var model = new ShelfViewModel();
            var read  = this.wantRepo.AllAsNoTracking().Where(x => x.UserId == userId).ToList();

            foreach (var map in read)
            {
                var anime = this.animeRepo.AllAsNoTracking().FirstOrDefault(x => x.Id == map.AnimeId);
                model.ShelfItems.Add(new ShelfItemVIewModel {
                    Title = anime.Title, Id = anime.Id
                });
            }

            return(model);
        }
Пример #17
0
        private ShelfViewModel MapShelfDtoToShelfViewModel(ShelfDto dto)
        {
            var vm = new ShelfViewModel
            {
                Id          = dto.Id,
                Name        = dto.Name,
                OwnerId     = dto.OwnerId,
                AccessLevel = dto.AccessLevel
            };

            if (dto.ShelfItems != null)
            {
                vm.ShelfItems     = dto.ShelfItems.Data;
                vm.PaginationInfo = GetPaginationInfo(dto.ShelfItems.PageIndex + 1,
                                                      dto.ShelfItems.PageSize, dto.ShelfItems.Count);
            }
            return(vm);
        }
Пример #18
0
        public void ReceivingRemovePartEventShouldRemovePart()
        {
            var part = new Part {
                Barcode = "expected", Position = 1
            };
            var shelf = new Shelf();

            shelf.Parts.Add(part);
            var viewModel = new ShelfViewModel(shelf, _eventAggregator);

            var removePartEvent = _eventAggregator.GetEvent <PubSubEvent <RemovePartFromShelfEvent> >();

            removePartEvent.Publish(new RemovePartFromShelfEvent {
                Shelf = shelf, Part = part
            });

            viewModel.Parts.Count.Should().Be(0);
        }
Пример #19
0
        public void ReceivingAddPartEventShouldAddPart()
        {
            var part = new Part {
                Barcode = "expected", Position = 1
            };
            var shelf     = new Shelf();
            var viewModel = new ShelfViewModel(shelf, _eventAggregator);

            var addPartEvent = _eventAggregator.GetEvent <PubSubEvent <AddPartEvent> >();

            addPartEvent.Publish(new AddPartEvent {
                Shelf = shelf, Part = part
            });

            viewModel.Parts.Count.Should().Be(1);
            var partViewModel = viewModel.Parts.First();

            partViewModel.Barcode.Should().Be("expected");
            partViewModel.Position.Should().Be(1);
        }
Пример #20
0
        // GET: Shelf

        public async Task <IActionResult> Index()
        {
            if (!_signInManager.IsSignedIn(User))
            {
                return(RedirectToAction("Index", "Home"));
            }
            var shelves = await Utils.Get <List <Shelf> >("api/Shelf");

            foreach (var shelf in shelves)
            {
                var books = await Utils.Get <List <Book> >("api/book");

                books       = books.Where(c => c.ShelfId == shelf.Id).ToList();
                shelf.Books = books;
            }

            var shelfViewModel = new ShelfViewModel {
                Shelves = shelves
            };

            return(View(shelfViewModel));
        }
Пример #21
0
 private void SearchShelf_Loaded(object sender, RoutedEventArgs e)
 {
     DataContext = new ShelfViewModel();
 }
Пример #22
0
 public ShelfSwipeTransition(ShelfViewModel shelf)
 {
     Shelf = shelf;
 }
Пример #23
0
        public ActionResult Details(int id, int page = 1, int pagesize = 0)
        {
            if (id == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var profile = (UserProfile)this.Session["UserInfo"];

            if (profile == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (pagesize < 1 || pagesize > 100)
            {
                pagesize = profile.PageSize;
            }

            ShelfViewModel vm = null;

            using (var db = new SDCContext())
            {
                profile.UpdatePageSize(db, pagesize);

                ViewBag.Languages = db.Languages.Where(p => p.IsVisible).OrderBy(p => p.Code).ToList();
                ViewBag.Genres    = db.Genres.OrderBy(p => p.Name).ToList();


                var shelf = db.Shelves
                            .AsNoTracking()
                            .Include(a => a.Books)
                            .Include(a => a.Books.Select(b => b.Pictures))
                            .Include(a => a.Books.Select(b => b.Authors))
                            .Include(a => a.Books.Select(b => b.Genres))
                            .Include(a => a.Books.Select(b => b.Publisher))
                            .FirstOrDefault(p => p.Id == id);
                if (shelf == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                int totalPages = ((int)Math.Ceiling((double)shelf.Books.Count / pagesize));
                if (page > totalPages)
                {
                    page = totalPages;
                }

                //actual pagination takes place here
                var show_books = shelf.Books
                                 .OrderBy(b => b.AddedDate)
                                 .Skip((page - 1) * pagesize)
                                 .Take(pagesize)
                                 .Select(b => AutoMapper.Mapper.Map <BookViewModel>(b));

                vm = new ShelfViewModel()
                {
                    Id              = shelf.Id,
                    Name            = shelf.Name,
                    IsVisible       = shelf.IsVisible,
                    CanEdit         = shelf.CanBeEdited(profile),
                    BookCount       = shelf.Books.Count(),
                    Books           = show_books,
                    Languages       = Language.GetAll(db),
                    Genres          = Genre.GetAll(db),
                    DefaultLanguage = profile.Country.Language,
                    Pagination      = new PaginationViewModel()
                    {
                        Id          = shelf.Id,
                        Action      = "Details",
                        Controller  = "Shelves",
                        Page        = page,
                        PageSize    = pagesize,
                        TotalPages  = totalPages,
                        EntityCount = show_books.Count(),
                        EntityName  = "Books"
                    }
                };

                if (profile.UserId == shelf.Owner.UserId)
                {
                    ViewBag.Breadcrumbs = Breadcrumb.Generate(
                        "My shelves", Url.Action("Index", "Shelves"),
                        vm.Name, "");
                }
                else
                {
                    ViewBag.Breadcrumbs = Breadcrumb.Generate("Directory", "", vm.Name, "");
                }

                db.Dispose();
            }

            return(View(vm));
        }