Example #1
0
        public ActionResult Yritys()
        {
            List <Yritykset> model = new List <Yritykset>();

            try
            {
                List <Shippers> shippers = db.Shippers.OrderByDescending(Shippers => Shippers.CompanyName).ToList();

                foreach (Shippers shipper in shippers)
                {
                    Yritykset yri = new Yritykset();
                    yri.ShipperID         = shipper.ShipperID;
                    yri.RegionID          = shipper.RegionID;
                    yri.CompanyName       = shipper.CompanyName;
                    yri.Phone             = shipper.Phone;
                    yri.RegionDescription = shipper.Region.RegionDescription;

                    model.Add(yri);
                }
            }
            finally
            {
                db.Dispose();
            }
            return(View(model));
        }
        public ActionResult GetOrderData(string id)  //id-parametri tulee MVC-mallin oletusreiteistä => mitä tarkoittaa ????
        {
            northwindEntities entities = new northwindEntities();

            try
            {
                List <Orders> orders = (from o in entities.Orders
                                        where o.CustomerID == id
                                        orderby o.OrderDate descending
                                        select o).ToList();

                StringBuilder html = new StringBuilder();       //lisätään html-dataa taulukkoon
                html.AppendLine("<td colspan = \"5\">" +
                                "<table class=\"table table-striped\">");

                foreach (Orders order in orders)
                {
                    html.AppendLine("<tr><td>" +
                                    order.OrderDate.Value.ToShortDateString() + "</td>" +
                                    "<td>" + order.OrderDate + "</td>" +
                                    "<td>" + order.ShipCity + "</td>" +
                                    "<td>" + order.RequiredDate.Value.ToShortDateString() + "</td></tr>");
                }
                html.AppendLine("</table></td>");

                // html.Append("Hello!");              //testataan, että kaikki toimii, että Ajax-kutsu toimii oikein!

                var jsonData = new { html = html.ToString() };        //palautetaan json-dataa, tässä vielä "Hello!"
                return(Json(jsonData, JsonRequestBehavior.AllowGet)); //palautetaan json -muodossa, HTTP-pyyntö GET, sallitaan GET
            }
            finally
            {
                entities.Dispose();
            }
        }
Example #3
0
        // GET: Order
        public ActionResult Index()
        {
            List <OrdersViewModel> model    = new List <OrdersViewModel>();
            northwindEntities      entities = new northwindEntities();

            try
            {
                List <Orders> order = entities.Orders.OrderBy(Orders => Orders.OrderID).ToList();
                foreach (Orders ord in order)
                {
                    OrdersViewModel view = new OrdersViewModel();
                    view.OrderID        = ord.OrderID;
                    view.CustomerID     = ord.CustomerID;
                    view.EmployeeID     = ord.EmployeeID;
                    view.OrderDate      = ord.OrderDate;
                    view.RequiredDate   = ord.RequiredDate;
                    view.ShippedDate    = ord.ShippedDate;
                    view.ShipVia        = ord.ShipVia;
                    view.Freight        = ord.Freight;
                    view.ShipName       = ord.ShipName;
                    view.ShipAddress    = ord.ShipAddress;
                    view.ShipCity       = ord.ShipCity;
                    view.ShipRegion     = ord.ShipRegion;
                    view.ShipPostalCode = ord.ShipPostalCode;
                    view.ShipCountry    = ord.ShipCountry;
                    model.Add(view);
                }
            }
            finally
            {
                entities.Dispose();
            }
            return(View(model));
        }
Example #4
0
        // GET: Customer
        public ActionResult Index()
        {
            List <CustomerViewModel> model    = new List <CustomerViewModel>();
            northwindEntities        entities = new northwindEntities();

            try
            {
                List <Customers> customer = entities.Customers.OrderBy(Customers => Customers.CustomerID).ToList();
                foreach (Customers cust in customer)
                {
                    CustomerViewModel view = new CustomerViewModel();
                    view.CustomerID   = cust.CustomerID;
                    view.CompanyName  = cust.CompanyName;
                    view.ContactName  = cust.ContactName;
                    view.ContactTitle = cust.ContactTitle;
                    view.Address      = cust.Address;
                    view.City         = cust.City;
                    view.Region       = cust.Region;
                    view.PostalCode   = cust.PostalCode;
                    view.Country      = cust.Country;
                    view.Phone        = cust.Phone;
                    view.Fax          = cust.Fax;
                    model.Add(view);
                }
            }
            finally
            {
                entities.Dispose();
            }
            return(View(model));
        }
Example #5
0
        public int OrderCount()
        {
            northwindEntities entities = new northwindEntities();
            int orderCount             = entities.Orders.Count();

            entities.Dispose();
            return(orderCount);
        }
Example #6
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
        public ActionResult ProdCards2()
        {
            northwindEntities db       = new northwindEntities(); //needs a using sentence
            List <Products>   tuotteet = db.Products.ToList();

            db.Dispose();
            return(View(tuotteet));
        }
Example #8
0
        // GET: Customer
        public ActionResult Index()
        {
            northwindEntities db    = new northwindEntities();
            List <Customer>   model = db.Customers.ToList();

            db.Dispose();
            return(View(model));
        }
        public ActionResult TuoteKuvat()
        {
            northwindEntities db    = new northwindEntities();
            List <Products>   model = db.Products.ToList();

            db.Dispose();

            return(View(model));
        }
Example #10
0
        public ActionResult Index2()
        {
            ViewBag.OmaTieto = "Tuotehaku";

            northwindEntities entities = new northwindEntities();
            List <Products>   model    = entities.Products.ToList();

            entities.Dispose();
            return(View(model));
        }
Example #11
0
        // GET: Customer
        public ActionResult Index()
        {
            northwindEntities entities = new northwindEntities(); //luodaan luokan ilmentymä eli instanssi

            //malliolion = model-olion avulla haetaan tietokannasta kaikki Customers-taulun tiedot
            List <Customers> model = entities.Customers.ToList();

            entities.Dispose(); //vapautetaan resurssit, joita käytettiin tietokantahakuun

            //näkymälle annetaan parametriksi malliolio
            return(View(model));
        }
Example #12
0
        public List <string> LastNOrders(int id)
        {
            northwindEntities entities          = new northwindEntities();
            int          numberOfOrdersToReturn = id;
            List <Order> lastOrders             = (from o in entities.Orders
                                                   orderby o.OrderDate descending
                                                   select o).Take(numberOfOrdersToReturn).ToList();

            List <string> customerNames =
                lastOrders.Select(o => o.Customer.CompanyName).ToList();

            entities.Dispose();
            return(customerNames);
        }
        // GET: Customer
        public ActionResult Index()
        {
            //1.luodaan luokan ilmentymä
            northwindEntities entities = new northwindEntities();

            //2.haetaan lista Customers-taulun olioista = tietokantakysely
            List<Customers> model = entities.Customers.ToList();

            //3.suljetaan tietokantayhteys
            entities.Dispose();

            //4.kerrotaan mitä näytetään
            return View(model);
        }
        // GET: Sales
        public ActionResult Index()
        {
            northwindEntities entities = new northwindEntities();

            try
            {
                List <Customers> model = entities.Customers.ToList();
                return(View(model));
            }
            finally
            {
                entities.Dispose();
            }
        }
Example #15
0
 // GET: Product
 public ActionResult Index()
 {
     ViewBag.OmaTieto = "Tuotehaku";
     if (Session["UserName"] == null)
     {
         return(RedirectToAction("login", "home"));
     }
     else
     {
         northwindEntities entities = new northwindEntities();
         List <Products>   model    = entities.Products.ToList();
         entities.Dispose();
         return(View(model));
     }
 }
        public ActionResult GetOrders(string id)
        {
            northwindEntities entities = new northwindEntities();
            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);
        }
Example #17
0
        // GET: Categorie
        public ActionResult Index()
        {
            List <CategorieViewModel> model    = new List <CategorieViewModel>();
            northwindEntities         entities = new northwindEntities();

            try
            {
                List <Categories> categorie = entities.Categories.OrderBy(Categories => Categories.CategoryID).ToList();
                foreach (Categories cat in categorie)
                {
                    CategorieViewModel view = new CategorieViewModel();
                    view.CategoryID   = cat.CategoryID;
                    view.CategoryName = cat.CategoryName;
                    view.Description  = cat.Description;
                    view.Picture      = cat.Picture;
                    model.Add(view);
                }
            }
            finally
            {
                entities.Dispose();
            }
            return(View(model));
        }
Example #18
0
        // GET: Employee
        public ActionResult Index()
        {
            List <EmployeeViewModel> model    = new List <EmployeeViewModel>();
            northwindEntities        entities = new northwindEntities();

            try
            {
                List <Employees> employee = entities.Employees.OrderBy(Employees => Employees.EmployeeID).ToList();
                foreach (Employees emp in employee)
                {
                    EmployeeViewModel view = new EmployeeViewModel();
                    view.EmployeeID      = emp.EmployeeID;
                    view.LastName        = emp.LastName;
                    view.FirstName       = emp.FirstName;
                    view.Title           = emp.Title;
                    view.TitleOfCourtesy = emp.TitleOfCourtesy;
                    view.BirthDate       = emp.BirthDate;
                    view.HireDate        = emp.HireDate;
                    view.Address         = emp.Address;
                    view.City            = emp.City;
                    view.Region          = emp.Region;
                    view.PostalCode      = emp.PostalCode;
                    view.Country         = emp.Country;
                    view.HomePhone       = emp.HomePhone;
                    view.Extension       = emp.Extension;
                    view.Notes           = emp.Notes;
                    view.ReportsTo       = emp.ReportsTo;
                    model.Add(view);
                }
            }
            finally
            {
                entities.Dispose();
            }
            return(View(model));
        }
Example #19
0
        // GET: Contact
        public ActionResult Index()
        {
            List <ContactViewModel> model    = new List <ContactViewModel>();
            northwindEntities       entities = new northwindEntities();

            try
            {
                List <Contacts> contact = entities.Contacts.OrderBy(Contacts => Contacts.ContactID).ToList();
                foreach (Contacts cont in contact)
                {
                    ContactViewModel view = new ContactViewModel();
                    view.ContactID    = cont.ContactID;
                    view.ContactType  = cont.ContactType;
                    view.CompanyName  = cont.CompanyName;
                    view.ContactName  = cont.ContactName;
                    view.ContactTitle = cont.ContactTitle;
                    view.Address      = cont.Address;
                    view.City         = cont.City;
                    view.Region       = cont.Region;
                    view.PostalCode   = cont.PostalCode;
                    view.Country      = cont.Country;
                    view.Phone        = cont.Phone;
                    view.Extension    = cont.Extension;
                    view.Fax          = cont.Fax;
                    view.HomePage     = cont.HomePage;
                    view.PhotoPath    = cont.PhotoPath;
                    view.Photo        = cont.Photo;
                    model.Add(view);
                }
            }
            finally
            {
                entities.Dispose();
            }
            return(View(model));
        }