public async void add([FromBody] AddFolderRequest request) { using (var dbContext = new PulseDbContext()) { var account = await dbContext.Accounts .Include(a => a.Devices) .Include(a => a.Folders) .Where(a => a.AccountId == request.AccountId) .FirstOrDefaultAsync(); if (account == null) { return; } foreach (var folder in request.Folders) { dbContext.Folders.Add(folder); account.Folders.Add(folder); //await FirebaseHelper.SendMessage(account, "added_folder", folder); } await dbContext.SaveChangesAsync(); } }
public ActionResult <AddFolderResponse> AddFolder([FromBody] AddFolderRequest request) { try { var userId = Int32.Parse(User.Identity.Name); _userManagementService.CheckUserExists(userId); int folderId = _contentManagementService.AddFolder(request.FolderName, request.ParentFolderId, userId); return(Ok(new AddFolderResponse() { FolderId = folderId, })); } catch (UserNotExistError) { return(StatusCode(StatusCodes.Status404NotFound, new { message = "Пользователь не найден" })); } catch (ContentNotExistError) { return(StatusCode(StatusCodes.Status404NotFound, new { message = "Родительская папка не существует" })); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message })); } }
public async Task <Register> AddFolder(int userId, int?parentFolder, AddFolderRequest request) { string relativeFolderPath; if (parentFolder.HasValue) { var folder = await _context.Register.Where( register => register.Id == parentFolder.Value && register.Author == userId).AsNoTracking().FirstOrDefaultAsync(); if (folder == null) { return(null); } relativeFolderPath = await _userFilesService.CreateFolder( folderName : request.Name, relativeParentFolderPath : folder.PathOrUrl, parentFolderId : folder.Id ); } else { // IMPORTANT: When the parentFolder is null, the relativeParentFolderPath will be the user id // and the parentFolderId (only for the relativeFilePath) will be 0. // For example: If the user id is 5, the new folder's path will be "5/0-newFolder/" relativeFolderPath = await _userFilesService.CreateFolder( folderName : request.Name, relativeParentFolderPath : userId.ToString(), parentFolderId : 0 ); } if (relativeFolderPath == null) { return(null); } var folderToAdd = _context.Register.Add(new Register { Name = request.Name, PathOrUrl = relativeFolderPath, UploadDate = DateTime.Now, LastModifiedDate = DateTime.Now, IsFolder = true, ParentFolder = parentFolder, Author = userId, }); var entriesWritten = await _context.SaveChangesAsync(); if (entriesWritten > 0) { return(folderToAdd.Entity); } return(null); }
public ActionResult AddFolder() { AddFolderRequest request = ApiRequestBase.ParseRequest <AddFolderRequest>(this); if (!request.Validate(out Project p, out ApiResponseBase error)) { return(Json(error)); } using (DB db = new DB(p.Name)) { if (db.AddFolder(request.folderName, request.parentFolderId, out string errorMessage, out Folder newFolder)) { return(Json(new ApiResponseBase(true))); }
/// <summary> /// Creates a new folder in Percussion and obtains the detailed /// PSFolder object. /// </summary> /// <param name="folderPath">Path of the folder to be created.</param> /// <param name="navonAction">Action to perform on the folder's Navon.</param> /// <returns>PSFolder object detailing the new folder.</returns> private PSFolder CreateNewFolder(string folderPath, NavonAction navonAction) { int splitPoint = folderPath.LastIndexOfAny(new char[] { '/', '\\' }); string parentFolder = folderPath.Substring(0, splitPoint); string newFolderName = folderPath.Substring(splitPoint + 1); // Force the parent path to exist if it doesn't already. // This seems scary because GuaranteeFolder() establishes a lock which would need // to be released before execution could continue. So what happens when another // thread has a lock inside GuaranteeFolder()? Doesn't that create a deadlock // since the other thread is waiting for us to finish and we're waiting for the // other thread? // // It turns out the lock is smart and only applies to *other* threads. // When the current execution encounters the lock, it's able to continue. // Ref: ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_csref/html/656da1a4-707e-4ef6-9c6e-6d13b646af42.htm GuaranteeFolder(parentFolder, navonAction); AddFolderRequest req = new AddFolderRequest(); req.Path = parentFolder; req.Name = newFolderName; AddFolderResponse resp = _contentService.AddFolder(req); // Folder is newly created, update Navon switch (navonAction) { // FUTURE. //case NavonAction.Suppress: // break; case NavonAction.MakePublic: MakeNavonPublic(folderPath); break; case NavonAction.None: default: break; } return(resp.PSFolder); }
public async Task <IActionResult> AddFolder([FromBody] AddFolderRequest request) { var userIdString = JWTUtility.GetUserId(User); if (userIdString == null) { return(BadRequest()); } var userId = int.Parse(userIdString); if (request.ParentFolder != null) { // Check if the parent folder does belong to the user if (!await _registerService.DoesFolderBelongToUser( userId, folderId: request.ParentFolder.Value)) { return(BadRequest()); } } // Check if the folder name is valid if (!FileNameUtility.FileFolderNameIsValid(request.Name)) { return(BadRequest(Texts.INVALID_FILE_NAME)); } // Check if the folder does not exist if (await _registerService.DoesFileOrFolderAlreadyExist(userId, name: request.Name, parentFolder: request.ParentFolder)) { return(BadRequest(Texts.FILE_FOLDER_ALREADY_EXISTS)); } var folderAdded = await _registerService.AddFolder(userId, parentFolder : request.ParentFolder, request); if (folderAdded == null) { return(StatusCode(statusCode: 500, value: Texts.ERROR_CREATING_FOLDER)); } return(Ok(folderAdded)); }