public ActionResult DeleteConfirmed(int id)
        {
            discovery discovery = db.discovery.Find(id);

            db.discovery.Remove(discovery);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ictag,time,serial,brand,model,cpu,hdd,ram,optical_drive,location")] discovery discovery)
 {
     if (ModelState.IsValid)
     {
         db.Entry(discovery).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(discovery));
 }
        public ActionResult Create([Bind(Include = "ictag,time,serial,brand,model,cpu,hdd,ram,optical_drive,location")] discovery discovery)
        {
            if (ModelState.IsValid)
            {
                db.discovery.Add(discovery);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(discovery));
        }
        // GET: discoveries/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            discovery discovery = db.discovery.Find(id);

            if (discovery == null)
            {
                return(HttpNotFound());
            }
            return(View(discovery));
        }
        public JsonResult edit_form(string asset, string time, string serial, string make, string cpu, string ram, string hdd, string model)
        {
            List <string> message = new List <string>();

            using (var db = new db_a094d4_demoEntities1()) {
                try
                {
                    var discovery = new discovery();
                    discovery.serial = serial;
                    discovery.brand  = make;
                    discovery.cpu    = cpu;
                    discovery.ram    = ram;
                    discovery.hdd    = hdd;
                    discovery.model  = model;
                    discovery.ictag  = int.Parse(asset);
                    db.discovery.Attach(discovery);
                    var entry = db.Entry(discovery);
                    entry.Property(e => e.serial).IsModified = true;
                    entry.Property(e => e.brand).IsModified  = true;
                    entry.Property(e => e.cpu).IsModified    = true;
                    entry.Property(e => e.ram).IsModified    = true;
                    entry.Property(e => e.hdd).IsModified    = true;
                    entry.Property(e => e.model).IsModified  = true;

                    // other changed properties
                    db.SaveChanges();


                    message.Add("Info Has Updated for Asset ");
                }
                catch (Exception e) {
                    message.Add(e.InnerException.InnerException.Message);
                }
            }



            return(Json(new { message = message }, JsonRequestBehavior.AllowGet));
        }
Example #6
0
        //add new database entry for discover data
        public ActionResult insert_asset(int asset, string brand, string model, string refrub, string download, string cpu_brand, string cpu_type, string cpu_speed, string ram, string hdd, string serial)
        {
            var cpu = cpu_brand + " " + cpu_type + " " + cpu_speed;
            var xml = mrm_xml(asset.ToString(), brand, model, hdd, ram, serial, cpu);


            var db = new db_a094d4_icdbEntities1();

            var exisit = (from t in db.discovery where t.ictag == asset select t).ToList();

            if (exisit.Count == 0)
            {
                using (db as db_a094d4_icdbEntities1) {
                    var new_entry = new discovery();
                    new_entry.brand         = brand;
                    new_entry.cpu           = cpu;
                    new_entry.hdd           = hdd;
                    new_entry.ictag         = asset;
                    new_entry.location      = null;
                    new_entry.model         = model;
                    new_entry.optical_drive = null;
                    new_entry.ram           = ram;
                    new_entry.serial        = serial;
                    new_entry.time          = DateTime.Now;

                    db.discovery.Add(new_entry);
                    db.SaveChanges();

                    TempData["message"] = "Data Imported";
                }
                if (refrub == "on")
                {
                    using (var db2 = new db_a094d4_icdbEntities1())
                    {
                        var new_entry = new rediscovery();
                        new_entry.brand         = brand;
                        new_entry.cpu           = cpu;
                        new_entry.hdd           = hdd;
                        new_entry.ictag         = asset;
                        new_entry.location      = null;
                        new_entry.model         = model;
                        new_entry.optical_drive = null;
                        new_entry.ram           = ram;
                        new_entry.serial        = serial;
                        new_entry.time          = DateTime.Now;

                        db2.rediscovery.Add(new_entry);
                        db2.SaveChanges();

                        TempData["message"] = "Discovery and Rediscovery Data Imported";
                    }
                }
                if (download == "on")
                {
                    System.IO.MemoryStream stream = new System.IO.MemoryStream();
                    XmlTextWriter          writer = new XmlTextWriter(stream, System.Text.Encoding.UTF8);
                    xml.WriteTo(writer);
                    writer.Flush();
                    Response.Clear();
                    byte[] byteArray = stream.ToArray();
                    Response.AppendHeader("Content-Disposition", "attachment; filename=" + asset.ToString() + ".xml");
                    Response.AppendHeader("Content-Length", byteArray.Length.ToString());
                    Response.ContentType = "application/octet-stream";
                    Response.BinaryWrite(byteArray);
                    writer.Close();


                    Response.End();
                }
            }

            else
            {
                TempData["message"] = "an error has occurred";
            }
            return(View());
        }