public async Task <bool> AddAsync(OfficeDto dto) { ValidatorOffice.ValidatorAddOfficeIfDtoIsNull(dto); var office = new Office { Street = dto.Street, StreetNumber = dto.StreetNumber, CityId = dto.CityId, CompanyId = dto.CompanyId, }; await this.context.Offices.AddAsync(office); await this.context.SaveChangesAsync(); return(true); }
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 }); }
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); }
public async Task EditAsync(OfficeDto dto) { ValidatorOffice.ValidatorAddOfficeIfIdNotExist(dto.Id); var office = await this.context.Offices.FindAsync(dto.Id); var addres = ValidatorOffice.ValidatorForUpdateOfficeStreet(dto); var number = ValidatorOffice.ValidatorForUpdateOfficeStreetNumber(dto); if (addres) { office.Street = dto.Street; } if (number) { office.StreetNumber = dto.StreetNumber; } office.CompanyId = dto.CompanyId; office.CityId = dto.CityId; await this.context.SaveChangesAsync(); }