Beispiel #1
0
        public async Task <CreateFolderDto> CreateFolders(CreateFolderDto cFolderDto)
        {
            CreateFolderValidator createFolderValidator = new CreateFolderValidator();

            if (!createFolderValidator.Validate(cFolderDto).IsValid)
            {
                throw new Exception("Not Valid... ");
            }
            var path = _fileManager.GetRootPath() + cFolderDto.FolderName;

            if (cFolderDto.FolderParentId == null)
            {
                _fileManager.CreateDirectory(path);
                var folder = _mapper.Map <CreateFolderDto, Entities.Folder>(cFolderDto);
                folder.FolderPath = path;
                _unitOfWork.FoldersRepository.Add(folder);
                await _unitOfWork.CompleteAsync();

                var x = _mapper.Map <Entities.Folder, CreateFolderDto>(folder);
                return(x);
            }
            else
            {
                var pFolder = await _unitOfWork.FoldersRepository.GetById(cFolderDto.FolderParentId);

                path = pFolder.FolderPath + "\\" + cFolderDto.FolderName;
                _fileManager.CreateDirectory(path);
                var folder = _mapper.Map <CreateFolderDto, Entities.Folder>(cFolderDto);
                folder.FolderPath = path;
                _unitOfWork.FoldersRepository.Add(folder);
                await _unitOfWork.CompleteAsync();

                return(_mapper.Map <Entities.Folder, CreateFolderDto>(folder));
            }
        }
Beispiel #2
0
        public async void testUpdateProject()
        {//TODO add all types of projects
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _projectsEnv._stringDict.GetValueOrDefault("token"));
            var folder = new CreateFolderDto
            {
                description = "test",
                name        = "test1",
                icon        = "test3"
            };
            var actualResponseFolder = await client.testSuccessPostAsync <GetFolderDto, CreateFolderDto>("/api/folders", folder);

            var responseTimersGet = await client.testSuccessGetAsync <List <GetTimerDto> >("/api/timers");

            var newTimerId = responseTimersGet.data.FirstOrDefault(x => x.id != _projectsEnv._stringDict.GetValueOrDefault("timerId")).id;

            var project = new CreateProjectDto
            {
                projectType    = PROJECT_TYPE.ENERGY,
                name           = "test10",
                stats          = new STATS[] { STATS.EMOTIONS },
                dominantStat   = STATS.EMOTIONS,
                folderId       = actualResponseFolder.data.id,
                defaultTimerId = newTimerId
            };
            var expectedProject = new GetProjectDto
            {
                name           = project.name,
                stats          = project.stats,
                dominantStat   = project.dominantStat,
                projectType    = project.projectType,
                folderId       = project.folderId,
                defaultTimerId = project.defaultTimerId
            };

            // Act
            var actualResponseProject = await client
                                        .testSuccessPutAsync <GetProjectDto, CreateProjectDto>($"/api/projects/{_projectsEnv._stringDict.GetValueOrDefault("projectId")}", project);

            // Assert
            expectedProject.WithDeepEqual(actualResponseProject.data)
            .SkipDefault <DateTime>()
            .IgnoreSourceProperty(x => x.id)
            .IgnoreDestinationProperty(x => x.dateCreated)
            .Assert();

            // Act
            var actualResponseProjectGet = await client.testSuccessGetAsync <GetProjectDto>("/api/projects/" + actualResponseProject.data.id);

            expectedProject.id = actualResponseProject.data.id;
            // Assert
            expectedProject.WithDeepEqual(actualResponseProjectGet.data)
            .SkipDefault <DateTime>()
            .IgnoreDestinationProperty(x => x.dateCreated)
            .Assert();
        }
Beispiel #3
0
        public async Task <long> CreateFolder(CreateFolderDto model)
        {
            model.ParentFolderId = model.FolderType == FolderType.Public ? (long)FolderType.Public : model.ParentFolderId;
            var folderId = await ExecuteScalarAsync <long>($"insert into folders(tenant_id,folder_name,parent_folder_id) values ({GET_TENANT_QUERY},@Name,@ParentFolderId) returning id", model);

            await ExecuteActionAsync($"insert into user_folders_permissions(tenant_id,user_id,folder_id,permission_id) values ({GET_TENANT_QUERY},{model.UserId},{folderId},{(int) FolderPermissionType.ViewFolders})");

            return(folderId);
        }
Beispiel #4
0
        public async Task CreateFolderWithNotExistingUser()
        {
            var dto = new CreateFolderDto
            {
                Name   = "aa",
                UserId = "a"
            };

            Assert.ThrowsAsync <NotFoundException>(async() => await _folderService.CreateFolder(dto));
        }
