public async Task <IActionResult> DeleteFile(Guid id, Guid said, string category, string section) { var requestFile = _context.ClamSectionAcademicSubCategoryItems.SingleOrDefault(m => m.ItemId == id); if (string.IsNullOrEmpty(id.ToString())) { ModelState.AddModelError("File", $"The request couldn't be processed (Error 1)."); // Log error return(BadRequest(ModelState)); } if (requestFile == null) { ModelState.AddModelError("File", $"The request couldn't be processed (Error 2)."); // Log error return(BadRequest(ModelState)); } //var proc = _context.ClamSectionAcademicSubCategoryItems.SingleOrDefault(m => m.ItemId == id); //var aid = proc.AcademicId; //var said = proc.SubCategoryId; int index = requestFile.ItemPath.LastIndexOf(@"\"); System.IO.File.Delete(requestFile.ItemPath); Directory.Delete(requestFile.ItemPath.Substring(0, index)); var model = _context.Set <ClamSectionAcademicSubCategoryItem>().Find(id); _context.Set <ClamSectionAcademicSubCategoryItem>().Remove(model); await _context.SaveChangesAsync(); return(RedirectToAction("Episode", "Academia", new { Id = id, Said = said, Category = category, Section = section })); }
public async Task <IActionResult> Create(StreamFileUploadDatabase model) { // Perform an initial check to catch FileUpload class // attribute violations. if (!ModelState.IsValid) { _uploadContent.Result = "Please correct the form."; return(View()); } var formFileContent = await FileHelpers.ProcessFormFile <StreamFileUploadDatabase>( model.FormFile, ModelState, _permittedExtentions, _fileSizeLimit); // Perform a second check to catch ProcessFormFile method // violations. If any validation check fails, return to the // page. if (!ModelState.IsValid) { _uploadContent.Result = "Please correct the form."; return(View()); } // **WARNING!** // In the following example, the file is saved without // scanning the file's contents. In most production // scenarios, an anti-virus/anti-malware scanner API // is used on the file before making the file available // for download or for use by other systems. // For more information, see the topic that accompanies // this sample. var file = new ClamSectionAcademicSubCategoryItem { ItemPath = null, ItemTitle = model.FormFile.FileName, ItemDescription = model.Note, Size = model.FormFile.Length, SubCategoryId = new Guid("8d7af8fa-4659-4aef-1746-08d7d7789232") //AcademicId = new Guid("a7e95d01-3a1c-474c-d5ab-08d7d76073f2") }; _context.Set <ClamSectionAcademicSubCategoryItem>().Add(file); //_context.Entry(file).State = EntityState.Modified; _context.SaveChanges(); //await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public void SaveAccount(Guid id, UserAccountRegister entity) { var model = _mapper.Map <ClamDataLibrary.Models.ClamUserAccountRegister>(entity); Context.Set <ClamDataLibrary.Models.ClamUserAccountRegister>().Update(model); Context.SaveChanges(); }
public async Task AddTVShowSeason(Guid id, SectionTVShowSubCategorySeason model) { var showImagePath = _context.ClamSectionTVShowSubCategories.Find(model.TVShowId); ClamSectionTVShowSubCategorySeason result = new ClamSectionTVShowSubCategorySeason { CategoryId = id, TVShowId = model.TVShowId, ItemPath = showImagePath.ItemPath, TVShowSeasonNumber = model.TVShowSeasonNumber }; await _context.Set <ClamSectionTVShowSubCategorySeason>().AddAsync(result); Task.WaitAll(_context.SaveChangesAsync()); }
public void Add(TEntity entity) { _context.Set <TEntity>().Add(entity); }