예제 #1
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));
        }