public JsonResult Save(CustomersSupplier customersupplier)
        {
            SmallMarketDBEntities db = new SmallMarketDBEntities();

            if (customersupplier.Id > 0)
            {
                var dbcussup = db.CustomersSuppliers.FirstOrDefault(x => x.Id == customersupplier.Id);
                dbcussup.Name               = customersupplier.Name;
                dbcussup.Phone              = customersupplier.Phone;
                dbcussup.TypeId             = customersupplier.TypeId;
                dbcussup.DiscountPurchasing = customersupplier.DiscountPurchasing;
                dbcussup.DiscountSelling    = customersupplier.DiscountSelling;
                db.SaveChanges();
                return(Json(dbcussup, JsonRequestBehavior.AllowGet));
            }
            else
            {
                db.CustomersSuppliers.Add(customersupplier);
            }
            db.SaveChanges();
            return(Json(customersupplier, JsonRequestBehavior.AllowGet));

            {
            }
        }
        public JsonResult SaveItem(Item item)
        {
            SmallMarketDBEntities db = new SmallMarketDBEntities();

            if (item.Id > 0)
            {
                var dbitem = db.Items.FirstOrDefault(x => x.Id == item.Id);
                dbitem.Name          = item.Name;
                dbitem.CategoryId    = item.CategoryId;
                dbitem.PurchasePrice = item.PurchasePrice;
                dbitem.SellPrice     = item.SellPrice;
                dbitem.UnitId        = item.UnitId;
                dbitem.ValidQuantity = item.ValidQuantity;
                db.SaveChanges();
                return(Json(dbitem, JsonRequestBehavior.AllowGet));
            }
            else
            {
                db.Items.Add(item);
            }
            db.SaveChanges();
            return(Json(item, JsonRequestBehavior.AllowGet));

            {
            }
        }
        public JsonResult SaveOrder(PurchaseSellInvoice item)
        {
            bool     status = false;
            DateTime dateOrg;
            var      isValidDate = DateTime.TryParseExact(item.DateString, "mm-dd-yyyy", null, System.Globalization.DateTimeStyles.None, out dateOrg);

            if (isValidDate)
            {
                item.Date = dateOrg;
            }
            var isValidModel = TryUpdateModel(item);

            if (isValidModel)
            {
                using (SmallMarketDBEntities dc = new SmallMarketDBEntities())
                {
                    dc.PurchaseSellInvoices.Add(item);
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public void DeleteItem(int Id)
        {
            SmallMarketDBEntities db = new SmallMarketDBEntities();
            var item = db.Items.FirstOrDefault(x => x.Id == Id);

            db.Items.Remove(item);
            db.SaveChanges();
        }