public static Process ToDataModel(this Contracts.Process.CreateProcess create, RAAPEntities db) { var process = new Process { Enabled = create.Enabled, Name = create.Name, Description = create.Description, ProcessCategory = db.ProcessCategories.FirstOrDefault(c => c.ProcessCategoryId == create.Category.ProcessCategoryId), CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now, ResponsibleUserId = create.ResponsibleUserId ?? null, }; create.Evaluations.Where(e => !string.IsNullOrEmpty(e.Text)).OrderBy(e => e.Revision).ForEach(e => process.HtmlComments.Add(e.ToDataModel(db, process))); create.Risks.ForEach(r => process.ThreatRisks.Add(r.ToDataModel())); return(process); }
public Contracts.Process.Process Create(Contracts.Process.CreateProcess createProcess) { using (var db = new RAAPEntities(GetConnectionString())) { if (db.Processes.Any(a => a.Name == createProcess.Name)) { throw new RAAPConflictException("Name is already in use, please try another name."); } if (createProcess.Category == null) { throw new RAAPConflictException("Category is not selected."); } RiskCalculator.CheckRiskTypes(createProcess, db); var process = createProcess.ToDataModel(db); AddAssets(db, process, createProcess.Assets); db.Processes.Add(process); RiskCalculator.CalculateRisk(process); db.SaveChanges(); return(process.ToContract(_userService)); } }
public IHttpActionResult Post([FromBody] Contracts.Process.CreateProcess create) { var created = ProcessService.Create(create); return(Ok(created)); }