Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using NorthwindData.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace NorthwindData.Controllers
- {
- public class CustomerController : Controller
- {
- // GET: Customer
- public ActionResult Index()
- {
- List<Customers> model = new List<Customers>();
- try
- {
- northwindEntities entities = new northwindEntities();
- model = entities.Customers.ToList();
- entities.Dispose();
- }
- catch (Exception ex)
- {
- ViewBag.ErrorMessage = ex.GetType() + ": " + ex.Message;
- }
- 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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement