public JsonResult UpdateStore(Store s)
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         dbobj.Entry(s).State = EntityState.Modified;
         dbobj.SaveChanges();
         return(Json(new { success = true, message = "saved" }, JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult AddStore(Store s)
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         dbobj.Stores.Add(s);
         dbobj.SaveChanges();
         return(RedirectToAction("GetStore"));
     }
 }
 //to get product by id
 public ActionResult GetStoreById(int id)
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         dbobj.Configuration.ProxyCreationEnabled = false;
         var s = dbobj.Stores.Where(x => x.SId == id).FirstOrDefault();
         return(Json(s, JsonRequestBehavior.AllowGet));
     }
 }
 public JsonResult RemoveProduct(int ID)
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         ProductSold psold = dbobj.ProductSolds.Find(ID);
         dbobj.ProductSolds.Remove(psold);
         return(Json(dbobj.SaveChanges(), JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult AddCustomer(Customer c)
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         dbobj.Customers.Add(c);
         dbobj.SaveChanges();
         return(RedirectToAction("GetCustomer"));
     }
 }
 public JsonResult Update(ProductSold psold)
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         dbobj.Entry(psold).State = EntityState.Modified;
         dbobj.SaveChanges();
         return(Json(dbobj.SaveChanges(), JsonRequestBehavior.AllowGet));
     }
 }
        // to add
        public JsonResult Add(ProductSold psold)
        {
            using (ProductSoldEntities dbobj = new ProductSoldEntities())
            {
                dbobj.ProductSolds.Add(psold);

                return(Json(dbobj.SaveChanges(), JsonRequestBehavior.AllowGet));
            }
        }
 public ActionResult AddProduct(Product p)
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         dbobj.Products.Add(p);
         dbobj.SaveChanges();
         return(RedirectToAction("GetProduct"));
     }
 }
 public ActionResult DeleteStore(int id)
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         var store = dbobj.Stores.Where(x => x.SId == id).FirstOrDefault();
         dbobj.Stores.Remove(store);
         dbobj.SaveChanges();
         return(Json(new { success = true, message = "deleted" }, JsonRequestBehavior.AllowGet));
     }
 }
        // GET: ProductSold
        public ActionResult PSIndex()
        {
            ProductSoldEntities dbobj = new ProductSoldEntities();
            var psold = new ProductSold();

            ViewBag.CustomerId = new SelectList(dbobj.Customers, "CId", "CustomerName", psold.CustomerId);
            ViewBag.ProductId  = new SelectList(dbobj.Products, "PId", "ProductName", psold.ProductId);
            ViewBag.StoreId    = new SelectList(dbobj.Stores, "SId", "StoreName", psold.StoreId);
            return(View());
        }
 //get list of store
 public JsonResult GetStore()
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         //dbobj.Configuration.ProxyCreationEnabled = false;
         var s = dbobj.Stores.Select(x => new
         {
             SId          = x.SId,
             StoreName    = x.StoreName,
             StoreAddress = x.StoreAddress,
         }).ToList();
         return(Json(new { data = s }, JsonRequestBehavior.AllowGet));
     }
 }
 public JsonResult GetbyID(int id)
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         var ProductSold = dbobj.ProductSolds.Where(x => x.PSId == id).Select(x => new ProductSoldViewModel
         {
             PSId       = x.PSId,
             CustomerId = x.CustomerId,
             StoreId    = x.StoreId,
             ProductId  = x.ProductId
         }).FirstOrDefault();
         return(Json(ProductSold, JsonRequestBehavior.AllowGet));
     }
 }
 //list of all customers
 public JsonResult GetCustomer()
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         //dbobj.Configuration.ProxyCreationEnabled = false;
         var c = dbobj.Customers.Select(x => new
         {
             CId             = x.CId,
             CustomerName    = x.CustomerName,
             CustomerAddress = x.CustomerAddress,
         }).ToList();
         return(Json(new { data = c }, JsonRequestBehavior.AllowGet));
     }
 }
 //get list of product
 public JsonResult GetProduct()
 {
     using (ProductSoldEntities dbobj = new ProductSoldEntities())
     {
         // dbobj.Configuration.ProxyCreationEnabled = false;
         var p = dbobj.Products.Select(x => new
         {
             PId          = x.PId,
             ProductName  = x.ProductName,
             ProductPrice = x.ProductPrice,
         }).ToList();
         return(Json(new { data = p }, JsonRequestBehavior.AllowGet));
     }
 }
        // to get list
        public JsonResult GetProductSold()
        {
            using (ProductSoldEntities dbobj = new ProductSoldEntities())
            {
                var productsold = dbobj.ProductSolds.Include(s => s.Customer).Include(s => s.Product).Include(s => s.Store).Select(x => new
                {
                    PSId       = x.PSId,
                    ProductId  = x.Product.ProductName,
                    CustomerId = x.Customer.CustomerName,
                    StoreId    = x.Store.StoreName
                }).ToList();

                return(Json(productsold, JsonRequestBehavior.AllowGet));
            }
        }