コード例 #1
0
 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));
     }
 }
コード例 #2
0
        // 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());
        }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
        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));
        }