Ejemplo n.º 1
0
        public async Task <bool> DeleteCompanyAsync(string name)
        {
            var companyToDelete = await CompanyRepository.GetFirstWhereAsync(c => c.Name == name);

            if (companyToDelete == null)
            {
                throw new NotFoundException(_companyNotFound);
            }

            var companyUsers = UserRepository.GetAll(u => u.Company.Name == name).AsTracking();

            foreach (var u in companyUsers)
            {
                u.Company = null;
            }

            var companyRoles = CompanyRolesRepository.GetAll(r => r.Company.Name == name);
            await CompanyRolesRepository.DeleteRangeAsync(companyRoles);

            await CompanyRepository.DeleteAsync(companyToDelete);

            await CompanyRepository.SaveAsync();

            await UserRepository.SaveAsync();

            await CompanyRolesRepository.SaveAsync();

            return(true);
        }
Ejemplo n.º 2
0
        public async Task Add_Valid_Company_With_Employee()
        {
            //Arrange

            //Act
            var companyResult = await CompanyRepository.AddAsync(_newCompany);

            await CompanyRepository.DeleteAsync(companyResult.Id);

            //Assert
            Assert.IsTrue(companyResult.Id > 0);
        }
Ejemplo n.º 3
0
        public async Task Get_Companies_Employees_Without_Search()
        {
            //Arrange
            var searchModel = new CompanySearch();

            //Act
            var companyResult = await CompanyRepository.AddAsync(_newCompany);

            var companies = await CompanyRepository.GetCompaniesEmployeesAsync(searchModel);

            await CompanyRepository.DeleteAsync(companyResult.Id);

            //Assert
            Assert.IsTrue(companies.Count > 0);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> DeleteCompany(int id)
        {
            try
            {
                await _companyRepository.DeleteAsync(id);

                return(Ok());
            }
            catch (DBNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Ejemplo n.º 5
0
        public async Task <bool> Delete(string id)
        {
            DeleteResult result;

            try
            {
                result = await _companyRepository.DeleteAsync(x => x.Id == id);
            }
            catch (Exception)
            {
                return(false);
            }

            if (!result.IsAcknowledged)
            {
                return(false);
            }

            return(result.DeletedCount == 1);
        }
Ejemplo n.º 6
0
        public async Task Delete_Existing_Company_With_Employee()
        {
            //Arrange
            var isThrown = false;

            //Act
            var companyResult = await CompanyRepository.AddAsync(_newCompany);

            try
            {
                await CompanyRepository.DeleteAsync(companyResult.Id);
            }
            catch (Exception)
            {
                isThrown = true;
            }

            //Assert
            Assert.IsFalse(isThrown);
        }
Ejemplo n.º 7
0
        public async Task Update_Valid_Company_With_Employee()
        {
            //Arrange
            var isThrown      = false;
            var companyResult = new NewCompanyResponse();

            //Act
            try
            {
                companyResult = await CompanyRepository.AddAsync(_newCompany);

                await CompanyRepository.UpdateAsync(companyResult.Id, _newCompany);
            }
            catch (Exception)
            {
                isThrown = true;
            }

            await CompanyRepository.DeleteAsync(companyResult.Id);

            //Assert
            Assert.IsFalse(isThrown);
        }
Ejemplo n.º 8
0
        public async Task Get_Companies_Employees_With_Search()
        {
            //Arrange
            var searchModel = new CompanySearch
            {
                Keyword           = "jakub",
                EmployeeJobTitles = new List <JobTitle> {
                    JobTitle.Developer
                },
                EmployeeBirthDateFrom = new DateTime(1998, 01, 01),
                EmployeeBirthDateTo   = new DateTime(2000, 01, 01),
            };

            //Act
            var companyResult = await CompanyRepository.AddAsync(_newCompany);

            var companies = await CompanyRepository.GetCompaniesEmployeesAsync(searchModel);

            await CompanyRepository.DeleteAsync(companyResult.Id);

            //Assert
            Assert.IsTrue(companies.Count > 0);
        }