Ejemplo n.º 1
0
        public UploadedDataVersion MapVersion(CaseTemplatePnDbContext dbContext, UploadedData uploadedData)
        {
            UploadedDataVersion uploadedDataVersion = new UploadedDataVersion();

            uploadedDataVersion.Checksum         = uploadedData.Checksum;
            uploadedDataVersion.Extension        = uploadedData.Extension;
            uploadedDataVersion.CurrentFile      = uploadedData.CurrentFile;
            uploadedDataVersion.UploaderType     = uploadedData.UploaderType;
            uploadedDataVersion.FileLocation     = uploadedData.FileLocation;
            uploadedDataVersion.FileName         = uploadedData.FileName;
            uploadedDataVersion.ExpirationDate   = uploadedData.ExpirationDate;
            uploadedDataVersion.Local            = uploadedData.Local;
            uploadedDataVersion.OriginalFileName = uploadedData.OriginalFileName;

            uploadedDataVersion.Version         = uploadedData.Version;
            uploadedDataVersion.CreatedAt       = uploadedData.CreatedAt;
            uploadedDataVersion.UpdatedAt       = uploadedData.UpdatedAt;
            uploadedDataVersion.CreatedByUserId = uploadedData.CreatedByUserId;
            uploadedDataVersion.UpdatedByUserId = uploadedData.UpdatedByUserId;
            uploadedDataVersion.WorkflowState   = uploadedData.WorkflowState;

            uploadedDataVersion.UploadedDataId = uploadedData.Id;

            return(uploadedDataVersion);
        }
