Пример #1
0
    public async Task <IActionResult> OnPostCreateTemplateVersion()
    {
        // TODO: Error handling
        TemplateTbl?template = (await _templateTbl.Get(x => x.Id.Equals(CreateTemplateVersion.TemplateId), null, nameof(TemplateTbl.Versions))).FirstOrDefault();

        if (template == null)
        {
            throw new NullReferenceException();
        }

        CreateTemplateVersion.Name     = "Untitled name";
        CreateTemplateVersion.Subject  = "Default subject";
        CreateTemplateVersion.Html     = string.Empty;
        CreateTemplateVersion.TestData = "{}";
        if (!template.Versions?.Any() ?? true)
        {
            CreateTemplateVersion.IsActive = true;
        }

        TemplateVersionTbl result = await _templateVersionTbl.Add(CreateTemplateVersion);

        await _projectTbl.UpdateFromQuery(x => x.Id.Equals(MarkAsActive.ProjectId), _ => new ProjectTbl
        {
            DateModified = DateTime.Now
        });

        TempData["toastStatus"]  = "success";
        TempData["toastMessage"] = "Template version created";
        TempData["scrollToId"]   = $"version-{result.Id}";

        return(RedirectToPage("/Project/Details", new { id = template.ProjectId }));
    }
Пример #2
0
    public async Task <IActionResult> OnPostDuplicateTemplateVersion()
    {
        // TODO: Error handling
        TemplateVersionTbl?version = (await _templateVersionTbl.Get(x =>
                                                                    x.Id.Equals(DuplicateTemplateVersion.VersionId) &&
                                                                    x.TemplateId.Equals(DuplicateTemplateVersion.TemplateId) &&
                                                                    x.Template !.ProjectId.Equals(DuplicateTemplateVersion.ProjectId)))
                                     .FirstOrDefault();

        if (version == null)
        {
            throw new NullReferenceException(nameof(version));
        }

        TemplateVersionTbl result = await _templateVersionTbl.Add(new TemplateVersionTbl
        {
            Name       = $"{version.Name}_copy",
            Subject    = version.Subject,
            TestData   = version.TestData,
            Html       = version.Html,
            Categories = version.Categories,
            TemplateId = version.TemplateId
        });

        await _templateTbl.UpdateFromQuery(x => x.Id.Equals(MarkAsActive.TemplateId), _ => new TemplateTbl
        {
            DateModified = DateTime.Now
        });

        await _projectTbl.UpdateFromQuery(x => x.Id.Equals(MarkAsActive.ProjectId), _ => new ProjectTbl
        {
            DateModified = DateTime.Now
        });

        TempData["toastStatus"]  = "success";
        TempData["toastMessage"] = "Template version duplicated";
        TempData["scrollToId"]   = $"version-{result.Id}";

        return(RedirectToPage("/Project/Details", new { id = DuplicateTemplateVersion.ProjectId }));
    }