Пример #1
0
        public DeleteEnvironmentScanningResponse DeleteEnvironmentalScanning(DeleteEnvironmentScanningRequest request)
        {
            var environmental = new EnvironmentalScanning { Id = request.Id };
            DataContext.EnvironmentalScannings.Attach(environmental);
            DataContext.EnvironmentalScannings.Remove(environmental);
            DataContext.SaveChanges();

            return new DeleteEnvironmentScanningResponse
            {
                IsSuccess = true,
                Message = "Deleted has been succesfully"
            };
        }
Пример #2
0
        public SaveConstraintResponse SaveConstraint(SaveConstraintRequest request)
        {
            var constraint = request.MapTo<Constraint>();
            if (request.Id == 0)
            {
                constraint.EnvironmentScanning = DataContext.EnvironmentsScannings.Where(x => x.Id == request.EnviId).FirstOrDefault();
                constraint.ESCategory = DataContext.ESCategories.FirstOrDefault(x => x.Id == request.Category);
                foreach (var id in request.RelationIds)
                {
                    var envistate = DataContext.EnvironmentalScannings.Local.FirstOrDefault(x => x.Id == id);
                    if (envistate == null)
                    {
                        envistate = new EnvironmentalScanning { Id = id };
                        DataContext.EnvironmentalScannings.Attach(envistate);
                    }
                    constraint.Relations.Add(envistate);
                }

                DataContext.Constraint.Add(constraint);
            }
            else
            {
                constraint = DataContext.Constraint.Include(x => x.ESCategory)
                     .Include(x => x.Relations)
                    .Include(x => x.ESCategory)
                    .Include(x => x.Relations.Select(y => y.ThreatHost))
                    .Include(x => x.Relations.Select(y => y.OpportunityHost))
                    .Include(x => x.Relations.Select(y => y.WeaknessHost))
                    .Include(x => x.Relations.Select(y => y.StrengthHost))
                    .FirstOrDefault(x => x.Id == request.Id);
                request.MapPropertiesToInstance<Constraint>(constraint);
                if (constraint.ESCategory.Id != request.Category)
                {
                    constraint.ESCategory = DataContext.ESCategories.FirstOrDefault(x => x.Id == request.Category);
                }
                constraint.Relations = new List<EnvironmentalScanning>();
                foreach (var id in request.RelationIds)
                {
                    var envistate = DataContext.EnvironmentalScannings.Local.FirstOrDefault(x => x.Id == id);
                    if (envistate == null)
                    {
                        envistate = new EnvironmentalScanning { Id = id };
                        DataContext.EnvironmentalScannings.Attach(envistate);
                    }
                    constraint.Relations.Add(envistate);
                }

            }

            DataContext.SaveChanges();
            var result = DataContext.Constraint.Where(x => x.Id == constraint.Id)
                .Include(x => x.Relations)
                .Include(x => x.Relations.Select(y => y.ThreatHost))
                .Include(x => x.Relations.Select(y => y.OpportunityHost))
                .Include(x => x.Relations.Select(y => y.WeaknessHost))
                .Include(x => x.Relations.Select(y => y.StrengthHost)).FirstOrDefault();

            return new SaveConstraintResponse
            {
                IsSuccess = true,
                Message = "Constraint has been saved successfully",
                Category = result.ESCategory.Name,
                Definition = result.Definition,
                Id = result.Id,
                Type = result.Type,
                RelationIds = result.Relations.Select(x => x.Id).ToArray(),
                ThreatIds = result.Relations.Where(x => x.ThreatHost != null).Select(y => y.Id).ToArray(),
                OpportunityIds = result.Relations.Where(x => x.OpportunityHost != null).Select(y => y.Id).ToArray(),
                WeaknessIds = result.Relations.Where(x => x.WeaknessHost != null).Select(y => y.Id).ToArray(),
                StrengthIds = result.Relations.Where(x => x.StrengthHost != null).Select(y => y.Id).ToArray(),
                CategoryId = result.ESCategory.Id

            };
        }