Beispiel #5
0
        public async Task CreateValidFolder()
        {
            var dto = new CreateFolderDto
            {
                Name   = "Directory",
                UserId = UserHelper.UserModel.Id
            };

            var result = await _folderService.CreateFolder(dto);

            Assert.IsNotEmpty(result.Id);
            Assert.AreEqual(UserHelper.UserModel.Id, result.UserId);
        }
Beispiel #6
0
        public async Task <Contract.Models.Folder> CreateFolder(CreateFolderDto createFolderDto)
        {
            ValidationHelper.ValidateAndThrow(createFolderDto);
            await CheckExistingUser(createFolderDto.UserId);

            var model = new Contract.Models.Folder
            {
                Id     = Guid.NewGuid().ToString(),
                Name   = createFolderDto.Name,
                UserId = createFolderDto.UserId
            };

            await InitializeFolder(model);


            return(await _folderWriteOperations.Create(model));
        }
Beispiel #7
0
        public async Task <IActionResult> Create(CreateFolderDto dto)
        {
            try
            {
                var user = await _userService.GetCurrentUser(User.Identity?.Name);

                dto.UserId = user.Id;
                var result = await _folderService.CreateFolder(dto);

                return(Redirect("/Folder/Folders/" + result.Id));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(dto));
            }
        }
        public ActionResult <FolderDto> CreateFolderInFolder([FromBody] CreateFolderDto createFolderDto)
        {
            FolderDto response = null;

            try
            {
                if (!string.IsNullOrEmpty(createFolderDto.IdFolderDto))
                {
                    response = _iDriveService.CreateFolderInFolder(createFolderDto.NameDto, createFolderDto.IdFolderDto);
                }
                else
                {
                    response = _iDriveService.CreateFolder(createFolderDto.NameDto, createFolderDto.DescriptionDto);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.StackTrace);
            }
            return(Ok(response));
        }
Beispiel #9
0
        public async void testAddFolder()
        {
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _projectsEnv._stringDict.GetValueOrDefault("token"));
            var folder = new CreateFolderDto
            {
                description = "test",
                name        = "test1",
                icon        = "test3"
            };
            var expectedFolder = new GetFolderDto
            {
                description = folder.description,
                icon        = folder.icon,
                name        = folder.name,
                userId      = _projectsEnv._parsedToken.Claims.FirstOrDefault(claim => claim.Type == "nameid").Value
            };

            // Act
            var actualResponseFolder = await client.testSuccessPostAsync <GetFolderDto, CreateFolderDto>("/api/folders", folder);

            // Assert
            expectedFolder.WithDeepEqual(actualResponseFolder.data)
            .SkipDefault <DateTime>()
            .IgnoreSourceProperty(x => x.id)
            .IgnoreDestinationProperty(x => x.dateCreated)
            .Assert();

            // Act
            var actualResponseFolderGet = await client.testSuccessGetAsync <GetFolderDto>("/api/folders/" + actualResponseFolder.data.id);

            expectedFolder.id = actualResponseFolder.data.id;
            // Assert
            expectedFolder.WithDeepEqual(actualResponseFolderGet.data)
            .SkipDefault <DateTime>()
            .IgnoreDestinationProperty(x => x.dateCreated)
            .Assert();
            _projectsEnv._stringDict.Add("folderId", actualResponseFolder.data.id);
        }
        public async Task <Contract.Models.Folder> CreateFolder(CreateFolderDto createFolderDto)
        {
            ValidationHelper.ValidateAndThrow(createFolderDto);
            await CheckExistingUser(createFolderDto.UserId);

            var statuseIds = new List <string>();

            for (int i = 0; i < 4; i++)
            {
                statuseIds.Add(Guid.NewGuid().ToString());
            }
            var model = new Contract.Models.Folder
            {
                Id            = Guid.NewGuid().ToString(),
                Name          = createFolderDto.Name,
                UserId        = createFolderDto.UserId,
                StatusesOrder = statuseIds
            };

            await InitializeFolder(model);


            return(await _folderWriteOperations.Create(model));
        }
Beispiel #11
0
        public async Task <ActionResult <ControllerResponse <GetFolderDto> > > create(CreateFolderDto createFolder)
        {
            string userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier).ToString();
            var    folder = _mapper.Map <Folder>(createFolder);

            folder.userId      = userId;
            folder.dateCreated = DateTime.UtcNow;
            await _folderService.createAsync(folder);

            return(Created(new Uri($"{Request.Path}/{folder.id}", UriKind.Relative), new ControllerResponse <GetFolderDto>
            {
                data = _mapper.Map <GetFolderDto>(folder)
            }));
        }
Beispiel #12
0
        public async Task CreateInvalidFolder()
        {
            var dto = new CreateFolderDto();

            Assert.ThrowsAsync <ValidationException>(async() => await _folderService.CreateFolder(dto));
        }
 public async Task <IActionResult> CreateFolders([FromBody] CreateFolderDto cFolderDto) => Ok(await _folderService.CreateFolders(cFolderDto));