public ActionResult Index2() { if (Session["UserName"] == null) { return(RedirectToAction("login", "home")); } else { northwindEntities2 db = new northwindEntities2(); List <Products> model = db.Products.ToList(); db.Dispose(); return(View(model)); } }
// GET: Customers public ActionResult Index() { List <Customers> model = new List <Customers>(); try { northwindEntities2 entities = new northwindEntities2(); model = entities.Customers.ToList(); entities.Dispose(); } catch (Exception ex) { ViewBag.ErrorMessage = ex.GetType() + ": " + ex.Message; } return(View(model)); //return View(db.Customers.ToList()); }
public ActionResult Authorize(Logins LoginModel) { northwindEntities2 db = new northwindEntities2(); var LoggedUser = db.Logins.SingleOrDefault(x => x.UserName == LoginModel.UserName && x.PassWord == LoginModel.PassWord); //Haetaan käyttäjän/Loginin tiedot annetuilla tunnustiedoilla tietokannasta LINQ -kyselyllä if (LoggedUser != null) { ViewBag.LoginMessage = "Successfull login"; Session["UserName"] = LoggedUser.UserName; return(RedirectToAction("Index", "Home")); //Tässä määritellään mihin onnistunut kirjautuminen johtaa --> Home/Index } else { ViewBag.LoginMessage = "Login unsuccessfull"; LoginModel.LoginErrorMessage = "Tuntematon käyttäjätunnus tai salasana."; return(View("Index", LoginModel)); } }
public ActionResult GetOrders(string id) { northwindEntities2 entities = new northwindEntities2(); List <Orders> orders = (from o in entities.Orders where o.CustomerID == id select o).ToList(); entities.Dispose(); List <SimpleOrderData> result = new List <SimpleOrderData>(); foreach (Orders order in orders) { SimpleOrderData data = new SimpleOrderData(); data.CustomerId = order.CustomerID; data.OrderId = order.OrderID; data.OrderDate = order.OrderDate.ToString(); result.Add(data); } return(Json(result, JsonRequestBehavior.AllowGet)); }