public QCEvent ConvertToQCEvent(QCEventMessage model, QCDevice device) { var defectTypeService = provider.GetRequiredService <IDefectTypeService>(); var proBatchService = provider.GetRequiredService <IProductionBatchService>(); var proBatch = proBatchService.ProductionBatchs.InLine(device.ProductionLineId.Value) .RunningAtTime(model.CreatedTime).Select(o => new ProductionBatch { Id = o.Id, ProductModelId = o.ProductModelId }).First(); var defCodes = model.Details.Select(o => o.QCDefectCode).ToList(); var defectTypesMap = defectTypeService.DefectTypes.QCMappingCodes(defCodes) .Select(o => new { o.Id, o.QCMappingCode }).ToDictionary(o => o.QCMappingCode); var entity = new QCEvent { Id = model.Id, CreatedTime = model.CreatedTime, QCDeviceId = device.Id, ProductionBatchId = proBatch.Id, Details = model.Details.Select(o => new QCEventDetail { DefectTypeId = defectTypesMap[o.QCDefectCode].Id, Id = o.Id, }).ToList() }; return(entity); }
public AppEvent DeleteQCDevice(QCDevice entity, ClaimsPrincipal principal) { string username = principal.FindFirstValue(AppClaimType.UserName); var ev = new AppEvent { Data = null, Description = $"User {username} deleted QC device id: {entity.Id}", Type = Data.Constants.AppEventType.DeleteQCDevice, UserId = principal.Identity.Name }; PrepareCreate(ev); return(context.AppEvent.Add(ev).Entity); }
public AppEvent ChangeQCDeviceStatus(QCDevice entity, ClaimsPrincipal principal) { string username = principal.FindFirstValue(AppClaimType.UserName); var ev = new AppEvent { Data = null, Description = $"User {username} changed QC device archived status: {entity.Archived} - id: {entity.Id}", Type = Data.Constants.AppEventType.ChangeQCDeviceStatus, UserId = principal.Identity.Name }; PrepareCreate(ev); return(context.AppEvent.Add(ev).Entity); }
public AppEvent SendCommandToDeviceAPI(SendCommandToDeviceAPIModel model, QCDevice entity, ClaimsPrincipal principal) { string username = principal.FindFirstValue(AppClaimType.UserName); var ev = new AppEvent { Data = null, Description = $"User {username} sent cmd {model.Command} to QC device with code {entity.Code} id: {entity.Id}", Type = Data.Constants.AppEventType.SendCommandToDeviceAPI, UserId = principal.Identity.Name }; PrepareCreate(ev); return(context.AppEvent.Add(ev).Entity); }
public QCEvent ConvertToQCEvent(QCEventDeviceModel model, QCDevice device) { var defectTypeService = provider.GetRequiredService <IDefectTypeService>(); var proBatchService = provider.GetRequiredService <IProductionBatchService>(); var proBatch = proBatchService.ProductionBatchs.InLine(device.ProductionLineId.Value) .RunningAtTime(model.CreatedTime.Utc.Value).Select(o => new ProductionBatch { Id = o.Id, ProductModelId = o.ProductModelId }).First(); var defCodes = model.Details.Select(o => o.DefectTypeCode).ToList(); var defectTypesMap = defectTypeService.DefectTypes.QCMappingCodes(defCodes) .Select(o => new { o.Id, o.QCMappingCode }).ToDictionary(o => o.QCMappingCode); var entity = new QCEvent { Id = model.Id, CreatedTime = model.CreatedTime.Utc.Value, QCDeviceId = device.Id, ProductionBatchId = proBatch.Id, Details = model.Details.Select(o => new QCEventDetail { DefectTypeId = defectTypesMap[o.DefectTypeCode].Id, Id = o.Id, }).ToList(), LeftImage = model.LeftImage, RightImage = model.RightImage, SideImages = model.SideImages == null ? null : JsonConvert.SerializeObject(model.SideImages) }; return(entity); }