public object PersistFolder(PersistFolderRequest request) { // Variables. var result = default(object); // Catch all errors. try { // Parse or create the folder ID. var folderId = string.IsNullOrWhiteSpace(request.FolderId) ? Guid.NewGuid() : GuidHelper.GetGuid(request.FolderId); // Get path. var parentId = GuidHelper.GetGuid(request.ParentId); var parent = Entities.Retrieve(parentId); var path = parent.Path .Concat(new[] { folderId }).ToArray(); // Create the folder. var folder = new Folder() { Id = folderId, Path = path, Name = request.FolderName }; // Persist the folder. Persistence.Persist(folder); // Success. result = new { Success = true, FolderId = GuidHelper.GetString(folderId), Path = path.Select(x => GuidHelper.GetString(x)) .ToArray() }; } catch (Exception ex) { // Error. LogHelper.Error <FoldersController>(PersistFolderError, ex); result = new { Success = false, Reason = UnhandledError }; } // Return the result. return(result); }
public object PersistFolder(PersistFolderRequest request) { // Variables. var result = default(object); var folderId = Guid.NewGuid(); // Catch all errors. try { // Get path. var parentId = GuidHelper.GetGuid(request.ParentId); var parent = Entities.Retrieve(parentId); var path = parent.Path.Concat(new[] { folderId }).ToArray(); // Create the folder. var folder = new Folder() { Id = folderId, Path = path, Name = request.FolderName }; // Persist the folder. Persistence.Persist(folder); // Success. result = new { Success = true, FolderId = GuidHelper.GetString(folderId), Path = path.Select(x => GuidHelper.GetString(x)) .ToArray() }; } catch (Exception ex) { // Error. LogHelper.Error<FoldersController>(CreateFolderError, ex); result = new { Success = false, Reason = UnhandledError }; } // Return the result. return result; }