public ActionResult Insert(Product product) { var northwind = new Models.NorthwindEntities(); var products = northwind.Products; var categories = northwind.Categories; // Find the category which has been chosen using the posted Category.CategoryID (specified using the dropdownlist) var category = categories.FirstOrDefault(c => c.CategoryID == product.Category.CategoryID); // Set the chosen Category product.Category = category; // Add the new product products.AddObject(product); // Save the changes in the database northwind.SaveChanges(); var data = from p in products select new // Use anonymous type to avoid JSON serialization exceptions due to circular object references. Also serialize only the required properties (for performance) { p.Category, p.ProductID, p.ProductName, p.CategoryID }; return View(new GridModel(data)); }
public ActionResult Insert(Product product) { var northwind = new Models.NorthwindEntities(); var products = northwind.Products; var categories = northwind.Categories; // Find the category which has been chosen using the posted Category.CategoryID (specified using the dropdownlist) var category = categories.FirstOrDefault(c => c.CategoryID == product.Category.CategoryID); // Set the chosen Category product.Category = category; // Add the new product products.AddObject(product); // Save the changes in the database northwind.SaveChanges(); var data = from p in products select new // Use anonymous type to avoid JSON serialization exceptions due to circular object references. Also serialize only the required properties (for performance) { p.Category, p.ProductID, p.ProductName, p.CategoryID }; return(View(new GridModel(data))); }
public ActionResult Delete(Product product) { var northwind = new Models.NorthwindEntities(); var products = northwind.Products; // Get the product being deleted using the posted ProductID var actualProduct = products.FirstOrDefault(p => p.ProductID == product.ProductID); if (actualProduct != null) { // Delete the product products.DeleteObject(actualProduct); // Save the changes in the database northwind.SaveChanges(); } var data = from p in products select new // Use anonymous type to avoid JSON serialization exceptions due to circular object references. Also serialize only the required properties (for performance) { p.Category, p.ProductID, p.ProductName, p.CategoryID }; return(View(new GridModel(data))); }
// GET: Regiones public ActionResult Index() { var context = new Models.NorthwindEntities(); var regiones = context.Region.ToList(); return View(regiones); }
// GET api/<controller>/5 public string Get(string id) { Models.NorthwindEntities database = new Models.NorthwindEntities(); Models.Customer customer = database.Customers.Find(id); var json = JsonConvert.SerializeObject(customer); return(json.ToString()); }
public ActionResult Edit(Models.Orders order) { Models.NorthwindEntities db = new Models.NorthwindEntities(); //var _order = db.Orders.First(o => o.OrderID == order.OrderID); db.Set <Models.Orders>().AsNoTracking().FirstOrDefault(o => o.OrderID == order.OrderID); db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(View()); }
public ActionResult Select() { var products = new Models.NorthwindEntities().Products; var data = from p in products select new // Use anonymous type to avoid JSON serialization exceptions due to circular object references. Also serialize only the required properties (for performance) { p.Category, p.ProductID, p.ProductName, p.CategoryID }; return View(new GridModel(data)); }
public ActionResult Select() { var products = new Models.NorthwindEntities().Products; var data = from p in products select new // Use anonymous type to avoid JSON serialization exceptions due to circular object references. Also serialize only the required properties (for performance) { p.Category, p.ProductID, p.ProductName, p.CategoryID }; return(View(new GridModel(data))); }
[CustomAuth("admin")]//身份為admin才可進入 public ActionResult Edit(string id) { Models.Orders data; if (String.IsNullOrEmpty(id)) { //data = null; return(View()); } else { Models.NorthwindEntities db = new Models.NorthwindEntities(); data = (from o in db.Orders where o.OrderID.IndexOf(id.ToString()) >= 0 select o).FirstOrDefault(); return(View(data)); } }
// // GET: /Product/ public ActionResult Index(String startString) { List <Models.Product> theProducts; using ( Models.NorthwindEntities NWC = new Models.NorthwindEntities() ) { theProducts = (from e in NWC.Products where e.ProductName.StartsWith(startString) select e).ToList(); } return(View(theProducts)); }
[ValidateAntiForgeryToken] //防止CSRF public ActionResult Login(Models.Account account) { if (!ModelState.IsValid) { return(View()); } Models.NorthwindEntities db = new Models.NorthwindEntities(); var test = (from a in db.Account where a.UserId == account.UserId && a.Password == account.Password select a).FirstOrDefault(); if (test != null) { LoginProcess(test); return(RedirectToAction("index", "Home1")); } else { ModelState.AddModelError("", "Failed"); return(View()); } }
public ActionResult Delete(Product product) { var northwind = new Models.NorthwindEntities(); var products = northwind.Products; // Get the product being deleted using the posted ProductID var actualProduct = products.FirstOrDefault(p => p.ProductID == product.ProductID); if (actualProduct != null) { // Delete the product products.DeleteObject(actualProduct); // Save the changes in the database northwind.SaveChanges(); } var data = from p in products select new // Use anonymous type to avoid JSON serialization exceptions due to circular object references. Also serialize only the required properties (for performance) { p.Category, p.ProductID, p.ProductName, p.CategoryID }; return View(new GridModel(data)); }