public async Task CreateKeywordAsync(KeywordDTO keywordDTO)
        {
            var keyword   = _mapper.Map <Keyword>(keywordDTO);
            var resources = _mapper.Map <List <Resource> >(keywordDTO.Resources);

            keyword.KeywordResources = new List <KeywordResource>();
            foreach (Resource resource in resources)
            {
                var existedResourse = await _resourceRepository.UrlExists(resource.UrlAddress);

                if (existedResourse != default)
                {
                    _keywordRepository.AddResourceToKeyword(new KeywordResource {
                        Resource = existedResourse, Keyword = keyword
                    });
                }
                else
                {
                    _keywordRepository.AddResourceToKeyword(new KeywordResource {
                        Resource = resource, Keyword = keyword
                    });
                }
            }
            _keywordRepository.Add(keyword);
            await _context.SaveChangesAsync();
        }
        public async Task CreateKeywordAsyncIfResourceNotExists_AddResources()
        {
            ResourceDTO resourceDTO = new ResourceDTO()
            {
                UrlAddress = "anyUrl"
            };
            var keyWords = new KeywordDTO()
            {
                Resources = new List <ResourceDTO>()
                {
                    resourceDTO
                }
            };

            _resourceRepositoryMock.Setup(r => r.UrlExists(It.IsAny <string>()))
            .Returns(Task.FromResult((Resource) default));
        public async Task CreateKeywordAsyncIfResourceExists_DoesntAddResources()
        {
            var keyWords = new KeywordDTO()
            {
                Resources = new List <ResourceDTO>()
                {
                    new ResourceDTO()
                }
            };
            var resource = new Resource();

            _resourceRepositoryMock.Setup(r => r.UrlExists(It.IsAny <string>()))
            .Returns(Task.FromResult(resource));

            await _service.CreateKeywordAsync(keyWords);

            _keywordRepositoryMock.Verify(r =>
                                          r.AddResourceToKeyword(It.Is <KeywordResource>(k => k.Resource == resource)), Times.Once);
            _dbContextMock.Verify(r => r.SaveChangesAsync(CancellationToken.None), Times.Once);
        }
Example #4
0
        public async Task OnGetAsync()
        {
            var files = await client.GetAllFilesAsync();

            foreach (var file in files)
            {
                FileDTO fileDTO = new FileDTO();
                fileDTO.FileId       = file.FileId;
                fileDTO.Created_at   = file.Created_at;
                fileDTO.Location     = file.Location;
                fileDTO.Path         = file.Path;
                fileDTO.Type         = file.Type;
                fileDTO.Path_changed = file.Path_changed;
                ServiceReferenceClientWeb.Keyword[] keywordList = await client.GetKeywordsOfFileAsync(file.Path);

                foreach (var keyword in keywordList)
                {
                    FileKeywordDTO fkDTO      = new FileKeywordDTO();
                    KeywordDTO     keywordDTO = new KeywordDTO();
                    keywordDTO.Id       = keyword.Id;
                    keywordDTO.Kword    = keyword.Kword;
                    fkDTO.File          = fileDTO;
                    fkDTO.FileId        = fileDTO.FileId;
                    fkDTO.FIleKeywordId = keywordDTO.Id;
                    fkDTO.Keyword       = keywordDTO;
                    fileDTO.Keywords.Add(fkDTO);
                }
                if (FilterLocation == null && FilterKeyword == null)
                {
                    fileDTOList.Add(fileDTO);
                }
                else
                {
                    if (FilterLocation == null)
                    {
                        bool find = false;
                        foreach (var item in fileDTO.Keywords)
                        {
                            if (item.Keyword.Kword == FilterKeyword)
                            {
                                find = true;
                            }
                        }
                        if (find)
                        {
                            fileDTOList.Add(fileDTO);
                        }
                    }
                    else if (FilterKeyword == null)
                    {
                        if (fileDTO.Location == FilterLocation)
                        {
                            fileDTOList.Add(fileDTO);
                        }
                    }
                    else
                    {
                        bool find = false;
                        foreach (var item in fileDTO.Keywords)
                        {
                            if (item.Keyword.Kword == FilterKeyword && fileDTO.Location == FilterLocation)
                            {
                                find = true;
                            }
                        }
                        if (find)
                        {
                            fileDTOList.Add(fileDTO);
                        }
                    }
                }
                Number = fileDTOList.Count.ToString();
            }
        }
Example #5
0
 public ActionResult <KeywordDTO> UpdateKeyword([FromBody] Keyword keyword)
 {
     return(Ok(KeywordDTO.Of(_keywordService.UpdateKeyword(keyword))));
 }
Example #6
0
 public ActionResult <KeywordDTO> DeleteKeyword(int id)
 {
     return(Ok(KeywordDTO.Of(_keywordService.DeleteKeyword(id))));
 }
Example #7
0
 public ActionResult <List <KeywordDTO> > GetAllKeywords()
 {
     return(Ok(_keywordService.GetAllKeywords().Select(keyword => KeywordDTO.Of(keyword)).ToList()));
 }
Example #8
0
 public ActionResult <List <KeywordDTO> > GetKeywordsForCompany(int companyId)
 {
     return(Ok(_companyService.GetKeywordsForCompany(companyId).Select(x => KeywordDTO.Of(x)).ToList()));
 }
Example #9
0
 public ActionResult <List <KeywordDTO> > GetKeywordsForContact(int contactId)
 {
     return(Ok(_contactService.GetKeywordsForContact(contactId).Select(x => KeywordDTO.Of(x))));
 }