public async Task <Result <long> > CreateEmployee(CreateEmployeeDTO dto) { var name = Name.Create(dto.Name); if (name.IsFailure) { return(Result.Failure <long>(name.Error)); } var employee = new Domain.Employee(name.Value) { Surname = dto.Surname, Patronymic = dto.Patronymic, BirthDate = dto.BirthDate, Position = dto.Position, Organization = dto.Organization, }; var contacts = this.GetContactsFromDTO(dto.Contacts); if (contacts.IsFailure) { return(Result.Failure <long>($"Can't update contacts due to errors: {contacts.Error}")); } employee.AddContacts(contacts.Value); await this.dbContext.Employees.AddAsync(employee); await this.dbContext.SaveChangesAsync(); return(Result.Success(employee.Id)); }