Esempio n. 1
0
        public async Task <ActionResult> AddAnime(AnimeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var isAlready = await Context.Anime.AnyAsync(x => x.MalId == model.MalId);

                if (isAlready)
                {
                    ModelState.AddModelError(string.Empty, "Anime-ul deja exista.");
                    Response.StatusCode = AnimeUtils.PartialStatusCode;
                    return(PartialView("_Partials/_AddAnimeForm", model));
                }

                var genres = model.Genres.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim());
                if (genres.Any(x => !AnimeUtils.Genres.Select(y => y.ToLower()).Contains(x.Trim().ToLower())))
                {
                    return(BadRequest("Unul sau mai multe genuri invalide."));
                }

                model.Genres = string.Join(", ", genres);
                var anime = AutoMapper.Map <AnimeViewModel, Anime>(model);

                anime.TranslateStatus = TranslateStatus.InCursDeTraducere;
                await Context.Anime.AddAsync(anime);

                await Context.SaveChangesAsync();

                return(Ok());
            }
            Response.StatusCode = AnimeUtils.PartialStatusCode;
            return(PartialView("Partials/_AddAnimeForm", model));
        }
Esempio n. 2
0
        public async Task <ActionResult> EditAnime(AnimeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var anime = await Context.Anime.FirstOrDefaultAsync(x => x.Id == model.Id);

                if (anime == null)
                {
                    return(NotFound("Anime-ul nu exista."));
                }

                anime.BigImage        = model.BigImage;
                anime.EpisodeLength   = model.EpisodeLength;
                anime.Genres          = model.Genres;
                anime.Image           = model.Image;
                anime.NoOfEpisodes    = model.NoOfEpisodes;
                anime.Title           = model.Title;
                anime.Synopsis        = model.Synopsis;
                anime.Synonyms        = model.Synonyms;
                anime.Status          = model.Status;
                anime.Type            = model.Type;
                anime.Score           = model.Score;
                anime.EpisodeLength   = model.EpisodeLength;
                anime.BigImage        = model.BigImage;
                anime.TranslateStatus = model.TranslateStatus;

                Context.Update(anime);
                await Context.SaveChangesAsync();

                return(Ok());
            }

            Response.StatusCode = AnimeUtils.PartialStatusCode;
            return(PartialView("Partials/_EditAnimePartial", model));
        }
Esempio n. 3
0
        public static Anime VMToAnime(AnimeViewModel Anime)
        {
            Anime vm = new Anime();

            vm.Id          = Anime.Id;
            vm.Name        = Anime.Name;
            vm.OrderName   = Anime.OrderName;
            vm.ImgSrc      = Anime.ImgSrc;
            vm.Description = Anime.Description;
            // vm.Node = Anime.Node;
            vm.SrcTrailer  = Anime.SrcTrailer;
            vm.EpisodesMax = Anime.EpisodesMax;
            vm.IsAnime     = Anime.IsAnime;
            vm.IsEpisodes  = Anime.IsEpisodes;
            vm.CreateTime  = Anime.CreateTime;
            vm.UpdateTime  = Anime.UpdateTime;
            vm.SeasonId    = Anime.SeasonId;
            vm.SeasonName  = Anime.SeasonName;
            vm.YearId      = Anime.YearId;
            vm.SubId       = Anime.SubId;
            // vm.CategoryIds = Anime.CategoryIds;
            if ((Anime.CategoryIds != null) && (Anime.CategoryIds.Count > 0))
            {
                foreach (var item in Anime.CategoryIds)
                {
                    vm.CategoryIds += item + ",";
                }
                vm.CategoryIds = vm.CategoryIds.Remove(vm.CategoryIds.Length - 1);
            }
            return(vm);
        }
Esempio n. 4
0
        public static AnimeViewModel AnimeToVM(Anime Anime)
        {
            AnimeViewModel vm = new AnimeViewModel();

            vm.Id          = Anime.Id;
            vm.Name        = Anime.Name;
            vm.OrderName   = Anime.OrderName;
            vm.ImgSrc      = Anime.ImgSrc;
            vm.Description = Anime.Description;
            // vm.Node = Anime.Node;
            vm.SrcTrailer  = Anime.SrcTrailer;
            vm.EpisodesMax = Anime.EpisodesMax;
            vm.IsAnime     = Anime.IsAnime;
            vm.IsEpisodes  = Anime.IsEpisodes;
            vm.CreateTime  = Anime.CreateTime;
            vm.UpdateTime  = Anime.UpdateTime;
            vm.SeasonId    = Anime.SeasonId;
            vm.SeasonName  = Anime.SeasonName;
            vm.YearId      = Anime.YearId;
            vm.SubId       = Anime.SubId;
            // vm.CategoryIds = Anime.CategoryIds;
            if (!String.IsNullOrEmpty(Anime.CategoryIds))
            {
                vm.CategoryIds = Anime.CategoryIds.Split(",");
            }
            return(vm);
        }
