Ejemplo n.º 1
0
        public async Task EditAsync(EmployeeDto dto)
        {
            ValidationEmployee.ValidationEmployeeFirstNameLength(dto.FirstName);
            ValidationEmployee.ValidationEmployeeLastNameLength(dto.LastName);

            var employee = await this.context.Employees
                           .Include(office => office.Office)
                           .Include(company => company.Company)
                           .FirstOrDefaultAsync(empl => empl.Id == dto.Id);

            var office = await this.context.Offices
                         .FindAsync(dto.OfficeId);

            var company = await this.context.Companies
                          .Where(company => company.Id == office.CompanyId && office.IsDeleted == false)
                          .FirstAsync();

            var validateCompany = ValidatorCompany.ValidateIfCompanyIsNull(company);

            if (validateCompany)
            {
                employee.FirstName            = dto.FirstName;
                employee.LastName             = dto.LastName;
                employee.ExperienceEmployeeId = dto.ExperienceEmployeeId;
                employee.Salary       = dto.Salary;
                employee.VacationDays = dto.VacationDays;
                employee.CompanyId    = company.Id;
                employee.Company      = company;
                employee.OfficeId     = office.Id;
                employee.Office       = office;

                await this.context.SaveChangesAsync();
            }
        }
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);
        }