コード例 #1
0
        public async Task <IActionResult> UpdateFolder(int id, [FromBody] FolderMeta folderMeta)
        {
            var result = await _folderService.Update(CurrentUser.TenantId, CurrentUser.Id, CurrentUser.FullName, id, folderMeta);

            if (result.Code <= 0)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
コード例 #2
0
        public async Task <ActionResultReponese <string> > InsertAsync(string FolderName, int folderId, FolderMeta folderMeta)
        {
            var isFolderID = await _iFolderRepository.CheckExitsFolder(folderId);

            if (isFolderID)
            {
                return(new ActionResultReponese <string>(-21, "FolderId already exists", "Folder", null));
            }
            var folder = new Folder()
            {
                FolderId    = folderId,
                FolderName  = FolderName,
                NamePath    = folderMeta.NamePath?.Trim(),
                Level       = folderMeta.Level,
                ChildCount  = folderMeta.ChildCount,
                Description = folderMeta.Description?.Trim(),
                CreateTime  = DateTime.Now,
                DeleteTime  = null,
                LastUpdate  = null,
                IsActive    = true,
                IsDelete    = false,
            };
            var result = await _iFolderRepository.InsertAsync(FolderName, folderId, folder);

            if (result <= 0)
            {
                return(new ActionResultReponese <string>(-1, "Insert False", "Folder", null));
            }
            return(new ActionResultReponese <string>(result, "Insert Success", "Folder", null));
        }
コード例 #3
0
        public async Task <ActionResultResponse <Folder> > Insert(string tenantId, string creatorId, string creatorFullName, FolderMeta folderMeta)
        {
            var folder = new Folder
            {
                IdPath = "-1",
                //Order = folderMeta.Order,
                TenantId = tenantId,
                //OrderPath = folderMeta.Order.ToString(),
                CreatorId       = creatorId,
                CreatorFullName = creatorFullName,
                Name            = folderMeta.Name,
                UnsignName      = folderMeta.Name.Trim().StripVietnameseChars().ToUpper()
            };

            if (await _folderRepository.CheckName(tenantId, folder.UnsignName))
            {
                return(new ActionResultResponse <Folder>(-2,
                                                         _fileManagermentResourceResource.GetString("This folder does exists. Please try again.")));
            }

            if (folderMeta.ParentId.HasValue)
            {
                var parentInfo = await _folderRepository.GetInfo(tenantId, creatorId, folderMeta.ParentId.Value);

                if (parentInfo == null)
                {
                    return(new ActionResultResponse <Folder>(-2,
                                                             _fileManagermentResourceResource.GetString("Parent folder does not exists. Please try again.")));
                }

                folder.ParentId = parentInfo.Id;
                folder.IdPath   = $"{parentInfo.IdPath}.-1";
            }

            var result = await _folderRepository.Insert(folder);

            if (result <= 0)
            {
                return(new ActionResultResponse <Folder>(result, _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong)));
            }

            folder.IdPath = folder.IdPath.Replace("-1", folder.Id.ToString());
            await _folderRepository.UpdateFolderIdPath(folder.Id, folder.IdPath);

            return(new ActionResultResponse <Folder>(result, _fileManagermentResourceResource.GetString("Add new folder successful."),
                                                     string.Empty, folder));
        }
