public ActionResult SaunaOff(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Sauna sauna = db.Sauna.Find(id); if (sauna == null) { return(HttpNotFound()); } SaunaVIewModel view = new SaunaVIewModel(); view.SaunaId = sauna.SaunaId; view.SaunanNimi = sauna.SaunanNimi; view.SaunaStop = sauna.SaunaStop; view.SaunanTila = false; return(View(view)); }
// GET: SaunaTila public ActionResult Index() { List <SaunaVIewModel> model = new List <SaunaVIewModel>(); älytalodbEntities entities = new älytalodbEntities(); try { List <Sauna> sau = entities.Sauna.OrderByDescending(Sauna => Sauna.SaunaId).ToList(); foreach (Sauna saun in sau) { SaunaVIewModel view = new SaunaVIewModel(); view.SaunaId = saun.SaunaId; view.SaunanTila = saun.SaunanTila; view.SaunanNykyLampotila = saun.SaunanNykyLampotila; view.SaunaStart = saun.SaunaStart; view.SaunaStop = saun.SaunaStop; view.SaunanNimi = saun.SaunanNimi; model.Add(view); } } finally { entities.Dispose(); } return(View(model)); }
// GET: SaunaTila/Create public ActionResult Create() { älytalodbEntities db = new älytalodbEntities(); SaunaVIewModel model = new SaunaVIewModel(); return(View(model)); }
public ActionResult SaunaOff(SaunaVIewModel model) { Sauna view = db.Sauna.Find(model.SaunaId); view.SaunaStop = DateTime.Now; view.SaunanNimi = model.SaunanNimi; view.SaunanTila = false; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(SaunaVIewModel model) { Sauna view = new Sauna(); view.SaunaId = model.SaunaId; view.SaunanNimi = model.SaunanNimi; view.SaunanNykyLampotila = model.SaunanNykyLampotila; db.Sauna.Add(view); try { db.SaveChanges(); } catch (Exception ex) { } return(RedirectToAction("Index")); }