Example #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 }));
    }
Example #2
0
 public int Add(TemplateVersionDomain templateVersion)
 {
     if (templateVersion == null)
     {
         throw new NsiArgumentException(ExceptionMessages.ArgumentException);
     }
     return(_templateVersionRepository.Add(templateVersion));
 }
        public async Task <IActionResult> CreateTemplateVersion(long id, [FromBody] VersionCreateInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(JsonBadRequest("Invalid inputs."));
            }
            if (model.PreprocessGitModel != null && !model.PreprocessGitModel.IsValid())
            {
                return(JsonBadRequest($"The input about Preprocess Git is not valid."));
            }
            if (model.TrainingGitModel != null && !model.TrainingGitModel.IsValid())
            {
                return(JsonBadRequest($"The input about Training Git is not valid."));
            }
            if (model.EvaluationGitModel != null && !model.EvaluationGitModel.IsValid())
            {
                return(JsonBadRequest($"The input about Evaluation Git is not valid."));
            }

            var template = await templateRepository.GetByIdAsync(id);

            if (template == null)
            {
                return(JsonNotFound($"Template ID {id} is not found."));
            }
            template.LatestVersion += 1;
            templateRepository.Update(template);

            var templateVersion = new TemplateVersion();
            var errorResult     = await SetTemplateDetails(templateVersion, template, model);

            if (errorResult != null)
            {
                return(errorResult);
            }

            templateVersionRepository.Add(templateVersion);
            unitOfWork.Commit();
            return(JsonCreated(new VersionIndexOutputModel(templateVersion)));
        }