示例#1
0
        private async Task LoadFavouriteBoolAndRatings(int id, string userId, AnimeDetailsViewModel viewModel)
        {
            var ratedAnime = await this.ProfileService.GetUserRatingsAsync(id, userId);

            if (ratedAnime == null)
            {
                viewModel.IsFavourite = false;
                viewModel.Rating      = 0;
            }
            else
            {
                viewModel.IsFavourite = ratedAnime.IsFavourite;
                viewModel.Rating      = ratedAnime.Rating;
            }
        }
        public AnimeDetailsViewModel GetDetails(int id)
        {
            var product = _context.Animes.Find(id);

            if (product == null)
            {
                throw new Exception("Anime isn't in data.");
            }
            //var vm = MapperExtend.AnimeToVM(product);
            AnimeDetailsViewModel vm = new AnimeDetailsViewModel();

            vm.Id         = product.Id;
            vm.Name       = product.Name;
            vm.OrtherName = product.OrderName;
            vm.Image      = product.ImgSrc;
            vm.Details    = product.Description;
            vm.MaxEps     = product.EpisodesMax;

            vm.YearId = product.YearId;
            var y = _context.Year.Find(vm.YearId);

            if (y == null)
            {
                vm.YearName = " ";
            }
            else
            {
                vm.YearName = y.Name;
            }

            var sub = _context.Subs.Find(product.SubId);

            if (sub == null)
            {
                vm.SubName = " ";
            }
            else
            {
                vm.SubName = sub.Name;
            }


            vm.CategoryId = new List <string>();
            if (!String.IsNullOrEmpty(product.CategoryIds))
            {
                vm.CategoryId = product.CategoryIds.Split(",");
            }
            vm.CategoryName = new List <string>();
            foreach (var item in vm.CategoryId)
            {
                var c = _context.Catetgories.Find(Int32.Parse(item));
                if (c == null)
                {
                    vm.CategoryName.Add(" ");
                }
                else
                {
                    vm.CategoryName.Add(c.Name);
                }
            }
            vm.EpsName = new List <string>();
            vm.EpsId   = new List <int>();
            var eps = _context.Episodes.Where(x => x.AnimeId == product.Id).OrderByDescending(x => x.STT).Take(3);

            if (eps != null)
            {
                foreach (var ep in eps)
                {
                    vm.EpsId.Add(ep.Id);
                    vm.EpsName.Add(ep.Number);
                }
            }

            return(vm);
        }
 public AnimeDetailsView(AnimeDetailsViewModel animeDetailsView)
 {
     DataContext = animeDetailsView;
     InitializeComponent();
 }