Пример #1
0
        public async Task AddAsyncGenre(SectionTVShowCategory model)
        {
            var trustedFileNameForDisplay   = string.Empty;
            var trustedFilePathForStorage   = string.Empty;
            var streamedFilePhysicalContent = new byte[0];

            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Genre",
                                         $"The request couldn't be processed (Error 1).");
                // Log error
            }

            streamedFilePhysicalContent =
                await FileHelpers.ProcessFormFile <StreamFileUploadDatabase>(
                    model.FormFile, ModelState, _permittedExtentions,
                    _fileSizeLimit);

            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Genre",
                                         $"The request couldn't be processed (Error 1).");
                // Log error
            }

            trustedFilePathForStorage = String.Format("{0}\\{1}\\{2}",
                                                      _targetImagePath,
                                                      Guid.NewGuid().ToString(),
                                                      Path.GetRandomFileName());
            trustedFileNameForDisplay = String.Format("{0}_{1}",
                                                      Guid.NewGuid(),
                                                      WebUtility.HtmlEncode(model.FormFile.FileName));

            Directory.CreateDirectory(trustedFilePathForStorage);
            using (var targetStream = System.IO.File.Create(
                       Path.Combine(trustedFilePathForStorage, trustedFileNameForDisplay)))
            {
                await targetStream.WriteAsync(streamedFilePhysicalContent);

                //_logger.LogInformation(
                //    "Uploaded file '{TrustedFileNameForDisplay}' saved to " +
                //    "'{TargetFilePath}' as {TrustedFileNameForFileStorage}",
                //    trustedFileNameForDisplay, trustedFilePathForStorage,
                //    trustedFileNameForDisplay);
            }

            // TODO: Add insert logic here
            ClamSectionTVShowCategory result = new ClamSectionTVShowCategory
            {
                Genre    = model.Genre,
                ItemPath = Path.Combine(trustedFilePathForStorage, trustedFileNameForDisplay)
            };
            await _context.ClamSectionTVShowCategories.AddAsync(result);

            Task.WaitAll(_context.SaveChangesAsync());
        }
Пример #2
0
        public async Task <IActionResult> DeleteGenre(Guid id, SectionTVShowCategory entity, string category)
        {
            try
            {
                await _unitOfWork.TVShowControl.RemoveGenre(id, entity);

                _unitOfWork.Complete();
                return(RedirectToAction(nameof(Genre)));
            }
            catch
            {
                return(View());
            }
        }
Пример #3
0
        public async Task <IActionResult> EditGenre(Guid id, SectionTVShowCategory collection, string category)
        {
            try
            {
                await _unitOfWork.TVShowControl.UpdateGenre(id, collection);

                _unitOfWork.Complete();
                return(RedirectToAction(nameof(Genre)));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(View());
            }
        }
Пример #4
0
        public async Task <IActionResult> CreateGenre(SectionTVShowCategory model)
        {
            try
            {
                await _unitOfWork.TVShowControl.AddAsyncGenre(model);

                _unitOfWork.Complete();
                return(View());
            }
            catch
            {
                return(View("Error"));
            }
        }
Пример #5
0
        public async Task <SectionTVShowCategory> GetGenre(Guid id)
        {
            var shows = await _context.ClamSectionTVShowSubCategories.ToListAsync();

            var seasons = await _context.ClamSectionTVShowSubCategorySeasons.ToListAsync();

            var episodes = await _context.ClamSectionTVShowSubCategorySeasonItems.ToListAsync();

            var model = await _context.ClamSectionTVShowCategories.FindAsync(id);

            SectionTVShowCategory retrieveModel = new SectionTVShowCategory()
            {
                CategoryId                 = model.CategoryId,
                Genre                      = model.Genre,
                ItemPath                   = model.ItemPath,
                LastModified               = model.LastModified,
                DateCreated                = model.DateCreated,
                SubCategoryCount           = shows.Select(x => x.CategoryId).Where(x => x.Equals(id)).Count(),
                SubCategorySeasonCount     = seasons.Select(x => x.CategoryId).Where(x => x.Equals(id)).Count(),
                SubCategorySeasonItemCount = episodes.Select(x => x.CategoryId).Where(x => x.Equals(id)).Count()
            };

            return(retrieveModel);
        }
Пример #6
0
        public async Task UpdateGenre(Guid id, SectionTVShowCategory model)
        {
            var trustedFileNameForDisplay   = string.Empty;
            var trustedFilePathForStorage   = string.Empty;
            var streamedFilePhysicalContent = new byte[0];

            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Genre",
                                         $"The request couldn't be processed (Error 1).");
                // Log error
            }

            streamedFilePhysicalContent =
                await FileHelpers.ProcessFormFile <StreamFileUploadDatabase>(
                    model.FormFile, ModelState, _permittedExtentions,
                    _fileSizeLimit);

            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Genre",
                                         $"The request couldn't be processed (Error 1).");
                // Log error
            }

            var result = _context.Set <ClamSectionTVShowCategory>().Find(id);

            if (Directory.Exists(FilePathUrlHelper.GetFileDirectoryPath(result.ItemPath)))
            {
                System.IO.File.Delete(result.ItemPath);
            }

            trustedFilePathForStorage = String.Format("{0}\\{1}\\{2}",
                                                      _targetImagePath,
                                                      Guid.NewGuid().ToString(),
                                                      Path.GetRandomFileName());
            trustedFileNameForDisplay = String.Format("{0}_{1}",
                                                      Guid.NewGuid(),
                                                      WebUtility.HtmlEncode(model.FormFile.FileName));

            Directory.CreateDirectory(trustedFilePathForStorage);
            using (var targetStream = System.IO.File.Create(
                       Path.Combine(trustedFilePathForStorage, trustedFileNameForDisplay)))
            {
                await targetStream.WriteAsync(streamedFilePhysicalContent);

                //_logger.LogInformation(
                //    "Uploaded file '{TrustedFileNameForDisplay}' saved to " +
                //    "'{TargetFilePath}' as {TrustedFileNameForFileStorage}",
                //    trustedFileNameForDisplay, trustedFilePathForStorage,
                //    trustedFileNameForDisplay);
            }

            // TODO: Add update logic here
            var entity = await _context.ClamSectionTVShowCategories.FindAsync(id);

            _context.Entry(entity).Entity.Genre        = model.Genre;
            _context.Entry(entity).Entity.ItemPath     = Path.Combine(trustedFilePathForStorage, trustedFileNameForDisplay);
            _context.Entry(entity).Entity.LastModified = DateTime.Now;
            _context.Entry(entity).State = EntityState.Modified;
            _context.Update(entity);

            Task.WaitAll(_context.SaveChangesAsync());
        }
