public IHttpActionResult PutTalonTila(int id, TalonTila talonTila)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != talonTila.TalonTilaID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Create(TalonTilaModel model)
        {
            TalonTila tila = db.TalonTila.Find(model.TalonTilaID);

            tila.TalonTilaID           = model.TalonTilaID;
            tila.TalonTavoiteLampotila = model.TalonTavoiteLampotila;
            tila.TalonNykyLampotila    = model.TalonNykyLampotila;
            tila.PVM = DateTime.Now;
            //tila. = model.Talot?.TalonSijainti;
            tila.TaloID = model.Talot?.TaloID;
            // db.TalonTila.Add(tila);
            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }
            ///*
            //if (ModelState.IsValid)
            //{
            //    db.TalonTila.Add(talonTila);
            //    db.SaveChanges();*/
            //    return RedirectToAction("Index");
            //}



            ViewBag.TaloID = new SelectList(db.Talot, "TaloID", "TalonSijainti", tila.TaloID);
            // return View(talonTila);

            return(RedirectToAction("Index"));
        }
        // GET: TalonTila/Create
        public ActionResult Create()
        {
            TaloEntities db    = new TaloEntities();
            TalonTila    model = new TalonTila();

            ViewBag.TaloID = new SelectList(db.Talot, "TaloID", "TalonSijainti");
            return(View(model));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            TalonTila talonTila = db.TalonTila.Find(id);

            db.TalonTila.Remove(talonTila);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public IHttpActionResult GetTalonTila(int id)
        {
            TalonTila talonTila = db.TalonTila.Find(id);

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

            return(Ok(talonTila));
        }
 public ActionResult Edit([Bind(Include = "TalonTilaID,TaloID,TalonTavoiteLampotila,TalonNykyLampotila,PVM")] TalonTila talonTila)
 {
     if (ModelState.IsValid)
     {
         db.Entry(talonTila).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.TaloID = new SelectList(db.Talot, "TaloID", "TalonSijainti", talonTila.TaloID);
     return(View(talonTila));
 }
        public IHttpActionResult PostTalonTila(TalonTila talonTila)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TalonTila.Add(talonTila);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = talonTila.TalonTilaID }, talonTila));
        }
        public IHttpActionResult DeleteTalonTila(int id)
        {
            TalonTila talonTila = db.TalonTila.Find(id);

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

            db.TalonTila.Remove(talonTila);
            db.SaveChanges();

            return(Ok(talonTila));
        }
        // GET: TalonTila/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TalonTila talonTila = db.TalonTila.Find(id);

            if (talonTila == null)
            {
                return(HttpNotFound());
            }
            return(View(talonTila));
        }
        // GET: TalonTila/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TalonTila talonTila = db.TalonTila.Find(id);

            if (talonTila == null)
            {
                return(HttpNotFound());
            }
            ViewBag.TaloID = new SelectList(db.Talot, "TaloID", "TalonSijainti", talonTila.TaloID);
            return(View(talonTila));
        }