public async Task RemoveMultipleEpisodes(SectionTVShowSubCategory model) { var collectEpisodes = _context.ClamSectionTVShowSubCategorySeasonItems.AsNoTracking().ToList(); //List<ClamSectionTVShowSubCategorySeason> seasons = new List<ClamSectionTVShowSubCategorySeason>(); List <ClamSectionTVShowSubCategorySeasonItem> seasonItems = new List <ClamSectionTVShowSubCategorySeasonItem>(); foreach (var item in collectEpisodes) { if (item.TVShowId == model.TVShowId && item.CategoryId == model.CategoryId) { seasonItems.Add(new ClamSectionTVShowSubCategorySeasonItem() { ItemId = item.ItemId, CategoryId = model.CategoryId, TVShowId = model.TVShowId, SeasonId = item.SeasonId }); } } if (seasonItems.Count != 0) { _context.ClamSectionTVShowSubCategorySeasonItems.RemoveRange(seasonItems); await _context.SaveChangesAsync(); } }
public async Task RemoveTVShow(Guid id, SectionTVShowSubCategory model) { var fullDirectoryPath = string.Empty; fullDirectoryPath = string.Format("{0}\\{1}\\{2}", _targetFolderPath, model.CategoryId.ToString(), model.TVShowId.ToString()); // TODO: Add delete logic here var result = await _context.ClamSectionTVShowSubCategories.AsNoTracking() .FirstOrDefaultAsync(x => x.TVShowId == id); var tvShowCompletePath = string.Empty; if (!String.IsNullOrEmpty(model.ItemPath)) { tvShowCompletePath = model.ItemPath.Substring(0, FilePathUrlHelper.DataFilePathFilterIndex( model.ItemPath, 4)); } if (Directory.Exists(tvShowCompletePath)) { Directory.Delete(tvShowCompletePath, true); } if (Directory.Exists(fullDirectoryPath)) { Directory.Delete(fullDirectoryPath, true); } await RemoveMultipleEpisodes(model); await RemoveMultipleSeasons(model); _context.ClamSectionTVShowSubCategories.Remove(result); await _context.SaveChangesAsync(); }
public async Task AddTVShow(Guid id, SectionTVShowSubCategory 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); } var filterSeasons = _context.ClamSectionTVShowSubCategorySeasons.ToList(); ClamSectionTVShowSubCategory test = new ClamSectionTVShowSubCategory { CategoryId = id, TVShowTitle = model.TVShowTitle, ItemPath = Path.Combine(trustedFilePathForStorage, trustedFileNameForDisplay), TVShowSeasonNumberTotal = filterSeasons.Select(x => x.TVShowId).Where(x => x.Equals(id)).Count() }; await _context.ClamSectionTVShowSubCategories.AddAsync(test); Task.WaitAll(_context.SaveChangesAsync()); }
public async Task <IActionResult> DeleteTVShow(Guid id, SectionTVShowSubCategory entity, string category, string section) { try { await _unitOfWork.TVShowControl.RemoveTVShow(id, entity); _unitOfWork.Complete(); return(RedirectToAction(nameof(TVShows), new { Id = entity.CategoryId, Category = category })); } catch (Exception) { throw; } }
public async Task <IActionResult> EditTVShow(Guid id, SectionTVShowSubCategory entity, string category, string section) { try { var model = await _unitOfWork.TVShowControl.GetTVShow(id); await _unitOfWork.TVShowControl.UpdateTVShow(id, entity); return(RedirectToAction(nameof(TVShows), new { id = entity.CategoryId, Category = category })); } catch (Exception) { throw; } }
public async Task RemoveMultipleSeasons(SectionTVShowSubCategory model) { var collectSeasons = _context.ClamSectionTVShowSubCategorySeasons.AsNoTracking().ToList(); List <ClamSectionTVShowSubCategorySeason> seasons = new List <ClamSectionTVShowSubCategorySeason>(); foreach (var season in collectSeasons) { if (season.CategoryId == model.CategoryId && season.TVShowId == model.TVShowId) { seasons.Add(new ClamSectionTVShowSubCategorySeason() { TVShowId = season.TVShowId, CategoryId = season.CategoryId, SeasonId = season.SeasonId }); } } if (seasons.Count != 0) { _context.ClamSectionTVShowSubCategorySeasons.RemoveRange(seasons); await _context.SaveChangesAsync(); } }
public async Task <SectionTVShowSubCategory> GetTVShow(Guid id) { var filterSeasons = await _context.ClamSectionTVShowSubCategorySeasons.ToListAsync(); var filterSeasonEpisodes = await _context.ClamSectionTVShowSubCategorySeasonItems.ToListAsync(); var model = await _context.ClamSectionTVShowSubCategories.FindAsync(id); SectionTVShowSubCategory retrieveModel = new SectionTVShowSubCategory() { TVShowId = model.TVShowId, TVShowTitle = model.TVShowTitle, TVShowSeasonNumberTotal = model.TVShowSeasonNumberTotal, ItemPath = model.ItemPath, LastModified = model.LastModified, DateCreated = model.DateCreated, CategoryId = model.CategoryId, SubCategorySeasonCount = filterSeasons.Select(x => x.TVShowId).Where(x => x.Equals(id)).Count(), SubCategorySeasonItemCount = filterSeasonEpisodes.Select(x => x.TVShowId).Where(x => x.Equals(id)).Count() }; return(retrieveModel); }
public async Task UpdateTVShow(Guid id, SectionTVShowSubCategory 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 } if (model.FormFile != null) { 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 = await _context.ClamSectionTVShowSubCategories.FindAsync(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); } var entity = _context.Set <ClamSectionTVShowSubCategory>().Find(id); _context.Entry(entity).Entity.TVShowTitle = model.TVShowTitle; _context.Entry(entity).Entity.TVShowSeasonNumberTotal = model.TVShowSeasonNumberTotal; _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()); }