public async Task <OfficeDto> GetAsync(int id)
        {
            var office = await this.context.Offices
                         .Include(c => c.City)
                         .Where(office => office.Id == id && office.IsDeleted == false)
                         .FirstAsync();

            ValidatorOffice.ValidatorOffices(office);

            return(new OfficeDto
            {
                Id = office.Id,
                Street = office.Street,
                StreetNumber = office.StreetNumber,
                CityId = office.CityId,
                CountryId = office.City.CountryId,
                CompanyId = office.CompanyId,
                IsDeleted = office.IsDeleted
            });
        }
Ejemplo n.º 2
0
        public async Task <bool> AddAsync(EmployeeDto dto)
        {
            ValidationEmployee.ValidationEmployeeFirstNameLength(dto.FirstName);
            ValidationEmployee.ValidationEmployeeLastNameLength(dto.LastName);
            ValidationEmployee.ValidationEmployeeExperienceEmployeeId(dto.ExperienceEmployeeId);
            ValidationEmployee.ValidationEmployeeOfficeId(dto.OfficeId);
            ValidationEmployee.ValidationEmployeeCompanyId(dto.CompanyId);

            var office = await this.context.Offices
                         .Where(officeId => officeId.Id == dto.OfficeId)
                         .SingleOrDefaultAsync();

            ValidatorOffice.ValidatorOffices(office);

            var company = await this.context.Companies
                          .Where(companyId => companyId.Id == dto.CompanyId)
                          .SingleOrDefaultAsync();

            ValidatorCompany.ValidateCompanyIfNotExistExist(company);

            var employee = new Employee
            {
                FirstName            = dto.FirstName,
                LastName             = dto.LastName,
                VacationDays         = dto.VacationDays,
                CompanyId            = dto.CompanyId,
                Company              = company,
                ExperienceEmployeeId = dto.ExperienceEmployeeId,
                Office       = office,
                OfficeId     = dto.OfficeId,
                Salary       = dto.Salary,
                StartingDate = DateTime.Now
            };

            await this.context.Employees.AddAsync(employee);

            await this.context.SaveChangesAsync();

            return(true);
        }