コード例 #4
0
        public async Task <ActionResultResponse> Update(string tenantId,
                                                        string lastUpdateUserId, string lastUpdateFullName, int folderId, FolderMeta folderMeta)
        {
            var folderInfo = await _folderRepository.GetInfo(tenantId, lastUpdateUserId, folderId);

            if (folderInfo == null)
            {
                return(new ActionResultResponse(-2, _fileManagermentResourceResource.GetString("Folder info does not exists. Please try again.")));
            }

            if (folderInfo.TenantId != tenantId)
            {
                return(new ActionResultResponse(-3, _sharedResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            if (folderInfo.ConcurrencyStamp != folderMeta.ConcurrencyStamp)
            {
                return(new ActionResultResponse(-4,
                                                _sharedResourceService.GetString("The folder already updated by other people. You can not update this folder.")));
            }

            if (folderMeta.ParentId.HasValue && folderInfo.Id == folderMeta.ParentId.Value)
            {
                return(new ActionResultResponse(-5, _fileManagermentResourceResource.GetString("Folder and parent folder can not be the same.")));
            }
            ;

            var oldParentId = folderInfo.ParentId;
            var oldIdPath   = folderInfo.IdPath;

            folderInfo.Name = folderMeta.Name;
            //folderInfo.Order = folderMeta.Order;
            folderInfo.ConcurrencyStamp   = Guid.NewGuid().ToString();
            folderInfo.LastUpdate         = DateTime.Now;
            folderInfo.LastUpdateUserId   = lastUpdateUserId;
            folderInfo.LastUpdateFullName = lastUpdateFullName;
            folderInfo.UnsignName         = folderMeta.Name.Trim().StripVietnameseChars().ToUpper();

            if (await _folderRepository.CheckName(tenantId, folderInfo.UnsignName))
            {
                return(new ActionResultResponse <Folder>(-2,
                                                         _fileManagermentResourceResource.GetString("This folder does exists. Please try again.")));
            }

            if (folderInfo.ParentId.HasValue && !folderMeta.ParentId.HasValue)
            {
                folderInfo.ParentId = null;
                folderInfo.IdPath   = folderInfo.Id.ToString();
                //folderInfo.OrderPath = folderInfo.Order.ToString();
            }
            else if (folderMeta.ParentId.HasValue && folderMeta.ParentId != folderInfo.ParentId)
            {
                var parentInfo = await _folderRepository.GetInfo(tenantId, lastUpdateUserId, folderMeta.ParentId.Value);

                if (parentInfo == null)
                {
                    return(new ActionResultResponse(-6, _fileManagermentResourceResource.GetString("Parent folder does not exists. Please try again.")));
                }
                ;

                parentInfo.IdPath   = $"{parentInfo.IdPath}.{parentInfo.Id}";
                parentInfo.ParentId = parentInfo.Id;
                //parentInfo.OrderPath = $"{parentInfo.OrderPath}.{parentInfo.Order}";
            }

            await _folderRepository.Update(folderInfo);

            // Update children IdPath and RootInfo
            if (folderInfo.IdPath != oldIdPath)
            {
                await _folderRepository.UpdateChildrenIdPath(oldIdPath, folderInfo.IdPath);
            }

            // Update parent survey group child count.
            if (folderInfo.ParentId.HasValue && oldParentId.HasValue && folderInfo.ParentId.Value != oldParentId.Value)
            {
                // Update old parent survey group child count.
                var oldChildCount = await _folderRepository.GetChildCount(oldParentId.Value);

                await _folderRepository.UpdateChildCount(tenantId, lastUpdateUserId, oldParentId.Value, oldChildCount);

                // Update new parent survey group child count.
                var newParentId   = folderInfo.ParentId.Value;
                var newChildCount = await _folderRepository.GetChildCount(newParentId);

                await _folderRepository.UpdateChildCount(tenantId, lastUpdateUserId, newParentId, newChildCount);
            }

            //update lai folder child by Id
            var childCountid = await _folderRepository.GetChildCount(folderInfo.Id);

            await _folderRepository.UpdateChildCount(tenantId, lastUpdateUserId, folderInfo.Id, childCountid);

            //// Update survey group name translation in survey translation.
            //if (surveyGroupMeta.SurveyGroupTranslations.Any())
            //    await UpdateSurveyTranslations();

            return(new ActionResultResponse(1,
                                            _fileManagermentResourceResource.GetString("Update folder name successful.")));
        }
コード例 #5
0
        public async Task <IActionResult> InsertAsync(string IdPath, string FolderName, int FolderId, [FromBody] FolderMeta folderMeta)
        {
            var result = await _folderService.InsertAsync(IdPath, FolderName, FolderId, folderMeta);

            if (result.Code <= 0)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }