Beispiel #1
0
        public async Task <OperationDataResult <SegmentsModel> > Index(SegmentRequestModel pnRequestModel)
        {
            try
            {
                SegmentsModel segmentsModel = new SegmentsModel();

                IQueryable <Segment> segmentQuery = _dbContext.Segments.AsQueryable();
                if (!string.IsNullOrEmpty(pnRequestModel.Sort))
                {
                    if (pnRequestModel.IsSortDsc)
                    {
                        segmentQuery = segmentQuery
                                       .CustomOrderByDescending(pnRequestModel.Sort);
                    }
                    else
                    {
                        segmentQuery = segmentQuery
                                       .CustomOrderBy(pnRequestModel.Sort);
                    }
                }
                else
                {
                    segmentQuery = _dbContext.Segments
                                   .OrderBy(x => x.Id);
                }

                segmentQuery
                    = segmentQuery
                      .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                      .Skip(pnRequestModel.Offset)
                      .Take(pnRequestModel.PageSize);

                List <SegmentModel> segmentModels = await segmentQuery.Select(x => new SegmentModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    SdkFolderId = x.SdkFolderId
                }).ToListAsync();

                segmentsModel.Total = await _dbContext.Segments.CountAsync(x => x.WorkflowState != Constants.WorkflowStates.Removed);

                segmentsModel.SegmentList = segmentModels;
                Core _core = await _coreHelper.GetCore();


                return(new OperationDataResult <SegmentsModel>(true, segmentsModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _coreHelper.LogException(e.Message);
                return(new OperationDataResult <SegmentsModel>(false,
                                                               _trashInspectionLocalizationService.GetString("ErrorObtainingSegments")));
            }
        }
Beispiel #2
0
        public async Task <OperationResult> Update(FolderUpdateModel folderUpdateModel)
        {
            var core = await _coreHelper.GetCore();

            try
            {
                await using var sdkDbContext = core.DbContextHelper.GetDbContext();
                //var names = new List<KeyValuePair<string, string>>();
                //var descriptions = new List<KeyValuePair<string, string>>();
                //var languages = await sdkDbContext.Languages
                //    .Select(x => new {x.LanguageCode, x.Id})
                //    .ToListAsync();

                //foreach (var folderTranslationModel in folderUpdateModel.Translations)
                //{
                //    var languageCode = languages
                //        .First(y => y.Id == folderTranslationModel.LanguageId).LanguageCode;
                //    names.Add(new KeyValuePair<string, string>(languageCode, folderTranslationModel.Name));
                //    descriptions.Add(
                //        new KeyValuePair<string, string>(languageCode, folderTranslationModel.Description));
                //}

                var folder = await sdkDbContext.Folders.SingleOrDefaultAsync(x => x.Id == folderUpdateModel.Id);

                //await core.FolderUpdate(
                //    folderUpdateModel.Id,
                //    names,
                //    descriptions,
                //    folder.ParentId);

                var folderTranslations = folderUpdateModel.Translations
                                         .Select(x => new CommonTranslationsModel
                {
                    Name        = x.Name,
                    Description = x.Description,
                    LanguageId  = x.LanguageId,
                }).ToList();

                await core.FolderUpdate(folderUpdateModel.Id, folderTranslations, folder.ParentId);

                return(new OperationResult(true));
            }
            catch (Exception e)
            {
                _coreHelper.LogException(e.Message);
                _logger.LogError(e, e.Message);
                return(new OperationResult(
                           false,
                           _localizationService.GetString("ErrorWhileUpdatingFolder")));
            }
        }
Beispiel #3
0
        public async Task <OperationDataResult <InstallationsModel> > Index(InstallationRequestModel pnRequestModel)
        {
            try
            {
                var installationsModel = new InstallationsModel();

                var installationsQuery = _dbContext.Installations
                                         .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                                         .AsQueryable();

                if (!pnRequestModel.NameFilter.IsNullOrEmpty() && pnRequestModel.NameFilter != "")
                {
                    installationsQuery = installationsQuery.Where(x => x.Name.Contains(pnRequestModel.NameFilter));
                }

                QueryHelper.AddSortToQuery(installationsQuery, pnRequestModel.Sort, pnRequestModel.IsSortDsc);

                installationsModel.Total = installationsQuery.Count();

                installationsQuery
                    = installationsQuery
                      .Skip(pnRequestModel.Offset)
                      .Take(pnRequestModel.PageSize);

                var installations = await installationsQuery.Select(x => new InstallationModel
                {
                    Id   = x.Id,
                    Name = x.Name
                }).ToListAsync();

                installationsModel.InstallationList = installations;


                return(new OperationDataResult <InstallationsModel>(true, installationsModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _coreHelper.LogException(e.Message);
                return(new OperationDataResult <InstallationsModel>(false,
                                                                    _trashInspectionLocalizationService.GetString("ErrorObtainingInstallations")));
            }
        }
Beispiel #4
0
        public async Task <OperationDataResult <UploadedDatasModel> > Index(int itemCaseId)
        {
            try
            {
                UploadedDatasModel uploadedDatasModel = new UploadedDatasModel();

                IQueryable <UploadedData> uploadedDataQuery = _dbContext.UploadedDatas.AsQueryable();

                uploadedDataQuery
                    = uploadedDataQuery
                      .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed && x.ItemCaseId == itemCaseId);

                List <UploadedDataModel> uploadedDatas = await uploadedDataQuery.Select(x => new UploadedDataModel()
                {
                    Id           = x.Id,
                    Checksum     = x.Checksum,
                    CurrentFile  = x.CurrentFile,
                    Extension    = x.Extension,
                    FileLocation = x.FileLocation,
                    FileName     = x.FileName,
                    ItemCaseId   = x.ItemCaseId,
                    UploaderType = x.UploaderType
                }).ToListAsync();

                uploadedDatasModel.Total =
                    _dbContext.UploadedDatas.Count(x => x.WorkflowState != Constants.WorkflowStates.Removed);
                uploadedDatasModel.UploadedDatas = uploadedDatas;

                return(new OperationDataResult <UploadedDatasModel>(true, uploadedDatasModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _core.LogException(e.Message);
                return(new OperationDataResult <UploadedDatasModel>(false,
                                                                    _itemsPlanningLocalizationService.GetString("ErrorObtainingUploadedDatas")));
            }
        }
        public async Task <string> DownloadEFormPdf(string weighingNumber, string token, string fileType)
        {
            var trashInspectionSettings = _options.Value.Token;

            _coreHelper.LogEvent($"DownloadEFormPdf: weighingNumber is {weighingNumber} token is {token}");
            if (token == trashInspectionSettings && weighingNumber != null)
            {
                try
                {
                    var core = await _coreHelper.GetCore();

                    string microtingUId;
                    string microtingCheckUId;
                    var    caseId          = 0;
                    var    eFormId         = 0;
                    var    trashInspection = await _dbContext.TrashInspections.Select(x => new TrashInspectionModel
                    {
                        Id                 = x.Id,
                        Date               = x.Date,
                        EakCode            = x.EakCode,
                        InstallationId     = x.InstallationId,
                        MustBeInspected    = x.MustBeInspected,
                        Producer           = x.Producer,
                        RegistrationNumber = x.RegistrationNumber,
                        Time               = x.Time,
                        Transporter        = x.Transporter,
                        TrashFraction      = x.TrashFraction,
                        WeighingNumber     = x.WeighingNumber,
                        Status             = x.Status,
                        Version            = x.Version,
                        WorkflowState      = x.WorkflowState,
                        ExtendedInspection = x.ExtendedInspection,
                        InspectionDone     = x.InspectionDone,
                        SegmentId          = x.SegmentId
                    })
                                             .FirstOrDefaultAsync(x => x.WeighingNumber == weighingNumber);

                    var fraction = await _dbContext.Fractions.SingleOrDefaultAsync(x => x.ItemNumber == trashInspection.TrashFraction);

                    if (fraction == null)
                    {
                        fraction = await _dbContext.Fractions.SingleOrDefaultAsync(x => x.Name == trashInspection.TrashFraction);
                    }
                    _coreHelper.LogEvent($"DownloadEFormPdf: fraction is {fraction.Name}");

                    var segmentName = "";

                    var segment = await _dbContext.Segments.SingleOrDefaultAsync(x => x.Id == trashInspection.SegmentId);

                    if (segment != null)
                    {
                        segmentName = segment.Name;
                    }
                    _coreHelper.LogEvent($"DownloadEFormPdf: segmentName is {segmentName}");

                    var xmlContent = new XElement("TrashInspection",
                                                  new XElement("EakCode", trashInspection.EakCode),
                                                  new XElement("Producer", trashInspection.Producer),
                                                  new XElement("RegistrationNumber", trashInspection.RegistrationNumber),
                                                  new XElement("Transporter", trashInspection.Transporter),
                                                  new XElement("WeighingNumber", trashInspection.WeighingNumber),
                                                  new XElement("Segment", segmentName),
                                                  new XElement("noImageTitle", "true"),
                                                  new XElement("TrashFraction", $"{fraction.ItemNumber} {fraction.Name}")
                                                  ).ToString();
                    _coreHelper.LogEvent($"DownloadEFormPdf: xmlContent is {xmlContent}");

                    foreach (var trashInspectionCase in _dbContext.TrashInspectionCases.Where(x => x.TrashInspectionId == trashInspection.Id).ToList())
                    {
                        if (trashInspectionCase.Status == 100)
                        {
                            var caseDto = await core.CaseLookupMUId(int.Parse(trashInspectionCase.SdkCaseId));

                            microtingUId      = caseDto.MicrotingUId.ToString();
                            microtingCheckUId = caseDto.CheckUId.ToString();
                            caseId            = (int)caseDto.CaseId;
                            eFormId           = caseDto.CheckListId;
                        }
                    }

                    if (caseId != 0 && eFormId != 0)
                    {
                        _coreHelper.LogEvent($"DownloadEFormPdf: caseId is {caseId}, eFormId is {eFormId}");
                        await using var sdkDbContext = core.DbContextHelper.GetDbContext();
                        var language = await sdkDbContext.Languages.SingleAsync(x => x.LanguageCode == "da");

                        var filePath = await core.CaseToPdf(caseId, eFormId.ToString(),
                                                            DateTime.Now.ToString("yyyyMMddHHmmssffff"),
                                                            $"{await core.GetSdkSetting(Settings.httpServerAddress)}/" + "api/template-files/get-image/", fileType, xmlContent, language);

                        if (!File.Exists(filePath))
                        {
                            throw new FileNotFoundException();
                        }

                        return(filePath);
                    }

                    throw new Exception("could not find case of eform!");
                }
                catch (Exception exception)
                {
                    _coreHelper.LogException($"DownloadEFormPdf: We got the following exception: {exception.Message}");
                    throw new Exception("Something went wrong!", exception);
                }
            }

            throw new UnauthorizedAccessException();
        }
Beispiel #6
0
        public async Task <OperationDataResult <Paged <FractionModel> > > Index(FractionRequestModel pnRequestModel)
        {
            try
            {
                var fractionsModel = new Paged <FractionModel>();

                var fractionsQuery = _dbContext.Fractions
                                     .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                                     .AsQueryable();
                //if (!pnRequestModel.NameFilter.IsNullOrEmpty() && pnRequestModel.NameFilter != "")
                //{
                //    fractionsQuery = fractionsQuery.Where(x =>
                //        x.Name.Contains(pnRequestModel.NameFilter) ||
                //        x.Description.Contains(pnRequestModel.NameFilter));
                //}

                fractionsQuery = QueryHelper.AddSortToQuery(fractionsQuery, pnRequestModel.Sort, pnRequestModel.IsSortDsc);

                fractionsModel.Total = await fractionsQuery.Select(x => x.Id).CountAsync();

                fractionsQuery
                    = fractionsQuery
                      .Skip(pnRequestModel.Offset)
                      .Take(pnRequestModel.PageSize);

                var fractions = await fractionsQuery
                                .Select(x => new FractionModel
                {
                    Id           = x.Id,
                    Name         = x.Name,
                    eFormId      = x.eFormId,
                    Description  = x.Description,
                    LocationCode = x.LocationCode,
                    ItemNumber   = x.ItemNumber
                })
                                .ToListAsync();

                fractionsModel.Entities = fractions;
                var core = await _coreHelper.GetCore();

                var eFormNames = new List <KeyValuePair <int, string> >();

                var locale = await _userService.GetCurrentUserLocale();

                var language = core.DbContextHelper.GetDbContext().Languages.Single(x => x.LanguageCode == locale);
                foreach (var fractionModel in fractionsModel.Entities)
                {
                    if (fractionModel.eFormId > 0)
                    {
                        if (eFormNames.Any(x => x.Key == fractionModel.eFormId))
                        {
                            fractionModel.SelectedTemplateName = eFormNames.First(x => x.Key == fractionModel.eFormId).Value;
                        }
                        else
                        {
                            try
                            {
                                var eFormName = core.TemplateItemRead(fractionModel.eFormId, language).Result.Label;
                                fractionModel.SelectedTemplateName = eFormName;
                                var kvp =
                                    new KeyValuePair <int, string>(fractionModel.eFormId, eFormName);
                                eFormNames.Add(kvp);
                            }
                            catch
                            {
                                var kvp = new KeyValuePair <int, string>(fractionModel.eFormId, "");
                                eFormNames.Add(kvp);
                            }
                        }
                    }
                }

                return(new OperationDataResult <Paged <FractionModel> >(true, fractionsModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _coreHelper.LogException(e.Message);
                return(new OperationDataResult <Paged <FractionModel> >(false,
                                                                        _trashInspectionLocalizationService.GetString("ErrorObtainingFractions")));
            }
        }
Beispiel #7
0
        public async Task <OperationDataResult <TransportersModel> > Index(TransporterRequestModel pnRequestModel)
        {
            try
            {
                var transportersModel = new TransportersModel();

                var transporterQuery = _dbContext.Transporters.AsQueryable();

                if (!pnRequestModel.NameFilter.IsNullOrEmpty() && pnRequestModel.NameFilter != "")
                {
                    transporterQuery = transporterQuery.Where(x =>
                                                              x.Name.Contains(pnRequestModel.NameFilter) ||
                                                              x.Description.Contains(pnRequestModel.NameFilter));
                }
                if (!string.IsNullOrEmpty(pnRequestModel.Sort))
                {
                    if (pnRequestModel.IsSortDsc)
                    {
                        transporterQuery = transporterQuery
                                           .CustomOrderByDescending(pnRequestModel.Sort);
                    }
                    else
                    {
                        transporterQuery = transporterQuery
                                           .CustomOrderBy(pnRequestModel.Sort);
                    }
                }
                else
                {
                    transporterQuery = _dbContext.Transporters
                                       .OrderBy(x => x.Id);
                }

                transporterQuery
                    = transporterQuery
                      .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                      .Skip(pnRequestModel.Offset)
                      .Take(pnRequestModel.PageSize);
                var transporters = await transporterQuery.Select(x => new TransporterModel
                {
                    Id            = x.Id,
                    Name          = x.Name,
                    Description   = x.Description,
                    ForeignId     = x.ForeignId,
                    Address       = x.Address,
                    City          = x.City,
                    ZipCode       = x.ZipCode,
                    Phone         = x.Phone,
                    ContactPerson = x.ContactPerson
                }).ToListAsync();

                transportersModel.Total =
                    _dbContext.Transporters.Count(x => x.WorkflowState != Constants.WorkflowStates.Removed);
                transportersModel.TransporterList = transporters;

                return(new OperationDataResult <TransportersModel>(true, transportersModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _coreHelper.LogException(e.Message);
                return(new OperationDataResult <TransportersModel>(false,
                                                                   _trashInspectionLocalizationService.GetString("ErrorObtainingTransporters")));
            }
        }
        public async Task <OperationResult> ImportUnit(UnitImportModel unitAsJson)
        {
            try
            {
                {
                    JToken rawJson        = JRaw.Parse(unitAsJson.ImportList);
                    JToken rawHeadersJson = JRaw.Parse(unitAsJson.Headers);

                    JToken headers = rawHeadersJson;
                    IEnumerable <JToken> itemObjects = rawJson.Skip(1);

                    foreach (JToken itemObj in itemObjects)
                    {
                        bool numberExists   = int.TryParse(headers[0]["headerValue"].ToString(), out int numberColumn);
                        bool itemNameExists = int.TryParse(headers[1]["headerValue"].ToString(),
                                                           out int nameColumn);
                        if (numberExists || itemNameExists)
                        {
                            Item existingItem = FindItem(numberExists, numberColumn, itemNameExists,
                                                         nameColumn, headers, itemObj);
                            if (existingItem == null)
                            {
                                ItemsListPnItemModel itemModel =
                                    ItemsHelper.ComposeValues(new ItemsListPnItemModel(), headers, itemObj);

                                Item newItem = new Item
                                {
                                    ItemNumber   = itemModel.ItemNumber,
                                    Name         = itemModel.Name,
                                    Description  = itemModel.Description,
                                    LocationCode = itemModel.LocationCode,
                                };
                                await newItem.Save(_dbContext);
                            }
                            else
                            {
                                if (existingItem.WorkflowState == Constants.WorkflowStates.Removed)
                                {
                                    Item item = await _dbContext.Items.SingleOrDefaultAsync(x => x.Id == existingItem.Id);

                                    if (item != null)
                                    {
                                        item.Name          = existingItem.Name;
                                        item.Description   = existingItem.Description;
                                        item.ItemNumber    = existingItem.ItemNumber;
                                        item.LocationCode  = existingItem.LocationCode;
                                        item.WorkflowState = Constants.WorkflowStates.Created;

                                        await item.Update(_dbContext);
                                    }
                                }
                            }
                        }
                    }
                }
                return(new OperationResult(true,
                                           _itemsPlanningLocalizationService.GetString("ItemImportes")));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _coreHelper.LogException(e.Message);
                return(new OperationResult(false,
                                           _itemsPlanningLocalizationService.GetString("ErrorWhileImportingItems")));
            }
        }