Beispiel #1
0
        public async Task <CatalogueByGuidModel> GetCatalogueByGuid(string catalogueId)
        {
            CatalogueByGuidModel catalogueDetails = await(from catalogues in _catalogueContext.Catalogues
                                                          where catalogues.CatalogueId == catalogueId
                                                          select new CatalogueByGuidModel
            {
                CatalogueId    = catalogues.CatalogueId,
                FileName       = catalogues.FileName,
                CompanyDetails = (from company in _catalogueContext.CompanyDetails
                                  where company.CatalogueId == catalogueId
                                  select new CompanyDetailModel
                {
                    CompanyId = company.CompanyId,
                    CompanyName = company.CompanyName,
                    Region = company.Region,
                    Sector = company.Sector,
                    SubSector = company.SubSector,
                    NumberOfEmployees = company.NumberOfEmployees,
                    TotalRevenues = company.TotalRevenues,
                    WebSite = company.WebSite
                }).ToList()
            }).FirstOrDefaultAsync();

            return(catalogueDetails);
        }
        public async Task <CatalogueByGuidModel> GetCatalogueByCatalogueId(string catalogueId)
        {
            CatalogueByGuidModel catalogueByGuidModel = null;

            if (!string.IsNullOrWhiteSpace(catalogueId))
            {
                catalogueByGuidModel = await _retrieveCatalogueDetailsRepo.GetCatalogueByGuid(catalogueId);
            }
            return(catalogueByGuidModel);
        }
        public void Given_CatalogueId_As_string_1()
        {
            string catalogueId = "1";
            CatalogueByGuidModel catalogueByGuidModel = new CatalogueByGuidModel();
            var taskDecorator = Task.FromResult(catalogueByGuidModel);

            _mockRetrieveCatalogueDetailsRepo.Setup(x => x.GetCatalogueByGuid(It.IsAny <string>())).Returns(taskDecorator);
            var result = _catalogueDetails.GetCatalogueByCatalogueId(catalogueId);

            Assert.IsTrue(result is Task <CatalogueByGuidModel>);
        }
Beispiel #4
0
        public async Task <IActionResult> GetCompanyDetails([FromRoute] string catalogueId)
        {
            try
            {
                CatalogueByGuidModel catalogueDetails = await _catalogueDetails.GetCatalogueByCatalogueId(catalogueId);

                if (catalogueDetails != null)
                {
                    return(Ok(catalogueDetails));
                }
                else
                {
                    return(StatusCode(404));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public async Task <ExportModel> Export(string catalogueId)
        {
            try
            {
                CatalogueByGuidModel catalogueDetails = await _retrieveCatalogueDetailsRepo.GetCatalogueByGuid(catalogueId);

                string path = _constructFileStoragePath.GetPath(catalogueId);
                _constructExcelFile.Create(path, catalogueDetails.CompanyDetails);
                byte[] file = File.ReadAllBytes(path);
                _deleteFile.Delete(path);
                ExportModel fileDetails = new ExportModel
                {
                    FileBytes = file,
                    FileName  = catalogueDetails.FileName
                };
                return(fileDetails);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }