private AffairWorkerDto MapToAffairWorkerDto(AffairWorker aw) { var dto = ObjectMapper.Map <AffairWorkerDto>(aw); if (aw.Worker.Photo != null) { dto.PhotoString = Convert.ToBase64String(aw.Worker.Photo); } return(dto); }
public async Task <int> CreateFrom(DateTime carryoutDate, DateTime fromDate) { int workerId = await GetCurrentUserWorkerIdAsync(); workerId = WorkManager.GetCaptainOrAgentId(workerId); // Agent int depotId = WorkManager.GetWorkerDepotId(workerId); var list = _affairRepository.GetAllList(e => e.DepotId == depotId && e.CarryoutDate == fromDate); foreach (Affair a in list) { Affair affair = new Affair(); affair.DepotId = depotId; affair.CarryoutDate = carryoutDate; affair.Status = "安排"; affair.Content = a.Content; affair.WorkplaceId = a.WorkplaceId; affair.StartTime = a.StartTime; affair.EndTime = a.EndTime; affair.Remark = a.Remark; affair.CreateWorkerId = workerId; affair.CreateTime = DateTime.Now; int affairId = await _affairRepository.InsertAndGetIdAsync(affair); var workers = _workerRepository.GetAllList(e => e.AffairId == a.Id); foreach (AffairWorker w in workers) { AffairWorker worker = new AffairWorker(); worker.AffairId = affairId; worker.WorkerId = w.WorkerId; worker.WorkRoleId = w.WorkRoleId; await _workerRepository.InsertAsync(worker); } // var tasks = _taskRepository.GetAllList(e => e.AffairId == a.Id); // foreach (AffairTask t in tasks) // { // AffairTask task = new AffairTask(); // task.AffairId = affairId; // task.WorkplaceId = t.WorkplaceId; // task.Content = t.Content; // task.StartTime = t.StartTime; // task.EndTime = t.EndTime; // task.CreateWorkerId = workerId; // task.CreateTime = DateTime.Now; // await _taskRepository.InsertAsync(task); // } } return(list.Count); }