Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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));
            }
        }
Esempio n. 3
0
        public IHttpActionResult Post([FromBody] Contracts.Process.CreateProcess create)
        {
            var created = ProcessService.Create(create);

            return(Ok(created));
        }