public ServiceResult Delete(FileDeleteModel model) { var resultData = new ServiceResult(); try { if (!ModelState.IsValid) { resultData.Code = MISSING_REQUIRED_FIELDS; foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage))) { resultData.Message += error + Environment.NewLine; } return(resultData); } new FileComponent().Delete(model.Id); resultData.Success(); } catch (Exception ex) { resultData.SystemError(ex); } return(resultData); }
public ActionResult DeleteFile(int id) { Tbl_Files q = db.Tbl_Files.Where(a => a.File_ID == id).SingleOrDefault(); FileDeleteModel model = new FileDeleteModel(); model.ID = q.File_ID; model.Key = q.File_DownloadKey; model.name = q.File_Name; return(View(model)); }
public IHttpActionResult FileDelete(FileDeleteModel fileDeleteModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_fileService.DeleteFile(fileDeleteModel.FileUrl)) { return(NotFound()); } else { return(Ok()); } }
public ActionResult DeleteFile(FileDeleteModel model) { Tbl_Files q = db.Tbl_Files.Where(a => a.File_DownloadKey == model.Key).SingleOrDefault(); if (q != null) { Tbl_BookDetails _BookDetails = db.Tbl_Book.Where(a => a.Book_ID == q.File_BookID).SingleOrDefault().Tbl_BookDetails; if (_BookDetails.BD_FileCount > 1) { _BookDetails.BD_FileCount--; } else { _BookDetails.BD_FileCount = null; } int book_id = q.File_BookID; string path = Path.Combine(Server.MapPath("~/App_Data/Upload/"), q.File_Path); string root = Path.Combine(Server.MapPath("~/App_Data/Upload/"), q.File_FolderName.ToString()); db.Tbl_Files.Remove(q); db.Entry(_BookDetails).State = System.Data.Entity.EntityState.Modified; if (Convert.ToBoolean(db.SaveChanges() > 0)) { FileManagement file = new FileManagement(); file.DeleteFileWithPath(path); file.Dir_Empty(root); return(RedirectToAction("BookShow", "Book", new { id = book_id })); } else { return(null); } } else { return(null); } }