//Create Customer public JsonResult CreateCustomer(Customer customer) { try { db.Customers.Add(customer); db.SaveChanges(); } catch { throw; } return(new JsonResult { Data = "Customer created", JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
//Create Customer public JsonResult CreateProduct(Product product) { try { db.Products.Add(product); db.SaveChanges(); } catch (Exception e) { Console.Write("Exception Occured /n {0}", e.Data); return(new JsonResult { Data = "Create Product Failed", JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } return(new JsonResult { Data = "Product created", JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
// DELETE Sale public JsonResult DeleteSale(int id) { try { var sale = db.Sales.Where(s => s.SaleID == id).SingleOrDefault(); if (sale != null) { db.Sales.Remove(sale); db.SaveChanges(); } } catch (Exception e) { Console.Write("Exception Occured /n {0}", e.Data); return(new JsonResult { Data = "Deletion Falied", JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } return(new JsonResult { Data = "Success", JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }