I have a Business Object (Domain Object) representing an employee's shift timings. Its name is EmployeeWorkShift
.
using System;
namespace BusinessObjects
{
public class EmployeeWorkShift
{
public long EmployeeWorkShiftId { get; set; }
public long EmployeeId { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public TimeSpan StartTime { get; set; }
public TimeSpan EndTime { get; set; }
}
}
I have a Repository to create, read, update and delete this Business Object in database. Its name is IEmployeeWorkShiftRepository
.
I have a Service which has methods to perform operations with this Business Object. Its name is IEmployeeWorkShiftService
.
The User Interface call the Service methods for different events:
-
To retrieve all
EmployeeWorkShift
objects of an employee, it callsList<EmployeeWorkShift> GetEmployeeWorkShifts(long employeeId);
method -
To retrieve a specific
EmployeeWorkShift
object, it callsEmployeeWorkShift GetEmployeeWorkShift(long employeeWorkShiftId);
method -
To insert a specific
EmployeeWorkShift
object, it callsEmployeeWorkShift InsertEmployeeWorkShift(EmployeeWorkShift employeeWorkShift);
method -
To update a specific
EmployeeWorkShift
object, it callsEmployeeWorkShift UpdateEmployeeWorkShift(EmployeeWorkShift employeeWorkShift);
method -
To delete a specific
EmployeeWorkShift
object, it callsvoid DeleteEmployeeWorkShift(EmployeeWorkShift employeeWorkShift);
method
Now in the User Interface, for retrieve/insert/update, the user wants to use some specific formats for dates and times of EmployeeWorkShift
object.
One way to solve this issues, is to add 4 string properties in EmployeeWorkShift
object which contains the dates and times in specific formats user desires:
using System;
namespace BusinessObjects
{
public class EmployeeWorkShift
{
public long EmployeeWorkShiftId { get; set; }
public long EmployeeId { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public TimeSpan StartTime { get; set; }
public TimeSpan EndTime { get; set; }
public string StartDateString { get; set; }
public string EndDateString { get; set; }
public string StartTimeString { get; set; }
public string EndTimeString { get; set; }
}
}
So in User Interface I don't use the original 4 properties of dates and times and instead use the new 4 string properties.
In Service method for retrieve, once I get data from Repository, I translate the original 4 properties of dates and times retrieved from database into specific formats and populate the new 4 string properties.
In Service method for insert/update, I translate the new 4 string properties into original 4 properties of dates and times before calling Repository.
This looks a crude solution to me. Is there a better way to solve this issue?
Aucun commentaire:
Enregistrer un commentaire