Esempio n. 5
0
        public ActionResult EditAnime(AnimeViewModel viewModel)
        {
            if (LoginUserSession.Current.IsAuthenticated)
            {
                if (viewModel == null)
                {
                    TempData["Message"] = "No View Model";
                    return(RedirectToAction("Edit"));
                }

                AnimeRepository repo  = new AnimeRepository();
                Anime           anime = repo.GetByID(viewModel.ID);

                if (anime == null)
                {
                    anime = new Anime();
                }

                anime.Name          = viewModel.Name;
                anime.AnimeCategory = viewModel.Category;
                anime.Category      = viewModel.CategoryID;
                anime.Rating        = viewModel.Rating;


                repo.Save(anime);

                TempData["Mesage"] = "Anime was successfully saved!";
                return(RedirectToAction("Edit"));
            }


            TempData["ErrorMessage"] = "Please log in";
            return(RedirectToAction("Login", "Login"));
        }
Esempio n. 6
0
        public ActionResult EditAnime(int id = 0)
        {
            if (!LoginUserSession.Current.IsAdministrator)
            {
                return(RedirectToAction("Edit"));
            }

            CategoryRepository categoriesRepo = new CategoryRepository();

            List <Category> categories = categoriesRepo.GetAll();
            Category        category   = new Category();

            ViewBag.Categories = new SelectList(categories, "ID", "Name");

            AnimeRepository animeRepo = new AnimeRepository();

            AnimeViewModel anime;

            if (id != 0)
            {
                anime = new AnimeViewModel(animeRepo.GetByID(id));
            }
            else
            {
                anime = new AnimeViewModel(new Anime());
            }

            return(View(anime));
        }
Esempio n. 7
0
        public async Task <IActionResult> AddComicCategory(AnimeViewModel model)
        {
            await UploadFile(model);

            _acgBasicIntroductionRepository.Create(model);

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 8
0
        public void Update(AnimeViewModel anime)
        {
            var vm = MapperExtend.VMToAnime(anime);

            vm.UpdateTime = DateTime.Now;
            _context.Animes.Update(vm);
            _context.SaveChanges();
        }
Esempio n. 9
0
        public ActionResult Edit()
        {
            AnimeRepository repo = new AnimeRepository();

            AnimeViewModel model = new AnimeViewModel(repo.GetAll());

            return(View(model));
        }
Esempio n. 10
0
 internal void AddTitle(AnimeViewModel title)
 {
     if (title != null)
     {
         Collection.Add(title);
     }
     else
     {
         DisplayAlert("error!", "", "Cancel");
     }
 }
Esempio n. 11
0
        public int Add(AnimeViewModel anime)
        {
            var p = MapperExtend.VMToAnime(anime);

            p.CreateTime = DateTime.Now;
            p.UpdateTime = DateTime.Now;
            p.Status     = true;
            p.IsEpisodes = true;
            var a = _context.Animes.Add(p);

            var xxx = _context.SaveChanges();

            return(a.Entity.Id);
        }
Esempio n. 12
0
        public async Task <List <AnimeViewModel> > GetAll()
        {
            var listItems = await _context.Animes.ToListAsync();

            List <AnimeViewModel> listVM = new List <AnimeViewModel>();

            foreach (var item in listItems)
            {
                AnimeViewModel vm = new AnimeViewModel();
                vm = MapperExtend.AnimeToVM(item);
                listVM.Add(vm);
            }
            return(listVM);
        }
Esempio n. 13
0
        public static AnimeViewModel GetViewModel(this Anime anime)
        {
            var animeVm = new AnimeViewModel()
            {
                ID          = anime.Id,
                Name        = anime.Name,
                Description = anime.Description,
                PictureURL  = anime.PictureURL,
                Genre       = anime.Genre,
                CreatedAt   = anime.CreatedAt
            };

            return(animeVm);
        }
Esempio n. 14
0
        public async Task <IActionResult> SearchAnime(string searchText)
        {
            var            malApiUrl = "https://myanimelist.net/api/anime/search.xml";
            HttpWebRequest wr        = (HttpWebRequest)WebRequest.Create(malApiUrl + "?q=" + searchText);

            var authHeaderBytes = System.Text.Encoding.UTF8.GetBytes("PhoenixItachi:juventus32");
            var authHeader      = Convert.ToBase64String(authHeaderBytes);

            wr.Headers[HttpRequestHeader.Authorization] = "Basic " + authHeader;
            HttpWebResponse response = await wr.GetResponseAsync() as HttpWebResponse;

            List <AnimeViewModel> animeList = new List <AnimeViewModel>();

            try
            {
                if (response.StatusCode == HttpStatusCode.NoContent)
                {
                    return(new JsonResult(new { more = false }));
                }

                var responseStream = response.GetResponseStream();

                var xml  = XDocument.Load(responseStream);
                var list = xml.Descendants("entry").ToList()?.Take(5);
                foreach (var anime in list)
                {
                    var animeDB = await Context.Anime.FirstOrDefaultAsync(x => x.MalId == Int32.Parse(anime.Element("id").Value));

                    var animeObj = new AnimeViewModel()
                    {
                        Id           = animeDB != null ? animeDB.Id : -1,
                        MalId        = Int32.Parse(anime.Element("id").Value),
                        Title        = anime.Element("title").Value,
                        NoOfEpisodes = int.Parse(anime.Element("episodes").Value),
                        Status       = anime.Element("status").Value,
                        Type         = anime.Element("type").Value,
                        Score        = anime.Element("score").Value,
                        Image        = anime.Element("image").Value,
                        Synonyms     = anime.Element("synonyms").Value,
                        Synopsis     = anime.Element("synopsis").Value
                    };
                    animeList.Add(animeObj);
                }
            }
            catch (Exception e)
            {
            }

            return(new JsonResult(animeList));
        }
Esempio n. 15
0
        private async Task UploadFile(AnimeViewModel model)
        {
            foreach (var file in model.FormFile)
            {
                if (file.Length > 0)
                {
                    var guid = Guid.NewGuid().ToString();
                    var path = Path.Combine(_configuration.GetValue <string>("ThumbnailFolderPath"), guid);
                    await using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }

                    model.ThumbnailPath = path;
                }
            }
        }
Esempio n. 16
0
        public async Task <ActionResult> SetAnimeTranslateStatus(AnimeViewModel model)
        {
            if (!Enum.IsDefined(typeof(TranslateStatus), model.TranslateStatus.ToString()))
            {
                return(NotFound("Status-ul nu este corect."));
            }

            var anime = await Context.Anime.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (anime == null)
            {
                return(NotFound("Anime-ul nu exista."));
            }

            anime.TranslateStatus = model.TranslateStatus;
            await Context.SaveChangesAsync();

            return(Ok());
        }
Esempio n. 17
0
        public AnimeViewModel GetById(int id)
        {
            var sanitizer = new HtmlSanitizer();
            var anime     = this.animes.AllAsNoTracking().Where(x => x.Id == id).FirstOrDefault();
            var model     = new AnimeViewModel
            {
                Title      = anime.Title,
                Studios    = anime.Studios,
                Synopsis   = sanitizer.Sanitize(anime.Synopsis),
                Rating     = anime.Rating,
                Episodes   = anime.Episodes.ToString(),
                Duration   = anime.EpisodeDuration,
                Aired      = anime.Aired,
                PictureUrl = anime.Picture,
                Genres     = anime.Genres,
            };

            return(model);
        }
Esempio n. 18
0
        public IActionResult SaveEntity(AnimeViewModel animeVm)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(allErrors));
            }
            else
            {
                if (animeVm.Id == 0)
                {
                    _animeService.Add(animeVm);
                }
                else
                {
                    _animeService.Update(animeVm);
                }

                return(new OkObjectResult(animeVm));
            }
        }
 public AddAnimePage(AnimeViewModel vm)
 {
     InitializeComponent();
     ViewModel           = vm;
     this.BindingContext = ViewModel;
 }