public async Task <IActionResult> AddTemplate(TemplateDetailAC templateDetailAC) { string userId = HttpContext.User.Claims.FirstOrDefault(c => c.Type == "user_id").Value; string fullname = HttpContext.User.Claims.FirstOrDefault(c => c.Type == "fullname").Value; return(Ok(await _iTemplateRepository.AddTemplate(Convert.ToInt64(userId), templateDetailAC, fullname))); }
public ActionResult <Template> PostTemplate(TemplateDTO templatedto) { var naam = templatedto.Naam; if (naam == null || naam == "") { return(BadRequest()); } var template = new Template(naam); _templateRepository.AddTemplate(template); _templateRepository.SaveChanges(); return(CreatedAtAction(nameof(GetTemplateById), new { id = template.Id }, GetTemplateById(template.Id).Value)); }
public async Task <IActionResult> UploadNewChecklist(IFormFile checklistFile, string description = "") { try { _logger.LogInformation("Calling UploadNewChecklist()"); var name = checklistFile.FileName; string rawChecklist = string.Empty; using (var reader = new StreamReader(checklistFile.OpenReadStream())) { rawChecklist = reader.ReadToEnd(); } _logger.LogInformation("UploadNewChecklist() Making the template"); Template t = MakeTemplateRecord(rawChecklist); if (t != null && !string.IsNullOrEmpty(description)) { t.description = description; } // grab the user/system ID from the token if there which is *should* always be var claim = this.User.Claims.Where(x => x.Type == System.Security.Claims.ClaimTypes.NameIdentifier).FirstOrDefault(); if (claim != null) // get the value { t.createdBy = Guid.Parse(claim.Value); } _logger.LogInformation("UploadNewChecklist() template created, saving to the database"); var record = await _TemplateRepo.AddTemplate(t); _logger.LogInformation("Called UploadNewChecklist() and added checklists successfully"); if (record != null) { record.rawChecklist = ""; // remove this we do not need it here } // publish an audit event _logger.LogInformation("UploadNewChecklist() publish an audit message on a new template {0}.", name); Audit newAudit = GenerateAuditMessage(claim, "upload new template"); newAudit.message = string.Format("UploadNewChecklist() delete a single template {0}.", name); newAudit.url = string.Format("POST checklistFile={0}", name); _msgServer.Publish("openrmf.audit.save", Encoding.UTF8.GetBytes(Compression.CompressString(JsonConvert.SerializeObject(newAudit)))); _msgServer.Flush(); return(Ok(record)); } catch (Exception ex) { _logger.LogError(ex, "UploadNewChecklist() Error uploading template checklist file"); return(BadRequest()); } }