public ActionResult Create(Customer customer) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { bool exist = db.Customer.Where(x => x.Cust_Name == customer.Cust_Name).Any(); Customer cust = new Customer(); cust.Cust_Name = customer.Cust_Name; cust.Cust_Address = customer.Cust_Address; if (!exist) //check to updat eor create { db.Customer.Add(cust); } else { cust = db.Customer.SingleOrDefault(x => x.Cust_Name == customer.Cust_Name); cust.Cust_Name = customer.Cust_Name; cust.Cust_Address = customer.Cust_Address; } // executes the commands to implement the changes to the database db.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
// GET: Sale public ActionResult Index() { var model = new List <SaleInfo>(); using (var db = new Task1Entities()) { var query = (from ps in db.ProductSold join c in db.Customer on ps.Customer_Id equals c.Id join p in db.Product on ps.Product_Id equals p.Id join s in db.Store on ps.Store_Id equals s.Id select new { c.Cust_Name, p.Product_Name, s.Store_Name, ps.Date_Sold }).ToList(); foreach (var item in query) { SaleInfo sale = new SaleInfo(); sale.Cust_Name = item.Cust_Name; sale.Product_Name = item.Product_Name; sale.Store_Name = item.Store_Name; sale.Date_Sold = item.Date_Sold; model.Add(sale); } } return(View("SaleIndex", model)); }
public ActionResult Create(Store store) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { bool exist = db.Store.Where(x => x.Store_Name == store.Store_Name).Any(); Store str = new Store(); str.Store_Name = store.Store_Name; str.Store_Address = store.Store_Address; if (!exist) //check to updat eor create { db.Store.Add(str); } else { str = db.Store.SingleOrDefault(x => x.Store_Name == store.Store_Name); str.Store_Name = store.Store_Name; str.Store_Address = store.Store_Address; } // executes the commands to implement the changes to the database db.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
public ActionResult Product_Create(Product product) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { bool exist = db.Product.Where(x => x.Product_Name == product.Product_Name).Any(); Product prod = new Product(); prod.Product_Name = product.Product_Name; prod.Product_Price = product.Product_Price; if (!exist) //check to updat eor create { db.Product.Add(prod); } else { prod = db.Product.SingleOrDefault(x => x.Product_Name == product.Product_Name); prod.Product_Name = product.Product_Name; prod.Product_Price = product.Product_Price; } // executes the commands to implement the changes to the database db.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
public JsonResult List() { using (var db = new Task1Entities()) { var customer = db.Customer.Select(x => new { x.Id, x.Cust_Name, x.Cust_Address, }).ToList(); return(Json(customer, JsonRequestBehavior.AllowGet)); } }
// GET: Customer/Delete/5 public ActionResult Delete(int id) { Customer customer = new Customer(); using (var db = new Task1Entities()) { var query = db.Customer.Where(row => row.Id == id); foreach (var item in query) { customer.Cust_Name = item.Cust_Name; customer.Cust_Address = item.Cust_Address; customer.Id = item.Id; } } return(View(customer)); }
// GET: Store/Details/5 public ActionResult Details(int id) { Product product = new Product(); using (var db = new Task1Entities()) { var query = db.Product.Where(row => row.Id == id); foreach (var item in query) { product.Product_Name = item.Product_Name; product.Product_Price = item.Product_Price; product.Id = item.Id; } } return(View("ProductDetails", product)); }
// GET: Store/Delete/5 public ActionResult Delete(int id) { Store store = new Store(); using (var db = new Task1Entities()) { var query = db.Store.Where(row => row.Id == id); foreach (var item in query) { store.Store_Name = item.Store_Name; store.Store_Address = item.Store_Address; store.Id = item.Id; } } return(View(store)); }
// GET: Customer/Edit/5 public ActionResult Edit(int id) { var model = new List <Customer>(); Customer customer = new Customer(); using (var db = new Task1Entities()) { var query = db.Customer.Where(row => row.Id == id); foreach (var item in query) { customer.Cust_Name = item.Cust_Name; customer.Cust_Address = item.Cust_Address; customer.Id = item.Id; model.Add(customer); } } return(View("CustomerIndex", model)); }
public ActionResult Delete(int id, Product product) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { Product prod = db.Product.SingleOrDefault(x => x.Id == product.Id); db.Product.Remove(prod); db.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
// GET: Store/Edit/5 public ActionResult Edit(int id) { var model = new List <Product>(); Product product = new Product(); using (var db = new Task1Entities()) { var query = db.Product.Where(row => row.Id == id); foreach (var item in query) { product.Product_Name = item.Product_Name; product.Product_Price = item.Product_Price; product.Id = item.Id; model.Add(product); } } return(View("Product", model)); }
public ActionResult Delete(int id, Customer customer) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { Customer cust = db.Customer.SingleOrDefault(x => x.Id == customer.Id); db.Customer.Remove(cust); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { Console.WriteLine(ex.InnerException); return(View()); } }
// GET: Store public ActionResult Index() { var model = new List <Product>(); using (var db = new Task1Entities()) { var query = db.Product.Select(row => row); foreach (var item in query) { Product product = new Product(); product.Product_Name = item.Product_Name; product.Product_Price = item.Product_Price; product.Id = item.Id; model.Add(product); } } return(View("Product", model)); }
public ActionResult Edit(int id, Product product) { try { // TODO: Add insert logic here using (var db = new Task1Entities()) { Product prod = db.Product.SingleOrDefault(x => x.Product_Name == product.Product_Name); prod.Product_Name = product.Product_Name; prod.Product_Price = product.Product_Price; // executes the commands to implement the changes to the database db.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
// GET: Store public ActionResult Index() { var model = new List <Store>(); using (var db = new Task1Entities()) { var query = db.Store.Select(row => row); foreach (var item in query) { Store store = new Store(); store.Store_Name = item.Store_Name; store.Store_Address = item.Store_Address; store.Id = item.Id; model.Add(store); } } return(View("StoreIndex", model)); }
// GET: Customer public ActionResult Index() { var model = new List <Customer>(); using (var db = new Task1Entities()) { var query = db.Customer.Select(row => row); foreach (var item in query) { Customer customer = new Customer(); customer.Cust_Name = item.Cust_Name; customer.Cust_Address = item.Cust_Address; customer.Id = item.Id; model.Add(customer); } // var data1 = new JavaScriptSerializer().Deserialize(customer, typeof(IEnumerable<Customer>)); } return(View("CustomerIndex", model)); }