コード例 #1
0
ファイル: FileService.cs プロジェクト: Seko47/DataDrive
        public async Task <StatusCode <DirectoryOut> > CreateDirectoryByUser(DirectoryPost directoryPost, string username)
        {
            string userId = (await _databaseContext.Users.FirstOrDefaultAsync(_ => _.UserName == username))?.Id;

            if (directoryPost.ParentDirectoryID != null && !_databaseContext.Directories.AnyAsync(_ => _.OwnerID == userId && _.ID == directoryPost.ParentDirectoryID).Result)
            {
                return(new StatusCode <DirectoryOut>(StatusCodes.Status404NotFound, StatusMessages.PARENT_DIRECTORY_NOT_FOUND));
            }

            string nameForNewDirectory = directoryPost.Name;

            Directory newDirectory = new Directory
            {
                CreatedDateTime   = DateTime.Now,
                ResourceType      = ResourceType.DIRECTORY,
                Name              = nameForNewDirectory,
                OwnerID           = userId,
                ParentDirectoryID = directoryPost.ParentDirectoryID
            };

            await _databaseContext.Directories.AddAsync(newDirectory);

            await _databaseContext.SaveChangesAsync();

            DirectoryOut result = _mapper.Map <DirectoryOut>(newDirectory);

            return(new StatusCode <DirectoryOut>(StatusCodes.Status201Created, result));
        }
コード例 #2
0
ファイル: FileServiceTest.cs プロジェクト: Seko47/DataDrive
        public async void Returns_Status201Created_when_Created()
        {
            IDatabaseContext    databaseContext     = DatabaseTestHelper.GetContext();
            MapperConfiguration mapperConfiguration = new MapperConfiguration(conf =>
            {
                conf.AddProfile(new Directory_to_DirectoryOut());
            });

            IMapper mapper = mapperConfiguration.CreateMapper();

            IFileService fileService = new FileService(databaseContext, mapper);

            DirectoryPost directoryPost = new DirectoryPost
            {
                ParentDirectoryID = null,
                Name = "TestDirectory"
            };

            StatusCode <DirectoryOut> result = await fileService.CreateDirectoryByUser(directoryPost, "*****@*****.**");

            var a = databaseContext.Users.ToList();

            Assert.NotNull(result);
            Assert.True(result.Code == StatusCodes.Status201Created);
            Assert.True(result.Body.ParentDirectoryID == directoryPost.ParentDirectoryID);
            Assert.True(result.Body.Name == directoryPost.Name);
            Assert.True(databaseContext.Directories.Any(_ => _.ID == result.Body.ID));
        }
コード例 #3
0
ファイル: FilesController.cs プロジェクト: Seko47/DataDrive
        public async Task <IActionResult> CreateDirectory([FromBody] DirectoryPost directoryPost)
        {
            StatusCode <DirectoryOut> result = await _fileService.CreateDirectoryByUser(directoryPost, _userManager.GetUserName(User));

            if (result.Code == StatusCodes.Status404NotFound)
            {
                return(NotFound($"Directory {directoryPost.ParentDirectoryID} not exist"));
            }

            return(CreatedAtAction(nameof(GetFromDirectory), result.Body.ID));
        }
コード例 #4
0
 private bool IsValidateRemove(DirectoryPost directoryPost)
 {
     if (!_qt.GetCurrentPostIds().Contains(directoryPost.Id))
     {
         return(true);
     }
     else
     {
         MessageBox.Show("На этой должности уже есть сотрудники.");
     }
     return(false);
 }
コード例 #5
0
ファイル: FormWorker.cs プロジェクト: breshch/AIS
        private void AddCurrentPostToDataGrid(DirectoryPost post, DateTime postChangeDate)
        {
            var row = new DataGridViewRow();

            row.CreateCells(dataGridViewCompanyAndPost);

            row.Cells[0].Value = post.Id;
            row.Cells[1].Value = post.DirectoryCompany.Name;
            row.Cells[2].Value = post.Name;
            row.Cells[3].Value = post.UserWorkerSalary.ToString();
            row.Cells[4].Value = post.UserHalfWorkerSalary.ToString();
            row.Cells[5].Value = postChangeDate.ToShortDateString();

            dataGridViewCompanyAndPost.Rows.Add(row);
        }
コード例 #6
0
ファイル: FileServiceTest.cs プロジェクト: Seko47/DataDrive
        public async void Returns_Status404NotFound_when_ParentDirectoryNotExistOrNotBelongsToUser()
        {
            IDatabaseContext    databaseContext     = DatabaseTestHelper.GetContext();
            MapperConfiguration mapperConfiguration = new MapperConfiguration(conf =>
            {
                conf.AddProfile(new Directory_to_DirectoryOut());
            });

            IMapper mapper = mapperConfiguration.CreateMapper();

            IFileService fileService = new FileService(databaseContext, mapper);

            DirectoryPost directoryPost = new DirectoryPost
            {
                ParentDirectoryID = Guid.NewGuid(),
                Name = "TestDirectory"
            };

            StatusCode <DirectoryOut> result = await fileService.CreateDirectoryByUser(directoryPost, "*****@*****.**");

            Assert.NotNull(result);
            Assert.True(result.Code == StatusCodes.Status404NotFound);
        }
コード例 #7
0
        private void AddPost()
        {
            if (IsValidateAdd())
            {
                string nameOfCompany = comboBoxNameOfCompany.SelectedItem.ToString();
                string typeOfPost    = comboBoxTypeOfPost.SelectedItem.ToString();
                var    post          = _qt.GetDirectoryPostEqualDates(dateTimePickerDate.Value, textBoxNameOfPost.Text, nameOfCompany);

                if (post == null)
                {
                    post = new DirectoryPost
                    {
                        Name                 = textBoxNameOfPost.Text,
                        DirectoryCompany     = _qt.GetDirectoryCompany(nameOfCompany),
                        DirectoryTypeOfPost  = _qt.GetDirectoryTypeOfPost(typeOfPost),
                        Date                 = dateTimePickerDate.Value,
                        UserWorkerSalary     = double.Parse(textBoxWorkerSalary.Text.Replace(".", ",")),
                        UserHalfWorkerSalary = double.Parse(textBoxHalfWorkerSalary.Text.Replace(".", ","))
                    };
                    _qt.AddDirectoryPost(post);
                }
                else
                {
                    post.Name                 = textBoxNameOfPost.Text;
                    post.DirectoryCompany     = _qt.GetDirectoryCompany(nameOfCompany);
                    post.DirectoryTypeOfPost  = _qt.GetDirectoryTypeOfPost(typeOfPost);
                    post.Date                 = dateTimePickerDate.Value;
                    post.UserWorkerSalary     = double.Parse(textBoxWorkerSalary.Text.Replace(".", ","));
                    post.UserHalfWorkerSalary = double.Parse(textBoxHalfWorkerSalary.Text.Replace(".", ","));
                }

                _qt.Save();

                FormFill();
            }
        }
コード例 #8
0
ファイル: QueryTemplates.cs プロジェクト: breshch/AIS
 public void RemoveDirectoryPost(DirectoryPost directoryPost)
 {
     _db.DirectoryPosts.Remove(directoryPost);
 }
コード例 #9
0
ファイル: QueryTemplates.cs プロジェクト: breshch/AIS
 public void AddDirectoryPost(DirectoryPost post)
 {
     _db.DirectoryPosts.Add(post);
 }