public JsonResult edit_form(int asset, string serial, string model, string refurbisher, string sku)
        {
            List <string> message = new List <string>();

            using (var db = new db_a094d4_demoEntities1())
            {
                try
                {
                    var redis = new rediscovery();
                    redis.ictag       = asset;
                    redis.pallet      = sku;
                    redis.serial      = serial;
                    redis.model       = model;
                    redis.refurbisher = refurbisher;
                    db.rediscovery.Attach(redis);
                    var entry = db.Entry(redis);
                    entry.Property(e => e.pallet).IsModified      = true;
                    entry.Property(e => e.model).IsModified       = true;
                    entry.Property(e => e.serial).IsModified      = true;
                    entry.Property(e => e.refurbisher).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 #2
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());
        }