public WorkerStatusDTO ChangeStatus(UserDTO Driver, DriverWorkingStatusEnum newStatus, DateTime? blockTime = null, string message = null)
{
var driver = Mapper.Map<User>(Driver);
var driverStatus = uOW.WorkerStatusRepo.All.Where(o => o.WorkerId == Driver.Id).FirstOrDefault();
if (driverStatus != null)
{
driverStatus.WorkingStatus = newStatus;
if (blockTime != null)
driverStatus.BlockTime = blockTime;
if (message != null)
driverStatus.BlockMessage = message;
uOW.WorkerStatusRepo.Update(driverStatus);
}
else
{
driverStatus = new WorkerStatus();
driverStatus.WorkerId = Driver.Id;
driverStatus.WorkingStatus = newStatus;
if (blockTime != null)
driverStatus.BlockTime = blockTime;
if (message != null)
driverStatus.BlockMessage = message;
uOW.WorkerStatusRepo.Insert(driverStatus);
}
uOW.Save();
return Mapper.Map<WorkerStatusDTO>(driverStatus);
}