private void upload_Shared_To_DB(int userID, string email, Guid fileID) { SharedOwnership sharedOwnership = new SharedOwnership(); sharedOwnership.FilesId = fileID; sharedOwnership.UsersId = userID; sharedOwnership.SharedBy = email; _vdContext.Add(sharedOwnership); _vdContext.SaveChanges(); }
public async Task <IActionResult> Remove(Guid?id, [Bind(include: "FileName, Filesize, FileUploadDate, FileType")] File files) { try { var currentUser = await _userManager.GetUserAsync(HttpContext.User); string currentUserEmail = currentUser.Email; var user = await _vdContext.UserDetail.FirstOrDefaultAsync(i => i.UserEmail == currentUserEmail); int userID = user.UserId; var findPath = await _vdContext.File.FirstOrDefaultAsync(c => c.FileId == id); string path = findPath.FileDirectory; SharedOwnership shared = _vdContext.SharedOwnership.Find(userID, id); if (shared != null) { _vdContext.SharedOwnership.Remove(shared); _vdContext.SaveChanges(); deleteFileFromDirectory(path); } var log = await _vdContext.Log.FirstOrDefaultAsync(i => i.LogUploader == currentUserEmail); int logID = log.LogId; Log myLog = _vdContext.Log.Find(logID); if (myLog != null) { _vdContext.Log.Remove(myLog); _vdContext.SaveChanges(); } File myFile = _vdContext.File.Find(id); if (myFile != null) { _vdContext.File.Remove(myFile); _vdContext.SaveChanges(); deleteFileFromDirectory(path); } return(RedirectToAction("MyDocuments")); } catch (Exception e) { errorMsg = "The file could not be deleted \n For Administrator: " + e.ToString(); RedirectToAction("ErrorUploading", new { msg = errorMsg }); } return(View()); }
private async Task upload_Shared_To_DB(int userID, string email, string fileName) { var file_uploaded = await _vdContext.File.FirstOrDefaultAsync(i => i.FileName == fileName); Guid fileID = file_uploaded.FileId; SharedOwnership sharedOwnership = new SharedOwnership(); sharedOwnership.FilesId = fileID; sharedOwnership.UsersId = userID; sharedOwnership.SharedBy = email; _vdContext.Add(sharedOwnership); _vdContext.SaveChanges(); }