BAL.Manager.WorkerStatusManager.ChangeStatus C# (CSharp) Method

ChangeStatus() public method

public ChangeStatus ( UserDTO Driver, DriverWorkingStatusEnum newStatus, System.DateTime blockTime = null, string message = null ) : WorkerStatusDTO
Driver UserDTO
newStatus DriverWorkingStatusEnum
blockTime System.DateTime
message string
return Model.DTO.WorkerStatusDTO
        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);
        }