Пример #7
0
        public async Task RemoveGenre(Guid id, SectionTVShowCategory model)
        {
            var fullDirectoryPath = string.Empty;

            fullDirectoryPath = string.Format("{0}\\{1}",
                                              _targetFolderPath,
                                              model.CategoryId.ToString());
            var result = await _context.ClamSectionTVShowCategories.FindAsync(id);

            var collectEpisodes = _context.ClamSectionTVShowSubCategorySeasonItems.AsNoTracking();
            var collectSeasons  = _context.ClamSectionTVShowSubCategorySeasons.AsNoTracking();
            var collectShows    = _context.ClamSectionTVShowSubCategories.AsNoTracking();
            List <ClamSectionTVShowSubCategory>           shows       = new List <ClamSectionTVShowSubCategory>();
            List <ClamSectionTVShowSubCategorySeason>     seasons     = new List <ClamSectionTVShowSubCategorySeason>();
            List <ClamSectionTVShowSubCategorySeasonItem> seasonItems = new List <ClamSectionTVShowSubCategorySeasonItem>();

            if (collectEpisodes.Select(x => x.CategoryId).Where(x => x.Equals(id)).Count() > 0)
            {
                foreach (var item in collectEpisodes)
                {
                    if (item.CategoryId == model.CategoryId)
                    {
                        seasonItems.Add(new ClamSectionTVShowSubCategorySeasonItem()
                        {
                            ItemId     = item.ItemId,
                            CategoryId = model.CategoryId,
                            TVShowId   = item.TVShowId,
                            SeasonId   = item.SeasonId
                        });

                        if (!seasons.Any(x => x.SeasonId == item.SeasonId))
                        {
                            seasons.Add(new ClamSectionTVShowSubCategorySeason()
                            {
                                TVShowId   = item.TVShowId,
                                CategoryId = model.CategoryId,
                                SeasonId   = item.SeasonId,
                            });
                        }
                    }
                }
            }
            if (collectSeasons.Select(x => x.CategoryId).Where(x => x.Equals(id)).Count() > 0)
            {
                foreach (var item in collectSeasons)
                {
                    if (item.CategoryId == model.CategoryId)
                    {
                        if (!seasons.Any(x => x.SeasonId == item.SeasonId))
                        {
                            seasons.Add(new ClamSectionTVShowSubCategorySeason()
                            {
                                TVShowId   = item.TVShowId,
                                CategoryId = model.CategoryId,
                                SeasonId   = item.SeasonId,
                            });
                        }
                    }
                }
            }
            if (collectShows.Select(x => x.CategoryId).Where(x => x.Equals(id)).Count() > 0)
            {
                foreach (var item in collectShows)
                {
                    if (item.CategoryId == model.CategoryId)
                    {
                        if (!shows.Any(x => x.TVShowId == item.TVShowId))
                        {
                            shows.Add(new ClamSectionTVShowSubCategory()
                            {
                                TVShowId   = item.TVShowId,
                                CategoryId = model.CategoryId,
                                ItemPath   = item.ItemPath
                            });
                        }
                    }
                }
            }

            var tvShowCompletePath = string.Empty;

            if (!String.IsNullOrEmpty(model.ItemPath))
            {
                tvShowCompletePath = model.ItemPath.Substring(0, FilePathUrlHelper.DataFilePathFilterIndex(
                                                                  model.ItemPath, 4));
            }

            if (shows.Count != 0)
            {
                foreach (var subDirectory in shows)
                {
                    var subPath = subDirectory.ItemPath.Substring(0, FilePathUrlHelper.DataFilePathFilterIndex(
                                                                      subDirectory.ItemPath, 4));
                    if (Directory.Exists(subPath))
                    {
                        Directory.Delete(subPath, true);
                    }
                }
            }

            if (Directory.Exists(tvShowCompletePath))
            {
                Directory.Delete(tvShowCompletePath, true);
            }

            _context.ClamSectionTVShowSubCategorySeasonItems.RemoveRange(seasonItems);
            _context.ClamSectionTVShowSubCategorySeasons.RemoveRange(seasons);
            _context.ClamSectionTVShowSubCategories.RemoveRange(shows);
            if (Directory.Exists(fullDirectoryPath))
            {
                Directory.Delete(fullDirectoryPath, true);
            }
            _context.ClamSectionTVShowCategories.Remove(result);
            await _context.SaveChangesAsync();
        }