public async Task <ActionResult> UnShareDocument(int docId, string userName) { using (IntelliDocsEntities db = new IntelliDocsEntities()) { AspNetUser otherUser = await db.AspNetUsers.Where(usr => usr.UserName == userName).FirstOrDefaultAsync(); if (otherUser == null) { return(Json(new { status = "error", message = "<strong>Error!</strong> The specified Username couldn't be found." })); } List <Share> docShares = await db.Shares.Where(share => share.Document_docId == docId && share.AspNetUsers.Select(usr => usr.UserName).Contains(userName)).ToListAsync(); foreach (Share shr in docShares) { List <AspNetUser> updatedUsers = shr.AspNetUsers.ToList(); updatedUsers.RemoveAll(usr => usr.UserName == userName); shr.AspNetUsers = updatedUsers; db.Entry(shr).State = EntityState.Modified; } try { await db.SaveChangesAsync(); } catch (Exception ex) { return(Json(new { status = "error", message = "<strong>Error!</strong> Failed to modify the Share: " + ex.Message })); } return(Json(new { status = "success", message = "<strong>Success!</strong> This document was un-successfully shared with " + otherUser.UserName + "." })); } }
public ActionResult DeleteDirectory(int id) { using (IntelliDocsEntities db = new IntelliDocsEntities()) { Directory dir = db.Directories.Find(id); if (dir == null) { return(Json(new { status = "error", message = "Couldn't find the specified Directory." })); } if (dir.dirParentId == null) { return(Json(new { status = "error", message = "You can't delete your Root directory." })); } string path = dir.Path; db.Entry(dir).State = EntityState.Deleted; try { db.SaveChanges(); } catch (Exception ex) { return(Json(new { status = "error", message = "Failed to delete folder: " + ex.Message })); } path = Path.Combine(Server.MapPath("~"), path); System.IO.Directory.Delete(path, true); } return(Json(new { status = "success", message = "Folder successfully deleted!" })); }
public ActionResult Delete(int id) { using (IntelliDocsEntities db = new IntelliDocsEntities()) { Document doc = db.Documents.Find(id); string path = doc.Path; db.Entry(doc).State = EntityState.Deleted; try { db.SaveChanges(); } catch (Exception ex) { return(Json(new { status = "error", message = "Failed to delete file: " + ex.Message }, JsonRequestBehavior.AllowGet)); } System.IO.File.Delete(path); } return(Json(new { status = "success", message = "File successfully deleted!" }, JsonRequestBehavior.AllowGet)); }