public async Task <OperationResult> Update(TrashInspectionModel updateModel) { var selectedTrashInspection = new Microting.eFormTrashInspectionBase.Infrastructure.Data.Entities.TrashInspection { Id = updateModel.Id, Date = updateModel.Date, EakCode = updateModel.EakCode, InstallationId = updateModel.InstallationId, MustBeInspected = updateModel.MustBeInspected, Producer = updateModel.Producer, RegistrationNumber = updateModel.RegistrationNumber, Time = updateModel.Time, Transporter = updateModel.Transporter, TrashFraction = updateModel.TrashFraction, WeighingNumber = updateModel.WeighingNumber, Status = updateModel.Status, Version = updateModel.Version, WorkflowState = updateModel.WorkflowState, ExtendedInspection = updateModel.ExtendedInspection, InspectionDone = updateModel.InspectionDone }; await selectedTrashInspection.Update(_dbContext); return(new OperationResult(true)); }
public TrashInspectionReceived(TrashInspectionModel trashInspectionModel, Fraction fraction, Segment segment, Installation installation) { TrashInspectionModel = trashInspectionModel; Fraction = fraction; Segment = segment; Installation = installation; }
public TrashInspectionReceived(TrashInspectionModel trashInspectionModel, int fractionId, int segmentId, int installationId) { TrashInspectionModel = trashInspectionModel; FractionId = fractionId; SegmentId = segmentId; InstallationId = installationId; }
#pragma warning disable 1998 public async Task Handle(TrashInspectionDeleted message) { try { TrashInspectionModel createModel = message.TrashInspectionModel; List <TrashInspectionCase> trashInspectionCases = _dbContext.TrashInspectionCases .Where(x => x.TrashInspectionId == createModel.Id).ToList(); foreach (TrashInspectionCase trashInspectionCase in trashInspectionCases) { bool result = await _core.CaseDelete(int.Parse(trashInspectionCase.SdkCaseId)); if (result) { await trashInspectionCase.Delete(_dbContext); } } Microting.eFormTrashInspectionBase.Infrastructure.Data.Entities.TrashInspection trashInspection = await _dbContext.TrashInspections.SingleAsync(x => x.Id == createModel.Id); trashInspection.InspectionDone = true; await trashInspection.Update(_dbContext); if (message.ShouldDelete) { await trashInspection.Delete(_dbContext); } } catch (Exception exception) { Console.WriteLine(exception.Message); } }
public TrashInspectionCaseCreated(int templateId, int trashInspectionCaseId, TrashInspectionModel trashInspectionModel, int segmentId, int fractionId) { TemplateId = templateId; TrashInspectionCaseId = trashInspectionCaseId; TrashInspectionModel = trashInspectionModel; SegmentId = segmentId; FractionId = fractionId; }
public TrashInspectionDeleted(TrashInspectionModel trashInspectionModel, bool shouldDelete) { TrashInspectionModel = trashInspectionModel; ShouldDelete = shouldDelete; }
private async Task UpdateProducerAndTransporter(TrashInspection trashInspection, TrashInspectionModel createModel) { var producer = _dbContext.Producers .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) .SingleOrDefault(x => x.Name == createModel.Producer); if (producer == null) { producer = new Producer { Name = createModel.Producer, Address = createModel.ProducerAddress, City = createModel.ProducerCity, ContactPerson = createModel.ProducerContact, Phone = createModel.ProducerPhone, ZipCode = createModel.ProducerZip, ForeignId = createModel.ProducerForeignId, UpdatedByUserId = _userService.UserId, CreatedByUserId = _userService.UserId, }; await producer.Create(_dbContext); } else { producer.Address = createModel.ProducerAddress; producer.City = createModel.ProducerCity; producer.ContactPerson = createModel.ProducerContact; producer.Phone = createModel.ProducerPhone; producer.ZipCode = createModel.ProducerZip; producer.ForeignId = createModel.ProducerForeignId; producer.UpdatedByUserId = _userService.UserId; await producer.Update(_dbContext); } trashInspection.ProducerId = producer.Id; var transporter = _dbContext.Transporters .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) .SingleOrDefault(x => x.Name == createModel.Transporter); if (transporter == null) { transporter = new Transporter { Name = createModel.Transporter, Address = createModel.TransporterAddress, City = createModel.TransporterCity, ZipCode = createModel.TransporterZip, Phone = createModel.TransporterPhone, ContactPerson = createModel.TransporterContact, ForeignId = createModel.TransporterForeignId, UpdatedByUserId = _userService.UserId, CreatedByUserId = _userService.UserId, }; await transporter.Create(_dbContext); } else { transporter.Address = createModel.TransporterAddress; transporter.City = createModel.TransporterCity; transporter.ZipCode = createModel.TransporterZip; transporter.Phone = createModel.TransporterPhone; transporter.ContactPerson = createModel.TransporterContact; transporter.ForeignId = createModel.TransporterForeignId; transporter.UpdatedByUserId = _userService.UserId; await transporter.Update(_dbContext); } trashInspection.TransporterId = transporter.Id; transporter.UpdatedByUserId = _userService.UserId; await trashInspection.Update(_dbContext); }
public async Task <OperationResult> Create(TrashInspectionModel createModel) { var dateTime = DateTime.UtcNow; var pluginConfiguration = await _dbContext.PluginConfigurationValues.SingleOrDefaultAsync(x => x.Name == "TrashInspectionBaseSettings:Token"); if (pluginConfiguration == null) { return(new OperationResult(false)); } if (createModel.Token == pluginConfiguration.Value && createModel.WeighingNumber != null) { try { // Handling the situation, where incoming timestamp is not in UTC. var utcAdjustment = await _dbContext.PluginConfigurationValues.SingleOrDefaultAsync(x => x.Name == "TrashInspectionBaseSettings:UtcAdjustment"); if (utcAdjustment.Value == "true") { if (createModel.Time.Hour > dateTime.Hour) { var timeSpan = createModel.Time.Subtract(dateTime); var minutes = timeSpan.Hours * 60.0 + timeSpan.Minutes; var hours = minutes / 60.0; var fullHours = Math.Round(hours); createModel.Time = createModel.Time.AddHours(-fullHours); } } TrashInspection trashInspection = await _dbContext.TrashInspections.FirstOrDefaultAsync(x => x.WeighingNumber == createModel.WeighingNumber); if (trashInspection != null) { return(new OperationResult(true, trashInspection.Id.ToString())); } trashInspection = new TrashInspection { WeighingNumber = createModel.WeighingNumber, Date = createModel.Date, Time = createModel.Time, EakCode = createModel.EakCode, ExtendedInspection = createModel.ExtendedInspection, RegistrationNumber = createModel.RegistrationNumber, TrashFraction = createModel.TrashFraction, Producer = createModel.Producer, Transporter = createModel.Transporter, MustBeInspected = createModel.MustBeInspected, InspectionDone = false, Status = 0, UpdatedByUserId = _userService.UserId, CreatedByUserId = _userService.UserId, }; await trashInspection.Create(_dbContext); var segment = _dbContext.Segments.FirstOrDefault(x => x.Name == createModel.Segment); var installation = _dbContext.Installations.FirstOrDefault(x => x.Name == createModel.InstallationName); var fraction = _dbContext.Fractions.FirstOrDefault(x => x.ItemNumber == createModel.TrashFraction); _coreHelper.LogEvent($"CreateTrashInspection: Segment: {createModel.Segment}, InstallationName: {createModel.InstallationName}, TrashFraction: {createModel.TrashFraction} "); if (segment != null && installation != null && fraction != null) { trashInspection.SegmentId = segment.Id; trashInspection.FractionId = fraction.Id; trashInspection.InstallationId = installation.Id; await trashInspection.Update(_dbContext); createModel.SegmentId = segment.Id; createModel.FractionId = fraction.Id; createModel.InstallationId = installation.Id; createModel.Id = trashInspection.Id; await UpdateProducerAndTransporter(trashInspection, createModel); _coreHelper.LogEvent($"CreateTrashInspection: Segment: {segment.Name}, InstallationName: {installation.Name}, TrashFraction: {fraction.Name} "); await _bus.SendLocal(new TrashInspectionReceived(createModel, fraction.Id, segment.Id, installation.Id)); } return(new OperationResult(true, createModel.Id.ToString())); } catch (Exception ex) { Console.WriteLine(ex.Message); return(new OperationResult(false)); } } return(new OperationResult(false)); }
#pragma warning disable 1998 public async Task Handle(TrashInspectionCaseCreated message) { TrashInspectionCase trashInspectionCase = await _dbContext.TrashInspectionCases.SingleOrDefaultAsync(x => x.Id == message.TrashInspectionCaseId); LogEvent($"TrashInspectionCaseCreatedHandler.Handle: called for message.TrashInspectionModel.WeighingNumber / message.TrashInspectionCase.Id : {message.TrashInspectionModel.WeighingNumber} / {message.TrashInspectionCaseId}"); CultureInfo cultureInfo = new CultureInfo("de-DE"); int sdkSiteId = trashInspectionCase.SdkSiteId; await using MicrotingDbContext microtingDbContext = _core.DbContextHelper.GetDbContext(); Site site = await microtingDbContext.Sites.SingleAsync(x => x.MicrotingUid == sdkSiteId); Language language = await microtingDbContext.Languages.SingleAsync(x => x.Id == site.LanguageId); LogEvent($"TrashInspectionCaseCreatedHandler: sdkSiteId: {sdkSiteId}, message.TemplateId: {message.TemplateId} "); MainElement mainElement = await _core.ReadeForm(message.TemplateId, language); TrashInspectionModel createModel = message.TrashInspectionModel; Segment segment = await _dbContext.Segments.SingleOrDefaultAsync(x => x.Id == message.SegmentId); Fraction fraction = await _dbContext.Fractions.SingleOrDefaultAsync(x => x.Id == message.FractionId); LogEvent($"TrashInspectionCaseCreatedHandler: Segment: {segment.Name}, TrashFraction: {fraction.Name} "); mainElement.Repeated = 1; mainElement.EndDate = DateTime.Now.AddDays(2).ToUniversalTime(); mainElement.StartDate = DateTime.Now.ToUniversalTime(); await using (var dbContext = _core.DbContextHelper.GetDbContext()) { mainElement.CheckListFolderName = dbContext.Folders.Single(x => x.Id == segment.SdkFolderId).MicrotingUid.ToString(); } mainElement.Label = createModel.RegistrationNumber.ToUpper() + ", " + createModel.Transporter; mainElement.EnableQuickSync = true; mainElement.DisplayOrder = (int)Math.Round(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds) * -1; TimeZoneInfo timeZoneInfo; try { timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Europe/Copenhagen"); } catch { timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("E. Europe Standard Time"); } var localTime = TimeZoneInfo.ConvertTimeFromUtc(createModel.Time, timeZoneInfo); CDataValue cDataValue = new CDataValue { InderValue = $"<b>Vejenr:</b> {createModel.WeighingNumber}<br>" }; cDataValue.InderValue += $"<b>Dato:</b> {createModel.Date.ToString("dd-MM-yyyy") + " " + localTime.ToString("T", cultureInfo)}<br>"; cDataValue.InderValue += $"<b>Område:</b> {segment.Name}<br>"; cDataValue.InderValue += $"<b>Producent:</b> {createModel.Producer}<br>"; cDataValue.InderValue += $"<b>Varenummer:</b> {fraction.ItemNumber} {fraction.Name}"; if (createModel.EakCode != null) { cDataValue.InderValue += $"<br><b>EAK Kode:</b> {createModel.EakCode}"; } mainElement.PushMessageTitle = mainElement.Label; mainElement.PushMessageBody = ""; if (createModel.MustBeInspected && !createModel.ExtendedInspection) { mainElement.PushMessageBody += "*** SKAL INSPICERES ***\n"; cDataValue.InderValue += "<br><br><b>*** SKAL INSPICERES ***</b>"; } if (createModel.ExtendedInspection) { mainElement.PushMessageBody += "*** LOVPLIGTIG KONTROL ***\n"; cDataValue.InderValue += "<br><br><b>*** LOVPLIGTIG KONTROL ***</b>"; mainElement.Color = Constants.CheckListColors.Red; } mainElement.PushMessageBody += $"Vare: {fraction.Name}\n"; if (createModel.Producer.Length > 17) { mainElement.PushMessageBody += $"Producent: {createModel.Producer.Substring(0,17)}..."; } else { mainElement.PushMessageBody += $"Producent: {createModel.Producer}"; } mainElement.ElementList[0].Description = cDataValue; mainElement.ElementList[0].Label = mainElement.Label; DataElement dataElement = (DataElement)mainElement.ElementList[0]; dataElement.DataItemList[0].Label = mainElement.Label; dataElement.DataItemList[0].Description = cDataValue; if (createModel.MustBeInspected || createModel.ExtendedInspection) { dataElement.DataItemList[0].Color = Constants.FieldColors.Red; } LogEvent("CreateTrashInspection: Trying to create SDK case"); int?sdkCaseId = await _core.CaseCreate(mainElement, "", sdkSiteId, segment.SdkFolderId); LogEvent($"CreateTrashInspection: SDK case created and got id {sdkCaseId}"); trashInspectionCase.SdkCaseId = sdkCaseId.ToString(); trashInspectionCase.Status = 66; await trashInspectionCase.Update(_dbContext); var trashInspectionCases = _dbContext.TrashInspectionCases.AsNoTracking().Where(x => x.TrashInspectionId == trashInspectionCase.TrashInspectionId); bool allDone = true; foreach (TrashInspectionCase inspectionCase in trashInspectionCases) { if (inspectionCase.Status < 66) { allDone = false; } } if (allDone) { var trashInspection = await _dbContext.TrashInspections.SingleOrDefaultAsync(x => x.Id == trashInspectionCase.TrashInspectionId); if (trashInspection.Status < 66) { trashInspection.Status = 66; await trashInspection.Update(_dbContext); } } }
#pragma warning disable 1998 public async Task Handle(TrashInspectionReceived message) { LogEvent($"TrashInspectionReceivedHandler.Handle: called for message.TrashInspectionModel.WeighingNumber {message.TrashInspectionModel.WeighingNumber}"); TrashInspectionModel createModel = message.TrashInspectionModel; Fraction fraction = message.Fraction; Segment segment = message.Segment; Installation installation = message.Installation; int eFormId = fraction.eFormId; if (createModel.ExtendedInspection) { var result = await _dbContext.PluginConfigurationValues.SingleOrDefaultAsync(x => x.Name == "TrashInspectionBaseSettings:ExtendedInspectioneFormId"); eFormId = int.Parse(result.Value); } List <InstallationSite> installationSites = _dbContext.InstallationSites.Where(x => x.InstallationId == installation.Id && x.WorkflowState != Constants.WorkflowStates.Removed).ToList(); CultureInfo cultureInfo = new CultureInfo("de-DE"); await using MicrotingDbContext microtingDbContext = _core.DbContextHelper.GetDbContext(); // List<Task> tasks = new List<Task>(); foreach (InstallationSite installationSite in installationSites) { Site site = await microtingDbContext.Sites.SingleAsync(x => x.MicrotingUid == installationSite.SDKSiteId); Language language = await microtingDbContext.Languages.SingleAsync(x => x.Id == site.LanguageId); var mainElement = _core.ReadeForm(eFormId, language); if (mainElement == null) { return; } TrashInspectionCase trashInspectionCase = new TrashInspectionCase { SegmentId = segment.Id, Status = 0, TrashInspectionId = createModel.Id, SdkSiteId = installationSite.SDKSiteId, }; await trashInspectionCase.Create(_dbContext); LogEvent("TrashInspectionReceivedHandler: trashInspectionCase created dispatching TrashInspectionCaseCreated"); LogEvent($"TrashInspectionReceivedHandler: Segment: {segment.Name}, InstallationName: {installation.Name}, TrashFraction: {fraction.Name} "); if (eFormId != 0) { await _bus.SendLocal(new TrashInspectionCaseCreated(eFormId, trashInspectionCase.Id, createModel, segment.Id, fraction.Id)); } // tasks.Add(sendLocal); LogEvent("TrashInspectionReceivedHandler: trashInspectionCase created TrashInspectionCaseCreated dispatched"); } // await Task.WhenAll(tasks); var trashInspection = await _dbContext.TrashInspections.SingleAsync(x => x.Id == createModel.Id); if (trashInspection.Status < 33) { trashInspection.Status = 33; await trashInspection.Update(_dbContext); } }
public async Task <OperationResult> Update([FromBody] TrashInspectionModel updateModel) { return(await _trashInspectionService.Update(updateModel)); }
public async Task <OperationResult> Create([FromBody] TrashInspectionModel createModel) { return(await _trashInspectionService.Create(createModel)); }