Exemplo n.º 1
0
        public ServiceResult <object> CreateFolder(FolderDto dto)
        {
            var userInfo    = _userSessionManager.GetUserInfo(dto.Ticket, Request);
            var bp          = new BusinessParam(userInfo, _hostEnvironment);
            var checkAccess = _userSessionManager.CheckAccess(bp, ClassDetails[0].Clazz, "insert");

            return(checkAccess.Done
                ? FileFacade.GetInstance().CreateFolder(bp, dto)
                : checkAccess);
        }
Exemplo n.º 2
0
        public ServiceResult <object> CreateFolder(BusinessParam bp, FolderDto dto)
        {
            var methodName = $".{new StackTrace().GetFrame(1).GetMethod().Name}";

            try
            {
                if (string.IsNullOrEmpty(dto.FolderName))
                {
                    return(ExceptionUtil.ExceptionHandler("لطفا نام پوشه را وارد نمایید",
                                                          ClassDetails[0].Facade + methodName,
                                                          bp.UserInfo));
                }
                long?parentId    = null;
                var  webRootPath = bp.Environment.WebRootPath;
                var  fileName    = "\\file\\" + DateTime.UtcNow.RepositoryFolderName();
                if (!string.IsNullOrEmpty(dto.Path))
                {
                    parentId = dto.ParentId;
                    fileName = dto.Path + DateTime.UtcNow.RepositoryFolderName();
                }

                var exists = Directory.Exists(webRootPath + fileName);
                if (exists)
                {
                    return(ExceptionUtil.ExceptionHandler("نام پوشه تکراری می باشد",
                                                          ClassDetails[0].Facade + methodName,
                                                          bp.UserInfo));
                }
                Directory.CreateDirectory(webRootPath + fileName);
                var fileDto = new FileDto
                {
                    Alt                  = "",
                    DataSize             = "0",
                    Description          = "",
                    DisplayInFileManager = true,
                    Extension            = null,
                    FullTitle            = fileName + " | " + dto.FolderName,
                    Name                 = dto.FolderName,
                    ParentId             = parentId,
                    Path                 = fileName + "\\",
                    Thumbnail            = fileName + "\\",
                    Title                = dto.FolderName
                };
                var file = Copier.GetEntity(fileDto, bp, true);
                using (var unitOfWork = new UnitOfWork())
                {
                    var done = unitOfWork.File.Insert(file);
                    unitOfWork.File.Save();
                    if (!done)
                    {
                        return(ExceptionUtil.ExceptionHandler("خطا در ذخیره فایل درون دیتابیس",
                                                              ClassDetails[0].Facade + methodName,
                                                              bp.UserInfo));
                    }
                    Elastic <FileDto, DataLayer.Model.Core.File.File> .SaveToElastic(file, ClassDetails[0].Clazz, bp);

                    fileDto.EntityId = file.EntityId;
                    return(new ServiceResult <object>(fileDto, 1));
                }
            }
            catch (Exception e)
            {
                return(ExceptionUtil.ExceptionHandler(e, ClassDetails[0].Facade + methodName, bp.UserInfo));
            }
        }