Ejemplo n.º 2
0
        public void Update(CaseTemplatePnDbContext dbContext)
        {
            UploadedData uploadedData = dbContext.UploadedDatas.FirstOrDefault(x => x.Id == Id);

            if (uploadedData == null)
            {
                throw new NullReferenceException($"Could not find Uploaded Data with ID {Id}");
            }

            uploadedData.Checksum         = Checksum;
            uploadedData.Extension        = Extension;
            uploadedData.CurrentFile      = CurrentFile;
            uploadedData.UploaderType     = UploaderType;
            uploadedData.FileLocation     = FileLocation;
            uploadedData.FileName         = FileName;
            uploadedData.ExpirationDate   = ExpirationDate;
            uploadedData.Local            = Local;
            uploadedData.OriginalFileName = OriginalFileName;

            if (dbContext.ChangeTracker.HasChanges())
            {
                uploadedData.UpdatedAt = DateTime.Now;
                uploadedData.Version  += 1;

                dbContext.UploadedDataVersions.Add(MapVersion(dbContext, uploadedData));
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public void Delete(CaseTemplatePnDbContext dbContext)
        {
            UploadedData uploadedData = dbContext.UploadedDatas.FirstOrDefault(x => x.Id == Id);

            if (uploadedData == null)
            {
                throw new NullReferenceException($"Could not find Uploaded Data with ID {Id}");
            }


            uploadedData.WorkflowState = Constants.WorkflowStates.Removed;

            if (dbContext.ChangeTracker.HasChanges())
            {
                uploadedData.UpdatedAt = DateTime.Now;
                uploadedData.Version  += 1;

                dbContext.UploadedDataVersions.Add(MapVersion(dbContext, uploadedData));
                dbContext.SaveChanges();
            }
        }
        public async Task <OperationResult> CreateCaseTemplate(int id)
        {
            try
            {
                Core _core = new Core();
                _core.StartSqlOnly(
                    "host= localhost;Database=759_SDK;user = root;port=3306;Convert Zero Datetime = true;SslMode=none;");

                Dictionary <int, string> laRoutes = new Dictionary <int, string>()
                {
                    { 24, "Århus H - Aalborg" },
                    { 25, "Aalborg - Lindholm" }
                };

                string checkSum;

                DateTime dt            = DateTime.Now;
                var      dayofWeek     = dt.AddDays(1).ToString("dddd", new System.Globalization.CultureInfo("da-DK"));
                var      dayOfWeek2    = dt.AddDays(2).ToString("dddd", new System.Globalization.CultureInfo("da-DK"));
                var      date          = dt.AddDays(1).ToString("dd");
                var      date2         = dt.AddDays(2).ToString("dd");
                var      monthOfYear   = dt.ToString("MMMM", new System.Globalization.CultureInfo("da-DK"));
                var      year          = dt.ToString("yyyy");
                string   dateFormatted = dt.ToString("-yyyy-MM-dd-yyyy-MM-dd");
                string   laNumber;
                string   laTitle;

                foreach (KeyValuePair <int, string> entry in laRoutes)
                {
                    laNumber = entry.Key.ToString();
                    laTitle  = "La-" + laNumber + dateFormatted;

                    CaseTemplate existingCaseTemplate = await _dbContext.CaseTemplates.SingleOrDefaultAsync(x =>
                                                                                                            x.Title == entry.Value && x.StartAt.ToString("dd-MM-yyyy") == dt.AddDays(1).ToString("dd-MM-yyyy") &&
                                                                                                            x.EndAt.ToString("dd-MM-yyyy") == dt.AddDays(2).ToString("dd-MM-yyyy"));

                    if (existingCaseTemplate == null)
                    {
                        string fileCheckSum = GetLa(laNumber, _core);
                        checkSum = fileCheckSum;

                        MainElement mainElement = _core.TemplateRead(9);
                        mainElement.Repeated                   = 1;
                        mainElement.Label                      = $"Banedanmark LA: {entry.Value}";
                        mainElement.ElementList[0].Label       = mainElement.Label;
                        mainElement.ElementList[0].Description = new CDataValue()

                        {
                            InderValue =
                                $"Fra: {dayofWeek} den {date}. {monthOfYear} {year}<br>Til: {dayOfWeek2} den {date2}. {monthOfYear} {year}"
                        };

                        DataElement dataElement = (DataElement)mainElement.ElementList[0];
                        dataElement.DataItemList[0].Label = entry.Value;
                        ShowPdf showPdf = (ShowPdf)dataElement.DataItemList[1];
                        showPdf.Value = fileCheckSum;

                        CaseTemplate newCaseTemplate = new CaseTemplate();
                        newCaseTemplate.Title    = entry.Value;
                        newCaseTemplate.StartAt  = dt.AddDays(1);
                        newCaseTemplate.EndAt    = dt.AddDays(2);
                        newCaseTemplate.PdfTitle = fileCheckSum;
                        newCaseTemplate.Create(_dbContext);

                        List <SiteName_Dto> sites = _core.Advanced_SiteItemReadAll(false);

                        foreach (var site in sites)
                        {
                            int?sdkCaseId = _core.CaseCreate(mainElement, "", site.SiteUId);

                            CaseTemplateSite caseTemplateSite = new CaseTemplateSite()
                            {
                                CaseTemplateId = newCaseTemplate.Id,
                                SdkSiteId      = site.SiteUId,
                                SdkCaseId      = (int)sdkCaseId
                            };

                            caseTemplateSite.Create(_dbContext);
                        }
                    }

                    UploadedData existingUploadedData = await _dbContext.UploadedDatas.SingleOrDefaultAsync(x =>
                                                                                                            x.FileName == laTitle);

                    if (existingUploadedData == null)
                    {
                        UploadedData uploadedData = new UploadedData()
                        {
                            FileName       = laTitle,
                            ExpirationDate = existingCaseTemplate.EndAt
                        };

                        uploadedData.Create(_dbContext);
                    }
                }

                return(new OperationResult(true, "Created successfully"));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                return(new OperationDataResult <CaseTemplatesModel>(false,
                                                                    _baneDanmarkLaLocalizationService.GetString("Failure creating LA") + $" {e.Message}"));
            }
        }