Commit 7198c837 authored by Almouhannad's avatar Almouhannad

(B) Apply result on people entities, make props with private setter

parent 42981ba9
......@@ -18,7 +18,7 @@ public sealed class Disease : Entity
#region Properties
public string Name { get; set; } = null!;
public string Name { get; private set; } = null!;
#region Navigations
......
......@@ -18,7 +18,7 @@ public sealed class Hospital : Entity
#region Properties
public string Name { get; set; } = null!;
public string Name { get; private set; } = null!;
#endregion
......
......@@ -17,9 +17,9 @@ public sealed class MedicalImage : Entity
#region Properties
public string Name { get; set; } = null!;
public string Name { get; private set; } = null!;
public string? Description { get; set; }
public string? Description { get; private set; }
#endregion
......
......@@ -17,9 +17,9 @@ public sealed class MedicalTest : Entity
#region Properties
public string Name { get; set; } = null!;
public string Name { get; private set; } = null!;
public string? Description { get; set; }
public string? Description { get; private set; }
#endregion
......
using Domain.Entities.Medicals.Medicines.MedicineFormValues;
using Domain.Entities.People.Patients.Relations.PatientMedicines;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Shared;
......@@ -25,13 +24,13 @@ public sealed class Medicine : Entity
#region Properties
public MedicineForm MedicineForm { get; set; } = null!;
public MedicineForm MedicineForm { get; private set; } = null!;
public int Amount { get; set; }
public int Amount { get; private set; }
public string Name { get; set; } = null!;
public string Name { get; private set; } = null!;
public decimal Dosage { get; set; }
public decimal Dosage { get; private set; }
#region Navigations
......
......@@ -16,7 +16,7 @@ public sealed class MedicineForm : Entity
#region Properties
public string Name { get; set; } = null!;
public string Name { get; private set; } = null!;
#endregion
......
using Domain.Entities.People.Doctors.Shared;
using Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues;
using Domain.Entities.People.Shared;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Doctors;
......@@ -22,9 +22,9 @@ public sealed class Doctor : Entity
#region Properties
public PersonalInfo PersonalInfo { get; set; } = null!;
public PersonalInfo PersonalInfo { get; private set; } = null!;
public DoctorStatus Status { get; set; } = null!;
public DoctorStatus Status { get; private set; } = null!;
#region Navigations
......@@ -41,45 +41,45 @@ public sealed class Doctor : Entity
#region Methods
#region Static factory
public static Doctor Create(string firstName, string middleName, string lastName)
public static Result<Doctor> Create(string firstName, string middleName, string lastName)
{
PersonalInfo personalInfo;
try
{
personalInfo = PersonalInfo.Create(firstName, middleName, lastName);
}
catch
{
throw;
}
Result<PersonalInfo> personalInfo = PersonalInfo.Create(firstName, middleName, lastName);
if (personalInfo.IsFailure)
return Result.Failure<Doctor>(Errors.DomainErrors.InvalidValuesError);
return new Doctor(0, personalInfo);
return new Doctor(0, personalInfo.Value);
}
#endregion
#region Add phone
public void AddPhone(string phone, string? number = null)
public Result AddPhone(string phone, string? name = null)
{
DoctorPhone doctorPhone;
try
{
doctorPhone = DoctorPhone.Create(phone, number);
}
catch
{
throw;
}
_phones.Add(doctorPhone);
#region Create number to attach
Result<DoctorPhone> doctorPhone = DoctorPhone.Create(phone, name);
if (doctorPhone.IsFailure)
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
#endregion
#region Check duplicate
if (Phones.Where(p => p.Phone == phone).ToList().Count > 0)
return Result.Failure(Errors.DomainErrors.PhoneAlreadyExist);
#endregion
_phones.Add(doctorPhone.Value);
return Result.Success();
}
#endregion
#region Change status
public void ChangeStatusTo(DoctorStatus status)
public Result ChangeStatusTo(DoctorStatus status)
{
if (status == DoctorStatuses.Available || status == DoctorStatuses.Busy || status == DoctorStatuses.Working)
{
Status = status;
throw new InvalidValuesDomainException<DoctorStatus>();
return Result.Success();
}
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
}
#endregion
......
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Doctors.Shared;
......@@ -18,9 +18,9 @@ public sealed class DoctorPhone : Entity
#region Properties
public string? Name { get; set; }
public string? Name { get; private set; }
public string Phone { get; set; } = null!;
public string Phone { get; private set; } = null!;
#endregion
......@@ -28,10 +28,10 @@ public sealed class DoctorPhone : Entity
#region Static factory
public static DoctorPhone Create(string phone, string? name)
public static Result<DoctorPhone> Create(string phone, string? name)
{
if (phone is null)
throw new InvalidValuesDomainException<DoctorPhone>();
return Result.Failure<DoctorPhone>(Errors.DomainErrors.InvalidValuesError);
return new DoctorPhone(0, phone, name);
}
......
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues;
......@@ -19,21 +19,22 @@ public sealed class DoctorStatus : Entity
#region Properties
public string Name { get; set; } = null!;
public string Name { get; private set; } = null!;
#endregion
#region Methods
#region Static factory
public static DoctorStatus Create(string name, int? id)
public static Result<DoctorStatus> Create(string name, int? id)
{
if (name is null)
throw new InvalidValuesDomainException<DoctorStatus>();
return Result.Failure<DoctorStatus>(Errors.DomainErrors.InvalidValuesError);
if (id is not null)
{
if (id < 0)
throw new InvalidValuesDomainException<DoctorStatus>();
return Result.Failure<DoctorStatus>(Errors.DomainErrors.InvalidValuesError);
return new DoctorStatus(id.Value, name);
}
......
namespace Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues;
using Domain.Exceptions.InvalidValue;
namespace Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues;
public static class DoctorStatuses
{
#region Constant id values
#region Constant values
public static DoctorStatus Available => DoctorStatus.Create("متاح", 1);
public static DoctorStatus Available
{
get
{
var result = DoctorStatus.Create("متاح", 1);
if (result.IsFailure)
throw new InvalidValuesDomainException<DoctorStatus>();
return result.Value;
}
}
public static DoctorStatus Working => DoctorStatus.Create("لديه مريض", 1);
public static DoctorStatus Working
{
get
{
var result = DoctorStatus.Create("لديه مريض", 1);
if (result.IsFailure)
throw new InvalidValuesDomainException<DoctorStatus>();
return result.Value;
}
}
public static DoctorStatus Busy => DoctorStatus.Create("مشغول", 1);
public static DoctorStatus Busy
{
get
{
var result = DoctorStatus.Create("مشغول", 1);
if (result.IsFailure)
throw new InvalidValuesDomainException<DoctorStatus>();
return result.Value;
}
}
#endregion
}
using Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers;
using Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues;
using Domain.Entities.People.Employees.Shared;
using Domain.Entities.People.FamilyMembers;
using Domain.Entities.People.Patients;
using Domain.Exceptions.InvalidValue;
using Domain.Entities.People.Shared.GenderValues;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Employees;
......@@ -30,15 +32,15 @@ public sealed class Employee : Entity
#region Properties
public Patient Patient { get; set; } = null!;
public Patient Patient { get; private set; } = null!;
public EmployeeAdditionalInfo? AdditionalInfo { get; set; }
public EmployeeAdditionalInfo? AdditionalInfo { get; private set; }
public string SerialNumber { get; set; } = null!;
public string SerialNumber { get; private set; } = null!;
public string CenterStatus { get; set; } = null!;
public string CenterStatus { get; private set; } = null!;
public bool IsMarried { get; set; }
public bool IsMarried { get; private set; }
#region Navigations
......@@ -65,7 +67,7 @@ public sealed class Employee : Entity
#region Methods
#region Static factory
public static Employee Create(
public static Result<Employee> Create(
string firstName, string middleName, string lastName, DateOnly dateOfBirth, string gender,
string serialNumber, string centerStatus, bool isMarried = false,
......@@ -75,64 +77,90 @@ public sealed class Employee : Entity
)
{
#region Create patient
Patient patient;
try
{
patient = Patient.Create(firstName, middleName, lastName, dateOfBirth, gender);
}
catch
{
throw;
}
Result<Patient> patient = Patient.Create(firstName, middleName, lastName, dateOfBirth, gender);
if (patient.IsFailure)
return Result.Failure<Employee>(Errors.DomainErrors.InvalidValuesError);
#endregion
#region Check employee's required details
if (serialNumber is null || centerStatus is null)
throw new InvalidValuesDomainException<Employee>();
return Result.Failure<Employee>(Errors.DomainErrors.InvalidValuesError);
#endregion
#region Create additional info
EmployeeAdditionalInfo? additionalInfo;
try
{
additionalInfo = EmployeeAdditionalInfo.Create(startDate, academicQualification,
workPhone, location, specialization, jobStatus, imageUrl);
}
catch
{
throw;
}
EmployeeAdditionalInfo? additionalInfo = EmployeeAdditionalInfo.Create(
startDate, academicQualification, workPhone,
location, specialization, jobStatus, imageUrl);
#endregion
return new Employee(0, patient, serialNumber, centerStatus, isMarried, additionalInfo);
return new Employee(0, patient.Value, serialNumber, centerStatus, isMarried, additionalInfo);
}
#endregion
#region Add family member
public void AddFamilyMember(FamilyMember familyMember, string role)
public Result AddFamilyMember(FamilyMember familyMember, string role)
{
EmployeeFamilyMember employeeFamilyMember;
try
{
employeeFamilyMember = EmployeeFamilyMember.Create(Id, familyMember.Id, role);
}
catch
{
throw;
}
#region Create family member to attach
Result<EmployeeFamilyMember> employeeFamilyMember =
EmployeeFamilyMember.Create(Id, familyMember.Id, role);
if (employeeFamilyMember.IsFailure)
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
#endregion
#region Check valid relation
_familyMembers.Add(employeeFamilyMember);
if (role == FamilyRoles.Husband.Name && Patient.Gender == Genders.Male)
return Result.Failure(Errors.DomainErrors.InvalidHusbandRole);
if (role == FamilyRoles.Wife.Name && Patient.Gender == Genders.Female)
return Result.Failure(Errors.DomainErrors.InvalidWifeRole);
#endregion
#region Check duplicate
if (FamilyMembers.Where(fm => fm.FamilyMemberId == familyMember.Id).ToList().Count > 0)
return Result.Failure(Errors.DomainErrors.RelationAlreadyExist);
#endregion
_familyMembers.Add(employeeFamilyMember.Value);
IsMarried = true;
return Result.Success();
}
#endregion
#region Add related employee
public void AddRelatedEmployee(Employee employee)
public Result AddRelatedEmployee(Employee employee)
{
#region Check valid relation
if (Patient.Gender == Genders.Male && employee.Patient.Gender == Genders.Male)
return Result.Failure(Errors.DomainErrors.InvalidHusbandRole);
if (Patient.Gender == Genders.Female && employee.Patient.Gender == Genders.Female)
{
return Result.Failure(Errors.DomainErrors.InvalidWifeRole);
}
#endregion
#region Check duplicate
if (RelatedEmployees.Where(re => re.Id == employee.Id).ToList().Count > 0
|| RelatedTo.Where(rt => rt.Id == employee.Id).ToList().Count > 0
)
return Result.Failure(Errors.DomainErrors.RelationAlreadyExist);
#endregion
_relatedEmployees.Add(employee);
IsMarried = true;
return Result.Success();
}
#endregion
......
using Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues;
using Domain.Entities.People.FamilyMembers;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers;
......@@ -18,26 +18,26 @@ public sealed class EmployeeFamilyMember : Entity
Role = role;
}
#endregion
#region Properties
#region Employee
public int EmployeeId { get; set; }
public Employee Employee { get; set; } = null!;
public int EmployeeId { get; private set; }
public Employee Employee { get; private set; } = null!;
#endregion
#region Family member
public int FamilyMemberId { get; set; }
public FamilyMember FamilyMember { get; set; } = null!;
public int FamilyMemberId { get; private set; }
public FamilyMember FamilyMember { get; private set; } = null!;
#endregion
#region Additional
public FamilyRole Role { get; set; } = null!;
public FamilyRole Role { get; private set; } = null!;
#endregion
......@@ -46,13 +46,13 @@ public sealed class EmployeeFamilyMember : Entity
#region Methods
#region Static factory
public static EmployeeFamilyMember Create(int employeeId, int familyMemberId, string role)
public static Result<EmployeeFamilyMember> Create(int employeeId, int familyMemberId, string role)
{
if (employeeId <= 0 || familyMemberId <= 0 || role is null)
throw new InvalidValuesDomainException<EmployeeFamilyMember>();
return Result.Failure<EmployeeFamilyMember>(Errors.DomainErrors.InvalidValuesError);
#region Check role
FamilyRole? selectedRole;
Result<FamilyRole> selectedRole = new(null, false, Errors.DomainErrors.InvalidValuesError);
FamilyRole husband = FamilyRoles.Husband;
FamilyRole wife = FamilyRoles.Wife;
......@@ -60,21 +60,20 @@ public sealed class EmployeeFamilyMember : Entity
FamilyRole daughter = FamilyRoles.Daughter;
if (role == husband.Name)
selectedRole = husband;
selectedRole = Result.Success<FamilyRole>(husband);
else if (role == wife.Name)
selectedRole = wife;
selectedRole = Result.Success<FamilyRole>(wife);
else if (role == son.Name)
selectedRole = son;
selectedRole = Result.Success<FamilyRole>(son);
else if (role == daughter.Name)
selectedRole = daughter;
else selectedRole = null;
selectedRole = Result.Success<FamilyRole>(daughter);
if (selectedRole is null)
throw new InvalidValuesDomainException<FamilyRole>();
if (selectedRole.IsFailure)
return Result.Failure<EmployeeFamilyMember>(Errors.DomainErrors.InvalidValuesError);
#endregion
return new EmployeeFamilyMember(0, employeeId, familyMemberId, selectedRole);
return new EmployeeFamilyMember(0, employeeId, familyMemberId, selectedRole.Value);
}
#endregion
......
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues;
......@@ -19,21 +19,21 @@ public sealed class FamilyRole : Entity
#region Properties
public string Name { get; set; } = null!;
public string Name { get; private set; } = null!;
#endregion
#region Methods
#region Static factory
public static FamilyRole Create(string name, int? id)
public static Result<FamilyRole> Create(string name, int? id)
{
if (name is null)
throw new InvalidValuesDomainException<FamilyRole>();
return Result.Failure<FamilyRole>(Errors.DomainErrors.InvalidValuesError);
if (id is not null)
{
if (id < 0)
throw new InvalidValuesDomainException<FamilyRole>();
return Result.Failure<FamilyRole>(Errors.DomainErrors.InvalidValuesError);
return new FamilyRole(id.Value, name);
}
......
namespace Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues;
using Domain.Exceptions.InvalidValue;
namespace Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues;
public static class FamilyRoles
{
#region Constant id values
public static FamilyRole Husband => FamilyRole.Create("زوج", 1);
public static FamilyRole Husband
{
get
{
var result = FamilyRole.Create("زوج", 1);
if (result.IsFailure)
throw new InvalidValuesDomainException<FamilyRole>();
return result.Value;
}
}
public static FamilyRole Wife => FamilyRole.Create("زوجة", 2);
public static FamilyRole Wife
{
get
{
var result = FamilyRole.Create("زوجة", 2);
if (result.IsFailure)
throw new InvalidValuesDomainException<FamilyRole>();
return result.Value;
}
}
public static FamilyRole Son => FamilyRole.Create("ابن", 3);
public static FamilyRole Son
{
get
{
var result = FamilyRole.Create("ابن", 3);
if (result.IsFailure)
throw new InvalidValuesDomainException<FamilyRole>();
return result.Value;
}
}
public static FamilyRole Daughter => FamilyRole.Create("ابنة", 4);
public static FamilyRole Daughter
{
get
{
var result = FamilyRole.Create("ابنة", 4);
if (result.IsFailure)
throw new InvalidValuesDomainException<FamilyRole>();
return result.Value;
}
}
#endregion
}
using Domain.Entities.People.Patients;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.FamilyMembers;
......@@ -18,32 +19,25 @@ public sealed class FamilyMember : Entity
#region Properties
public Patient Patient { get; set; } = null!;
public Patient Patient { get; private set; } = null!;
#endregion
#region Methods
#region Static factory
public static FamilyMember Create(string firstName, string middleName, string lastName,
public static Result<FamilyMember> Create(string firstName, string middleName, string lastName,
DateOnly dateOfBirth,
string gender
)
{
#region Create patient
Patient patient;
try
{
patient = Patient.Create(firstName, middleName, lastName, dateOfBirth, gender);
}
catch
{
throw;
}
Result<Patient> patient = Patient.Create(firstName, middleName, lastName, dateOfBirth, gender);
if (patient.IsFailure)
return Result.Failure<FamilyMember>(Errors.DomainErrors.InvalidValuesError);
#endregion
return new FamilyMember(0, patient);
return new FamilyMember(0, patient.Value);
}
#endregion
......
......@@ -5,8 +5,8 @@ using Domain.Entities.People.Patients.Relations.PatientMedicines;
using Domain.Entities.People.Shared;
using Domain.Entities.People.Shared.GenderValues;
using Domain.Entities.Visits;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Patients;
......@@ -75,80 +75,72 @@ public sealed class Patient : Entity
#region Methods
#region Static factory
public static Patient Create(string firstName, string middleName, string lastName,
public static Result<Patient> Create(string firstName, string middleName, string lastName,
DateOnly dateOfBirth,
string gender
)
{
#region Personal info
PersonalInfo? personalInfo;
try
{
personalInfo = PersonalInfo.Create(firstName, middleName, lastName);
}
catch
{
throw;
}
Result<PersonalInfo> personalInfo = PersonalInfo.Create(firstName, middleName, lastName);
if (personalInfo.IsFailure)
return Result.Failure<Patient>(Errors.DomainErrors.InvalidValuesError);
#endregion
#region Gender
if (gender is null)
throw new InvalidValuesDomainException<Gender>();
Gender? selectedGender;
Result<Gender> selectedGender = new(null, false, Errors.DomainErrors.InvalidValuesError);
Gender male = Genders.Male;
Gender female = Genders.Female;
if (gender == male.Name)
selectedGender = male;
selectedGender = Result.Success<Gender>(male);
else if (gender == female.Name)
selectedGender = female;
else selectedGender = null;
selectedGender = Result.Success<Gender>(female);
if (selectedGender is null)
throw new InvalidValuesDomainException<Gender>();
if (selectedGender.IsFailure)
return Result.Failure<Patient>(Errors.DomainErrors.InvalidValuesError);
#endregion
return new Patient(0, personalInfo, dateOfBirth, selectedGender);
return new Patient(0, personalInfo.Value, dateOfBirth, selectedGender.Value);
}
#endregion
#region Add medicine
public void AddMedicine(Medicine medicine, int number)
public Result AddMedicine(Medicine medicine, int number)
{
PatientMedicine entry;
#region Create medicine to attach
Result<PatientMedicine> entry = PatientMedicine.Create(Id, medicine.Id, number);
if (entry.IsFailure)
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
#endregion
try
{
entry = PatientMedicine.Create(Id, medicine.Id, number);
}
catch
{
throw;
}
#region Check duplication
if (Medicines.Where(m => m.MedicineId == medicine.Id).ToList().Count > 0)
return Result.Failure(Errors.DomainErrors.PatientAlreadyHasThisMedicine);
#endregion
_medicines.Add(entry);
_medicines.Add(entry.Value);
return Result.Success();
}
#endregion
#region Add disease
public void AddDisease (Disease disease)
public Result AddDisease(Disease disease)
{
PatientDisease entry;
try
{
entry = PatientDisease.Create(Id, disease.Id);
}
catch
{
throw;
}
#region Create disease to attach
Result<PatientDisease> entry = PatientDisease.Create(Id, disease.Id);
if (entry.IsFailure)
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
#endregion
#region Check duplication
if (Diseases.Where(d => d.DiseaseId == disease.Id).ToList().Count > 0)
return Result.Failure(Errors.DomainErrors.PatientAlreadyHasThisDisease);
#endregion
_diseases.Add(entry);
_diseases.Add(entry.Value);
return Result.Success();
}
#endregion
......
using Domain.Entities.Medicals.Diseases;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Patients.Relations.PatientDiseases;
......@@ -22,15 +22,15 @@ public sealed class PatientDisease : Entity
#region Patient
public int PatientId { get; set; }
public Patient Patient { get; set; } = null!;
public int PatientId { get; private set; }
public Patient Patient { get; private set; } = null!;
#endregion
#region Disease
public int DiseaseId { get; set; }
public Disease Disease { get; set; } = null!;
public int DiseaseId { get; private set; }
public Disease Disease { get; private set; } = null!;
#endregion
......@@ -43,10 +43,10 @@ public sealed class PatientDisease : Entity
#region Methods
#region Static factory
public static PatientDisease Create(int patientId, int diseaseId)
public static Result<PatientDisease> Create(int patientId, int diseaseId)
{
if (patientId <= 0 || diseaseId <= 0)
throw new InvalidValuesDomainException<PatientDisease>();
return Result.Failure<PatientDisease>(Errors.DomainErrors.InvalidValuesError);
return new PatientDisease(0, patientId, diseaseId);
}
#endregion
......
using Domain.Entities.Medicals.Medicines;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Patients.Relations.PatientMedicines;
......@@ -25,21 +25,21 @@ public sealed class PatientMedicine : Entity
#region Patient
public int PatientId { get; set; }
public Patient Patient { get; set; } = null!;
public int PatientId { get; private set; }
public Patient Patient { get; private set; } = null!;
#endregion
#region Medicine
public int MedicineId { get; set; }
public Medicine Medicine { get; set; } = null!;
public int MedicineId { get; private set; }
public Medicine Medicine { get; private set; } = null!;
#endregion
#region Additional
public int Number { get; set; }
public int Number { get; private set; }
#endregion
......@@ -49,10 +49,10 @@ public sealed class PatientMedicine : Entity
#region Methods
#region Static factory
public static PatientMedicine Create(int patientId, int medicineId, int number)
public static Result<PatientMedicine> Create(int patientId, int medicineId, int number)
{
if (patientId <= 0 || medicineId <= 0 || number <= 0)
throw new InvalidValuesDomainException<PatientMedicine>();
return Result.Failure<PatientMedicine>(Errors.DomainErrors.InvalidValuesError);
return new PatientMedicine(0, patientId, medicineId, number);
}
#endregion
......
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Shared.GenderValues;
......@@ -26,15 +26,15 @@ public sealed class Gender : Entity
#region Methods
#region Static factory
public static Gender Create(string name, int? id)
public static Result<Gender> Create(string name, int? id)
{
if (name is null)
throw new InvalidValuesDomainException<Gender>();
return Result.Failure<Gender>(Errors.DomainErrors.InvalidValuesError);
if (id is not null)
{
if (id < 0)
throw new InvalidValuesDomainException<Gender>();
return Result.Failure<Gender>(Errors.DomainErrors.InvalidValuesError);
return new Gender(id.Value, name);
}
......
namespace Domain.Entities.People.Shared.GenderValues;
using Domain.Exceptions.InvalidValue;
namespace Domain.Entities.People.Shared.GenderValues;
public static class Genders
{
#region Constant id values
#region Constant values
public static Gender Male => Gender.Create("ذكر", 1);
public static Gender Male
{
get
{
var result = Gender.Create("ذكر", 1);
if (result.IsFailure)
throw new InvalidValuesDomainException<Gender>();
return result.Value;
}
}
public static Gender Female => Gender.Create("أنثى", 2);
public static Gender Female
{
get
{
var result = Gender.Create("أنثى", 2);
if (result.IsFailure)
throw new InvalidValuesDomainException<Gender>();
return result.Value;
}
}
#endregion
}
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.People.Shared;
......@@ -41,10 +41,10 @@ public sealed class PersonalInfo : Entity
#region Methods
#region Static factory
public static PersonalInfo Create(string firstName, string middleName, string lastName)
public static Result<PersonalInfo> Create(string firstName, string middleName, string lastName)
{
if (firstName is null || middleName is null || lastName is null)
throw new InvalidValuesDomainException<PersonalInfo>();
return Result.Failure<PersonalInfo>(Errors.DomainErrors.InvalidValuesError);
return new PersonalInfo(0, firstName, middleName, lastName);
}
......
......@@ -4,5 +4,27 @@ namespace Domain.Errors;
public static class DomainErrors
{
public static Error InvalidValuesError => new Error("Domain.InvalidValues", "Given values are invalid!");
public static Error InvalidValuesError =>
new("Domain.InvalidValues", "القيم المدخلة غير صالحة");
public static Error PatientAlreadyHasThisMedicine =>
new("Domain.PatientAlreadyHasThisMedicine", "المريض لديه بالفعل الدواء الذي تحاول اضافته");
public static Error PatientAlreadyHasThisDisease =>
new("Domain.PatientAlreadyHasThisDisease", "المريض لديه بالفعل المرض الذي تحاول اضافته");
public static Error InvalidHusbandRole =>
new("Domain.InvalidHusbandRole", "لا يمكن للموظف أن يكون له زوج");
public static Error InvalidWifeRole =>
new("Domain.InvalidWifeRole", "لا يمكن للموظفة أن يكون لها زوجة");
public static Error RelationAlreadyExist =>
new("Domain.RelationAlreadyExist", "العلاقة موجودة بالفعل");
public static Error PhoneAlreadyExist =>
new("Domain.PhoneAlreadyExist", "رقم الهاتف موجود بالفعل");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment