Пример #1
0
 public void DeleteCountry(CountryModel Country)
 {
     if (Country == null)
     {
         throw new ArgumentNullException();
     }
     using (AppTourEntities data = new AppTourEntities())
     {
         COUNTRY current = data.COUNTRY.Where(x => x.ID == Country.Id).SingleOrDefault();
         if (current != null)
         {
             try
             {
                 data.DeleteObject(current);
                 data.SaveChanges();
             }
             catch (Exception e)
             {
                 if (e.InnerException != null)
                 {
                     throw new Exception(e.InnerException.Message);
                 }
                 throw;
             }
         }
     }
 }
Пример #2
0
        public void UpdateCountry(CountryModel Country)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                COUNTRY current = data.COUNTRY.Where(x => Country.Id == x.ID).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.COUNTRY_CODE = Country.CountryCode;
                        current.NAME         = Country.Name;
                        current.ISO          = Country.ISO;
                        current.ISO3         = Country.ISO3;
                        current.COUNTRY_NAME = Country.CountryName;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Пример #3
0
        public IHttpActionResult PutCOUNTRY(int id, COUNTRY cOUNTRY)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cOUNTRY.CTRY_ID)
            {
                return(BadRequest());
            }

            db.Entry(cOUNTRY).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!COUNTRYExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult CreateEdit(COUNTRY country)
        {
            try
            {
                result        = countryUtil.PostCountryCreate(country);
                ViewBag.Title = country == null ? "Country Create" : "Country Edit";

                //ViewBag.controller_name = menuUtil.GetController();
                //ViewBag.menu_parent_id = menuUtil.GetMenu(false);
                //ViewBag.menu_ddl_id = menuUtil.GetMenu(true);
                ViewBag.action_name = BaseUtil.GetListAllActionByController("");
                switch (result.MessageType)
                {
                case MessageType.Success:
                    return(RedirectToAction("Index", "Country", new { result = result.Message, MessageType = result.MessageType }));

                default:
                    return(RedirectToAction("CreateEdit", "Country", new { result = result.Message, MessageType = result.MessageType }));
                }

                return(View(country));
            }
            catch
            {
                return(View(country));
            }
        }
        //
        // GET: /Countries/Edit/5

        public ActionResult Edit(int id)
        {
            COUNTRY country = db.COUNTRIES.Single(c => c.ID == id);

            ViewBag.REGION_ID = new SelectList(db.REGIONS, "ID", "NAME", country.REGION_ID);
            return(View(country));
        }
Пример #6
0
 public ActionResult CountryCreateEdit(COUNTRY country)
 {
     result              = countryUtil.PostCountryCreate(country);
     ViewBag.Title       = country == null ? "Country Create" : "Country Edit";
     ViewBag.action_name = BaseUtil.GetListAllActionByController("");
     return(Json(result));
 }
Пример #7
0
        public Guid InsertCountry(CountryModel Country)
        {
            Guid id = Guid.NewGuid();

            if (Country == null)
            {
                throw new NullReferenceException();
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                COUNTRY _new = new COUNTRY
                {
                    ID           = id,
                    NAME         = Country.Name,
                    COUNTRY_CODE = Country.CountryCode,
                    COUNTRY_NAME = Country.CountryName,
                    ISO          = Country.ISO,
                    ISO3         = Country.ISO3
                };

                data.COUNTRY.AddObject(_new);
                data.SaveChanges();
            }

            return(id);
        }
Пример #8
0
        public ActionResult DeleteConfirmed(short id)
        {
            COUNTRY country = db.COUNTRies.Find(id);

            db.COUNTRies.Remove(country);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            COUNTRY cOUNTRY = db.COUNTRY.Find(id);

            db.COUNTRY.Remove(cOUNTRY);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #10
0
        public ActionResult DeleteConfirmed(int id)
        {
            COUNTRY country = db.COUNTRIES.Single(c => c.ID == id);

            db.COUNTRIES.DeleteObject(country);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #11
0
 public ActionResult CreateCountry(COUNTRY dist)
 {
     if (ModelState.IsValid)
     {
         db.COUNTRies.Add(dist);
         db.SaveChanges();
     }
     return(View());
 }
Пример #12
0
 public ActionResult Edit([Bind(Include = "Id,continent,Name,capital,iso2,iso3,ioc,tld,currency,phone,Lang_Id")] COUNTRY cOUNTRY)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cOUNTRY).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cOUNTRY));
 }
Пример #13
0
        //
        // GET: /Country/Delete/5

        public ActionResult Delete(short id = 0)
        {
            COUNTRY country = db.COUNTRies.Find(id);

            if (country == null)
            {
                return(HttpNotFound());
            }
            return(View(country));
        }
Пример #14
0
 public ActionResult Edit(COUNTRY country)
 {
     if (ModelState.IsValid)
     {
         db.Entry(country).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(country));
 }
Пример #15
0
        public IHttpActionResult GetCOUNTRY(int id)
        {
            COUNTRY cOUNTRY = db.COUNTRies.Find(id);

            if (cOUNTRY == null)
            {
                return(NotFound());
            }

            return(Ok(cOUNTRY));
        }
Пример #16
0
        public ActionResult Create([Bind(Include = "Id,continent,Name,capital,iso2,iso3,ioc,tld,currency,phone,Lang_Id")] COUNTRY cOUNTRY)
        {
            if (ModelState.IsValid)
            {
                db.COUNTRY.Add(cOUNTRY);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cOUNTRY));
        }
Пример #17
0
        public ActionResult Create(COUNTRY country)
        {
            if (ModelState.IsValid)
            {
                db.COUNTRies.Add(country);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(country));
        }
Пример #18
0
 private bool IsModified(COUNTRY record)
 {
     //Type-specific routine that takes into account relationships that should also be considered
     //when deciding if there are unsaved changes.  The entity properties also return true if the
     //record is new or deleted.
     if (record == null)
     {
         return(false);
     }
     return(record.IsModified(_context) ||
            record.SupplierCountry.IsModified(_context));
 }
Пример #19
0
        public ActionResult CountryIndex(string id)
        {
            ViewBag.Title = "Country List";
            COUNTRY c = new COUNTRY();

            if (id != null && id != "")
            {
                c = db.COUNTRies.Find(Convert.ToInt32(id));
            }

            return(View(c));
        }
Пример #20
0
        public IHttpActionResult PostCOUNTRY(COUNTRY cOUNTRY)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.COUNTRies.Add(cOUNTRY);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = cOUNTRY.CTRY_ID }, cOUNTRY));
        }
Пример #21
0
        public ActionResult Create(COUNTRY country)
        {
            if (ModelState.IsValid)
            {
                db.COUNTRIES.AddObject(country);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.REGION_ID = new SelectList(db.REGIONS, "ID", "NAME", country.REGION_ID);
            return View(country);
        }
Пример #22
0
 public ActionResult Edit(COUNTRY country)
 {
     if (ModelState.IsValid)
     {
         db.COUNTRIES.Attach(country);
         db.ObjectStateManager.ChangeObjectState(country, EntityState.Modified);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.REGION_ID = new SelectList(db.REGIONS, "ID", "NAME", country.REGION_ID);
     return(View(country));
 }
Пример #23
0
        public ActionResult Create(COUNTRY country)
        {
            if (ModelState.IsValid)
            {
                db.COUNTRIES.AddObject(country);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.REGION_ID = new SelectList(db.REGIONS, "ID", "NAME", country.REGION_ID);
            return(View(country));
        }
Пример #24
0
 void ClearBindings()
 {
     _ignoreLeaveRow       = true;
     _ignorePositionChange = true;
     _selectedRecord       = null;
     BindingSourceSupplierCountry.Clear();
     SetReadOnly(true);
     BarButtonItemDelete.Enabled = false;
     BarButtonItemSave.Enabled   = false;
     BindingSource.DataSource    = typeof(COUNTRY);
     _ignoreLeaveRow             = false;
     _ignorePositionChange       = false;
 }
Пример #25
0
        // GET: COUNTRY/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            COUNTRY cOUNTRY = db.COUNTRY.Find(id);

            if (cOUNTRY == null)
            {
                return(HttpNotFound());
            }
            return(View(cOUNTRY));
        }
Пример #26
0
        public IHttpActionResult DeleteCOUNTRY(int id)
        {
            COUNTRY cOUNTRY = db.COUNTRies.Find(id);

            if (cOUNTRY == null)
            {
                return(NotFound());
            }

            db.COUNTRies.Remove(cOUNTRY);
            db.SaveChanges();

            return(Ok(cOUNTRY));
        }
Пример #27
0
        private void BindFocusedRow(GridView view, int focusedRowHandle)
        {
            object row = view.GetRow(focusedRowHandle);

            if (row != null && row.GetType() != typeof(DevExpress.Data.NotLoadedObject))
            {
                ReadonlyThreadSafeProxyForObjectFromAnotherThread proxy = (ReadonlyThreadSafeProxyForObjectFromAnotherThread)view.GetRow(focusedRowHandle);
                COUNTRY record = (COUNTRY)proxy.OriginalRow;
                BindingSource.DataSource = _context.COUNTRY.Where(c => c.CODE == record.CODE);
            }
            else
            {
                ClearBindings();
            }
        }
        //
        // GET: /Country/Create
        public ActionResult CreateEdit(string id)
        {
            COUNTRY c = new COUNTRY();

            if (id != null && id != "")
            {
                ViewBag.Title = "Country Edit";
                c             = db.COUNTRies.Find(Convert.ToInt32(id));
            }
            else
            {
                ViewBag.Title = "Country Create";
            }
            return(View(c));
        }
Пример #29
0
 void SetBindings()
 {
     //If the route list is filtered, there will be rows in the binding source
     if (BindingSource.Current == null)
     {
         ClearBindings();
     }
     else
     {
         _selectedRecord = ((COUNTRY)BindingSource.Current);
         LoadAndBindSupplierCountry();
         SetReadOnly(false);
         SetReadOnlyKeyFields(true);
         BarButtonItemDelete.Enabled = true;
         BarButtonItemSave.Enabled   = true;
     }
     ErrorProvider.Clear();
 }
        public void CollateParams_ReturnGeoParams()
        {
            const float  LAT      = 47.345f;
            const float  LONG     = -27.872f;
            const string COUNTRY  = "France";
            const string STATE    = "Normandy";
            const string CITY     = "Le Havre";
            const string CITY_OUT = "LEHAVRE";

            var request = new TargetDeliveryRequest.Builder()
                          .SetContext(new Context(ChannelType.Web, geo: new Geo(null,
                                                                                LAT, LONG, COUNTRY, STATE, CITY)))
                          .Build();
            var result = new GeoParamsCollator().CollateParams(request);

            Assert.Equal(LAT, result[GeoParamsCollator.GeoLatitude]);
            Assert.Equal(LONG, result[GeoParamsCollator.GeoLongitude]);
            Assert.Equal(COUNTRY.ToUpperInvariant(), result[GeoParamsCollator.GeoCountry]);
            Assert.Equal(STATE.ToUpperInvariant(), result[GeoParamsCollator.GeoRegion]);
            Assert.Equal(CITY_OUT, result[GeoParamsCollator.GeoCity]);
        }
Пример #31
0
        static void Main()
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            //https://raw.github.com/vz-risk/veris/master/verisc-enum.json

            try
            {
                WebClient wc = new WebClient();
                Console.WriteLine("Downloading verisc-enum.json");
                wc.DownloadFile("https://raw.github.com/vz-risk/veris/master/verisc-enum.json", "C:/nvdcve/verisc-enum.json");  //HARDCODED
                //
                wc.Dispose();
                //Console.WriteLine("Download is completed", "info", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while downloading\n" + ex.Message + " " + ex.InnerException);
            }

            // create reader & open file
            StreamReader tr = new StreamReader(@"C:\nvdcve\verisc-enum.json");  //HARDCODED

            // read the file
            string verisenum = tr.ReadToEnd();

            //Console.WriteLine(verisenum);

            // close the stream
            tr.Close();


            XORCISMEntities model = new XORCISMEntities();

            XTHREATEntities threat_model = new XTHREATEntities();


            JsonObject jobj   = (JsonObject)JsonConvert.Import(verisenum);
            JsonArray  jarray = new JsonArray();

            foreach (string loc in jobj.Names)
            {
                //Console.WriteLine(loc);
                switch (loc)
                {
                case "security_compromise":

                    break;

                case "confidence":

                    break;

                case "victim":
                    //Console.WriteLine(Convert.ToString(((JsonObject)jobj[loc])["employee_count"]));
                    jarray = (JsonArray)((JsonObject)jobj[loc])["employee_count"];
                    for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                    {
                        //Console.WriteLine(Convert.ToString(jarray[cpt]));
                    }
                    break;

                case "actor":

                    break;

                case "action":
                    //Console.WriteLine(Convert.ToString(((JsonObject)jobj[loc])["malware"]));
                    //************* MALWARE **************************
                    JsonObject jobj2 = (JsonObject)JsonConvert.Import(Convert.ToString(((JsonObject)jobj[loc])["malware"]));

                    foreach (string loc2 in jobj2.Names)
                    {
                        //Console.WriteLine(loc2);
                        //variety
                        //vector
                        switch (loc2)
                        {
                        case "variety":
                            jarray = (JsonArray)(jobj2)["variety"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVarietyName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVarietyName);
                                //ThreatActionCategoryID=1  //malware
                                XTHREATModel.THREATACTIONVARIETY tactionvariety = new THREATACTIONVARIETY();
                                tactionvariety = threat_model.THREATACTIONVARIETY.FirstOrDefault(o => o.ThreatActionCategoryID == 1 && o.ThreatActionVarietyName == sThreatActionVarietyName);
                                if (tactionvariety == null)
                                {
                                    tactionvariety = new THREATACTIONVARIETY();
                                    tactionvariety.ThreatActionCategoryID  = 1;         //malware
                                    tactionvariety.ThreatActionVarietyName = sThreatActionVarietyName;
                                    threat_model.THREATACTIONVARIETY.Add(tactionvariety);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        case "vector":
                            jarray = (JsonArray)(jobj2)["vector"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVectorName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVectorName);
                                //ThreatActionCategoryID=1  //malware
                                XTHREATModel.THREATACTIONVECTOR tactionvector = new THREATACTIONVECTOR();
                                tactionvector = threat_model.THREATACTIONVECTOR.FirstOrDefault(o => o.ThreatActionCategoryID == 1 && o.ThreatActionVectorName == sThreatActionVectorName);
                                if (tactionvector == null)
                                {
                                    tactionvector = new THREATACTIONVECTOR();
                                    tactionvector.ThreatActionCategoryID = 1;          //malware
                                    tactionvector.ThreatActionVectorName = sThreatActionVectorName;
                                    threat_model.THREATACTIONVECTOR.Add(tactionvector);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        default:
                            Console.WriteLine("ERROR " + loc2 + " is unknown for action.malware");
                            break;
                        }
                    }

                    //************* HACKING **************************
                    jobj2 = (JsonObject)JsonConvert.Import(Convert.ToString(((JsonObject)jobj[loc])["hacking"]));

                    foreach (string loc2 in jobj2.Names)
                    {
                        //Console.WriteLine(loc2);
                        //variety
                        //vector
                        switch (loc2)
                        {
                        case "variety":
                            jarray = (JsonArray)(jobj2)["variety"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVarietyName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVarietyName);
                                //ThreatActionCategoryID=2  //hacking
                                XTHREATModel.THREATACTIONVARIETY tactionvariety = new THREATACTIONVARIETY();
                                tactionvariety = threat_model.THREATACTIONVARIETY.FirstOrDefault(o => o.ThreatActionCategoryID == 2 && o.ThreatActionVarietyName == sThreatActionVarietyName);
                                if (tactionvariety == null)
                                {
                                    tactionvariety = new THREATACTIONVARIETY();
                                    tactionvariety.ThreatActionCategoryID  = 2;         //hacking
                                    tactionvariety.ThreatActionVarietyName = sThreatActionVarietyName;
                                    threat_model.THREATACTIONVARIETY.Add(tactionvariety);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        case "vector":
                            jarray = (JsonArray)(jobj2)["vector"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVectorName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVectorName);
                                //ThreatActionCategoryID=2  //hacking
                                XTHREATModel.THREATACTIONVECTOR tactionvector = new THREATACTIONVECTOR();
                                tactionvector = threat_model.THREATACTIONVECTOR.FirstOrDefault(o => o.ThreatActionCategoryID == 2 && o.ThreatActionVectorName == sThreatActionVectorName);
                                if (tactionvector == null)
                                {
                                    tactionvector = new THREATACTIONVECTOR();
                                    tactionvector.ThreatActionCategoryID = 2;          //hacking
                                    tactionvector.ThreatActionVectorName = sThreatActionVectorName;
                                    threat_model.THREATACTIONVECTOR.Add(tactionvector);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        default:
                            Console.WriteLine(loc2 + " is unknown for action.hacking");
                            break;
                        }
                    }

                    //************* SOCIAL **************************
                    jobj2 = (JsonObject)JsonConvert.Import(Convert.ToString(((JsonObject)jobj[loc])["social"]));

                    foreach (string loc2 in jobj2.Names)
                    {
                        //Console.WriteLine(loc2);
                        //variety
                        //vector
                        switch (loc2)
                        {
                        case "variety":
                            jarray = (JsonArray)(jobj2)["variety"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVarietyName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVarietyName);
                                //ThreatActionCategoryID=3  //social
                                XTHREATModel.THREATACTIONVARIETY tactionvariety = new THREATACTIONVARIETY();
                                tactionvariety = threat_model.THREATACTIONVARIETY.FirstOrDefault(o => o.ThreatActionCategoryID == 3 && o.ThreatActionVarietyName == sThreatActionVarietyName);
                                if (tactionvariety == null)
                                {
                                    tactionvariety = new THREATACTIONVARIETY();
                                    tactionvariety.ThreatActionCategoryID  = 3;         //social
                                    tactionvariety.ThreatActionVarietyName = sThreatActionVarietyName;
                                    threat_model.THREATACTIONVARIETY.Add(tactionvariety);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        case "vector":
                            jarray = (JsonArray)(jobj2)["vector"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVectorName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVectorName);
                                //ThreatActionCategoryID=3  //social
                                XTHREATModel.THREATACTIONVECTOR tactionvector = new THREATACTIONVECTOR();
                                tactionvector = threat_model.THREATACTIONVECTOR.FirstOrDefault(o => o.ThreatActionCategoryID == 3 && o.ThreatActionVectorName == sThreatActionVectorName);
                                if (tactionvector == null)
                                {
                                    tactionvector = new THREATACTIONVECTOR();
                                    tactionvector.ThreatActionCategoryID = 3;          //social
                                    tactionvector.ThreatActionVectorName = sThreatActionVectorName;
                                    threat_model.THREATACTIONVECTOR.Add(tactionvector);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        case "target":
                            jarray = (JsonArray)(jobj2)["target"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionTargetName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionTargetName);
                                //ThreatActionCategoryID=3  //social
                                XTHREATModel.THREATACTIONTARGET tactiontarget = new THREATACTIONTARGET();
                                tactiontarget = threat_model.THREATACTIONTARGET.FirstOrDefault(o => o.ThreatActionCategoryID == 3 && o.ThreatActionTargetName == sThreatActionTargetName);
                                if (tactiontarget == null)
                                {
                                    tactiontarget = new THREATACTIONTARGET();
                                    tactiontarget.ThreatActionCategoryID = 3;          //social
                                    tactiontarget.ThreatActionTargetName = sThreatActionTargetName;
                                    threat_model.THREATACTIONTARGET.Add(tactiontarget);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        default:
                            Console.WriteLine(loc2 + " is unknown for action.social");
                            break;
                        }
                    }

                    //************* SOCIAL **************************
                    jobj2 = (JsonObject)JsonConvert.Import(Convert.ToString(((JsonObject)jobj[loc])["social"]));

                    foreach (string loc2 in jobj2.Names)
                    {
                        //Console.WriteLine(loc2);
                        //variety
                        //vector
                        switch (loc2)
                        {
                        case "variety":
                            jarray = (JsonArray)(jobj2)["variety"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVarietyName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVarietyName);
                                //ThreatActionCategoryID=3  //social
                                XTHREATModel.THREATACTIONVARIETY tactionvariety = new THREATACTIONVARIETY();
                                tactionvariety = threat_model.THREATACTIONVARIETY.FirstOrDefault(o => o.ThreatActionCategoryID == 3 && o.ThreatActionVarietyName == sThreatActionVarietyName);
                                if (tactionvariety == null)
                                {
                                    tactionvariety = new THREATACTIONVARIETY();
                                    tactionvariety.ThreatActionCategoryID  = 3;         //social
                                    tactionvariety.ThreatActionVarietyName = sThreatActionVarietyName;
                                    threat_model.THREATACTIONVARIETY.Add(tactionvariety);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        case "vector":
                            jarray = (JsonArray)(jobj2)["vector"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVectorName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVectorName);
                                //ThreatActionCategoryID=3  //social
                                XTHREATModel.THREATACTIONVECTOR tactionvector = new THREATACTIONVECTOR();
                                tactionvector = threat_model.THREATACTIONVECTOR.FirstOrDefault(o => o.ThreatActionCategoryID == 3 && o.ThreatActionVectorName == sThreatActionVectorName);
                                if (tactionvector == null)
                                {
                                    tactionvector = new THREATACTIONVECTOR();
                                    tactionvector.ThreatActionCategoryID = 3;          //social
                                    tactionvector.ThreatActionVectorName = sThreatActionVectorName;
                                    threat_model.THREATACTIONVECTOR.Add(tactionvector);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        default:
                            Console.WriteLine(loc2 + " is unknown for action.social");
                            break;
                        }
                    }

                    //************* MISUSE **************************
                    jobj2 = (JsonObject)JsonConvert.Import(Convert.ToString(((JsonObject)jobj[loc])["misuse"]));

                    foreach (string loc2 in jobj2.Names)
                    {
                        //Console.WriteLine(loc2);
                        //variety
                        //vector
                        switch (loc2)
                        {
                        case "variety":
                            jarray = (JsonArray)(jobj2)["variety"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVarietyName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVarietyName);
                                //ThreatActionCategoryID=4  //misuse
                                XTHREATModel.THREATACTIONVARIETY tactionvariety = new THREATACTIONVARIETY();
                                tactionvariety = threat_model.THREATACTIONVARIETY.FirstOrDefault(o => o.ThreatActionCategoryID == 4 && o.ThreatActionVarietyName == sThreatActionVarietyName);
                                if (tactionvariety == null)
                                {
                                    tactionvariety = new THREATACTIONVARIETY();
                                    tactionvariety.ThreatActionCategoryID  = 4;         //misuse
                                    tactionvariety.ThreatActionVarietyName = sThreatActionVarietyName;
                                    threat_model.THREATACTIONVARIETY.Add(tactionvariety);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        case "vector":
                            jarray = (JsonArray)(jobj2)["vector"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVectorName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVectorName);
                                //ThreatActionCategoryID=4  //misuse
                                XTHREATModel.THREATACTIONVECTOR tactionvector = new THREATACTIONVECTOR();
                                tactionvector = threat_model.THREATACTIONVECTOR.FirstOrDefault(o => o.ThreatActionCategoryID == 4 && o.ThreatActionVectorName == sThreatActionVectorName);
                                if (tactionvector == null)
                                {
                                    tactionvector = new THREATACTIONVECTOR();
                                    tactionvector.ThreatActionCategoryID = 4;          //misuse
                                    tactionvector.ThreatActionVectorName = sThreatActionVectorName;
                                    threat_model.THREATACTIONVECTOR.Add(tactionvector);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        default:
                            Console.WriteLine(loc2 + " is unknown for action.misuse");
                            break;
                        }
                    }

                    //************* PHYSICAL **************************
                    jobj2 = (JsonObject)JsonConvert.Import(Convert.ToString(((JsonObject)jobj[loc])["physical"]));

                    foreach (string loc2 in jobj2.Names)
                    {
                        //Console.WriteLine(loc2);
                        //variety
                        //vector
                        switch (loc2)
                        {
                        case "variety":
                            jarray = (JsonArray)(jobj2)["variety"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVarietyName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVarietyName);
                                //ThreatActionCategoryID=5  //physical
                                XTHREATModel.THREATACTIONVARIETY tactionvariety = new THREATACTIONVARIETY();
                                tactionvariety = threat_model.THREATACTIONVARIETY.FirstOrDefault(o => o.ThreatActionCategoryID == 5 && o.ThreatActionVarietyName == sThreatActionVarietyName);
                                if (tactionvariety == null)
                                {
                                    tactionvariety = new THREATACTIONVARIETY();
                                    tactionvariety.ThreatActionCategoryID  = 5;         //physical
                                    tactionvariety.ThreatActionVarietyName = sThreatActionVarietyName;
                                    threat_model.THREATACTIONVARIETY.Add(tactionvariety);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        case "location":
                            jarray = (JsonArray)(jobj2)["location"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionLocationName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionLocationName);
                                //ThreatActionCategoryID=5  //physical
                                XTHREATModel.THREATACTIONLOCATION tactionlocation = new THREATACTIONLOCATION();
                                tactionlocation = threat_model.THREATACTIONLOCATION.FirstOrDefault(o => o.ThreatActionLocationName == sThreatActionLocationName);
                                if (tactionlocation == null)
                                {
                                    tactionlocation = new THREATACTIONLOCATION();
                                    //tactionlocation.ThreatActionCategoryID = 5;  //physical
                                    tactionlocation.ThreatActionLocationName = sThreatActionLocationName;
                                    threat_model.THREATACTIONLOCATION.Add(tactionlocation);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        case "vector":
                            jarray = (JsonArray)(jobj2)["vector"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVectorName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVectorName);
                                //ThreatActionCategoryID=5  //physical
                                XTHREATModel.THREATACTIONVECTOR tactionvector = new THREATACTIONVECTOR();
                                tactionvector = threat_model.THREATACTIONVECTOR.FirstOrDefault(o => o.ThreatActionCategoryID == 5 && o.ThreatActionVectorName == sThreatActionVectorName);
                                if (tactionvector == null)
                                {
                                    tactionvector = new THREATACTIONVECTOR();
                                    tactionvector.ThreatActionCategoryID = 5;          //physical
                                    tactionvector.ThreatActionVectorName = sThreatActionVectorName;
                                    threat_model.THREATACTIONVECTOR.Add(tactionvector);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        default:
                            Console.WriteLine(loc2 + " is unknown for action.physical");
                            break;
                        }
                    }

                    //************* ERROR **************************
                    jobj2 = (JsonObject)JsonConvert.Import(Convert.ToString(((JsonObject)jobj[loc])["error"]));

                    foreach (string loc2 in jobj2.Names)
                    {
                        //Console.WriteLine(loc2);
                        //variety
                        //vector
                        switch (loc2)
                        {
                        case "variety":
                            jarray = (JsonArray)(jobj2)["variety"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVarietyName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVarietyName);
                                //ThreatActionCategoryID=6  //error
                                XTHREATModel.THREATACTIONVARIETY tactionvariety = new THREATACTIONVARIETY();
                                tactionvariety = threat_model.THREATACTIONVARIETY.FirstOrDefault(o => o.ThreatActionCategoryID == 6 && o.ThreatActionVarietyName == sThreatActionVarietyName);
                                if (tactionvariety == null)
                                {
                                    tactionvariety = new THREATACTIONVARIETY();
                                    tactionvariety.ThreatActionCategoryID  = 6;         //error
                                    tactionvariety.ThreatActionVarietyName = sThreatActionVarietyName;
                                    threat_model.THREATACTIONVARIETY.Add(tactionvariety);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        case "vector":
                            jarray = (JsonArray)(jobj2)["vector"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVectorName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVectorName);
                                //ThreatActionCategoryID=6  //error
                                XTHREATModel.THREATACTIONVECTOR tactionvector = new THREATACTIONVECTOR();
                                tactionvector = threat_model.THREATACTIONVECTOR.FirstOrDefault(o => o.ThreatActionCategoryID == 6 && o.ThreatActionVectorName == sThreatActionVectorName);
                                if (tactionvector == null)
                                {
                                    tactionvector = new THREATACTIONVECTOR();
                                    tactionvector.ThreatActionCategoryID = 6;          //error
                                    tactionvector.ThreatActionVectorName = sThreatActionVectorName;
                                    threat_model.THREATACTIONVECTOR.Add(tactionvector);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        default:
                            Console.WriteLine(loc2 + " is unknown for action.error");
                            break;
                        }
                    }

                    //************* ENVIRONMENTAL **************************
                    jobj2 = (JsonObject)JsonConvert.Import(Convert.ToString(((JsonObject)jobj[loc])["environmental"]));

                    foreach (string loc2 in jobj2.Names)
                    {
                        //Console.WriteLine(loc2);
                        //variety
                        switch (loc2)
                        {
                        case "variety":
                            jarray = (JsonArray)(jobj2)["variety"];
                            for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                            {
                                string sThreatActionVarietyName = Convert.ToString(jarray[cpt]);
                                //Console.WriteLine(sThreatActionVarietyName);
                                //ThreatActionCategoryID=7  //environmental
                                XTHREATModel.THREATACTIONVARIETY tactionvariety = new THREATACTIONVARIETY();
                                tactionvariety = threat_model.THREATACTIONVARIETY.FirstOrDefault(o => o.ThreatActionCategoryID == 7 && o.ThreatActionVarietyName == sThreatActionVarietyName);
                                if (tactionvariety == null)
                                {
                                    tactionvariety = new THREATACTIONVARIETY();
                                    tactionvariety.ThreatActionCategoryID  = 7;         //environmental
                                    tactionvariety.ThreatActionVarietyName = sThreatActionVarietyName;
                                    threat_model.THREATACTIONVARIETY.Add(tactionvariety);
                                    threat_model.SaveChanges();
                                }
                            }
                            break;

                        default:
                            Console.WriteLine(loc2 + " is unknown for action.environmental");
                            break;
                        }
                    }

                    break;

                case "asset":
                    jarray = (JsonArray)((JsonObject)jobj[loc])["variety"];
                    for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                    {
                        string sAssetVarietyName = Convert.ToString(jarray[cpt]);
                        //Console.WriteLine(sAssetVarietyName);
                        XORCISMModel.ASSETVARIETY assetvariety = new ASSETVARIETY();
                        assetvariety = model.ASSETVARIETY.FirstOrDefault(o => o.AssetVarietyName == sAssetVarietyName);
                        if (assetvariety == null)
                        {
                            assetvariety = new ASSETVARIETY();
                            assetvariety.AssetVarietyName = sAssetVarietyName;
                            model.ASSETVARIETY.Add(assetvariety);
                            model.SaveChanges();
                        }
                    }
                    //cloud
                    break;

                case "attribute":

                    break;

                case "timeline":

                    break;

                case "discovery_method":

                    break;

                case "cost_corrective_action":

                    break;

                case "impact":

                    break;

                case "country":
                    //ISOCOUNTRY    COUNTRYISO
                    //http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements.htm

                    // create reader & open file
                    tr = new StreamReader(@"country_names_and_code_element.txt");       //HARDCODED

                    // read the file
                    string scountryline = tr.ReadLine();
                    //Console.WriteLine(verisenum);
                    //Country Name;ISO 3166-1-alpha-2 code
                    //Ignore the first line (headers)
                    scountryline = tr.ReadLine();
                    string[] row;
                    while (scountryline != null && scountryline != "")
                    {
                        row = scountryline.Split(';');
                        string sCountryName          = row[0];
                        string sCountryCode          = row[1];
                        XORCISMModel.COUNTRY country = new COUNTRY();
                        country = model.COUNTRY.FirstOrDefault(o => o.CountryName == sCountryName && o.CountryCode == sCountryCode);
                        if (country == null)
                        {
                            country             = new COUNTRY();
                            country.CountryCode = sCountryCode;
                            country.CountryName = sCountryName;
                            model.COUNTRY.Add(country);
                            model.SaveChanges();
                        }
                        scountryline = tr.ReadLine();
                    }

                    // close the stream
                    tr.Close();



                    jarray = (JsonArray)jobj[loc];
                    for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                    {
                        string scountry = Convert.ToString(jarray[cpt]).ToUpper();
                        //Console.WriteLine(scountry);
                        XORCISMModel.COUNTRY country = new COUNTRY();
                        country = model.COUNTRY.FirstOrDefault(o => o.CountryName == scountry);
                        if (country == null)
                        {
                            country = new COUNTRY();
                            //country.CountryCode = "";
                            country.CountryName = scountry;
                            Console.WriteLine("Country: " + scountry + " not found in the database.");
                            //model.AddToCOUNTRY(country);
                            //model.SaveChanges();
                        }
                    }
                    break;

                case "iso_currency_code":
                    //jarray = (JsonArray)((JsonObject)jobj[loc])[0];
                    //jarray = new JsonArray(loc);
                    jarray = (JsonArray)jobj[loc];
                    for (int cpt = 0; cpt < jarray.Length - 1; cpt++)
                    {
                        string scurrency = Convert.ToString(jarray[cpt]);
                        //Console.WriteLine(scurrency);
                        XORCISMModel.ISOCURRENCY currency = new ISOCURRENCY();
                        currency = model.ISOCURRENCY.FirstOrDefault(o => o.iso_currency_code == scurrency);
                        if (currency == null)
                        {
                            currency = new ISOCURRENCY();
                            currency.iso_currency_code = scurrency;
                            model.ISOCURRENCY.Add(currency);
                            model.SaveChanges();
                        }
                    }
                    break;

                default:
                    break;
                }



                //wid.value = Convert.ToString(((JsonObject)jobj[loc])["name"]);
                //JsonArray coords = (JsonArray)((JsonObject)jobj[loc])["coords"];
                //wid.style.left = Convert.ToString(coords[0]);
                //wid.style.top = Convert.ToString(coords[1]);
            }
            //FREE
            model.Dispose();
            model = null;
        }
Пример #32
0
 public ActionResult Edit(COUNTRY country)
 {
     if (ModelState.IsValid)
     {
         db.COUNTRIES.Attach(country);
         db.ObjectStateManager.ChangeObjectState(country, EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.REGION_ID = new SelectList(db.REGIONS, "ID", "NAME", country.REGION_ID);
     return View(country);
 }