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

            db.RPC_Telai.Remove(rPC_Telai);
            db.SaveChanges();
            //return RedirectToAction("Index");
            return(RedirectToAction("DoRefresh", "Home"));
        }
        public ActionResult Image(int ID)
        {
            ViewBag.Message  = "Images";
            ViewBag.IDTelaio = ID;
            RPC_Telai telaio = db.RPC_Telai.Find(ID);

            //RPC_FotoXTelaio foto = db.RPC_FotoXTelaio.Find(ID);
            TempData["myIDTelaio"] = ID;

            return(View(telaio));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RPC_Telai rPC_Telai = db.RPC_Telai.Find(id);

            if (rPC_Telai == null)
            {
                return(HttpNotFound());
            }
            return(View(rPC_Telai));
        }
        //public ActionResult Delete()
        //{
        //    ViewBag.Message = "Delete.";

        //    return View();
        //}



        public ActionResult Edit(int ID)
        {
            RPC_Telai telai = db.RPC_Telai.Find(ID);

            ViewBag.IDCantiere = new SelectList(db.RPC_Cantieri_vw, "IDCantiere", "ragioneSociale", new { telai.IDCantiere });
            //ViewBag.IDLotto = new SelectList(db.RPC_Lotti, "ID", "Descrizione");
            //ViewBag.ID = new SelectList(db.RPC_Telai, "ID", "IDOperatore");

            //ViewBag.IDOperatore = new SelectList(db.PKT_Operatori, "ID", "ID");

            //ViewBag.Testing = new SelectList(GetLotti(), "Text", "Value");

            return(View(telai));
        }
        public ActionResult Create([Bind(Include = "ID,IDCantiere,IDOperatore,IDLotto,IsFinished,InsertDate,Telaio,Descr")] RPC_Telai rPC_Telai)
        {
            if (ModelState.IsValid)
            {
                db.RPC_Telai.Add(rPC_Telai);
                db.SaveChanges();
                return(RedirectToAction("DoRefresh", "Home"));
            }

            ViewBag.IDCantiere  = new SelectList(db.RPC_Cantieri_vw, "IDCantiere", "Descr", rPC_Telai.IDCantiere);
            ViewBag.IDLotto     = new SelectList(db.RPC_Lotti, "ID", "Descrizione", rPC_Telai.IDLotto);
            ViewBag.ID          = new SelectList(db.RPC_Telai, "ID", "IDOperatore", rPC_Telai.ID);
            ViewBag.ID          = new SelectList(db.RPC_Telai, "ID", "IDOperatore", rPC_Telai.ID);
            ViewBag.IDOperatore = new SelectList(db.PKT_Operatori, "ID", "ID", rPC_Telai.IDOperatore);
            return(View(rPC_Telai));
        }
        public ActionResult Edit([Bind(Include = " ID, IDCantiere, IDOperatore, IDLotto, IsFinished, InsertDate, Telaio, " +
                                                 " LastUpdateTime,Condizione, Note")] RPC_Telai rPC_Telai, string SearchResult)
        {
            if (ModelState.IsValid)
            {
                string myIDOperatore = TempData["myIDOperatore"] as string;
                if (rPC_Telai.IsFinished == true)
                {
                    rPC_Telai.IDOperatore = myIDOperatore.ToUpper();
                }
                else
                {
                    rPC_Telai.IDOperatore = null;
                }

                rPC_Telai.LastUpdateTime = DateTime.Now;

                db.Entry(rPC_Telai).State = EntityState.Modified;
                db.SaveChanges();

                var model = new Models.HomeModel();


                string mySearch = TempData["mySearch"] as string;
                string myLotto  = TempData["myLotto"] as string;

                var telai = from s in db.RPC_Telai
                            where s.IDCantiere.ToString() == mySearch && s.IDLotto.ToString() == myLotto
                            select s;

                model.RPC_Telai = telai.ToList();

                TempData["mySearch"] = mySearch;
                TempData["myLotto"]  = myLotto;


                //return View("VinList", model);
                //return View(rPC_Telai);
                return(RedirectToAction("DoRefresh", "Home"));
            }
            else
            {
                return(View(rPC_Telai));
            }
        }