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 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));

            {
            }
        }
        // Get: customer/supplier type
        public JsonResult SupplierCustomerType()
        {
            SmallMarketDBEntities db   = new SmallMarketDBEntities();
            var CustomersSuppliersType = db.CustomerSuppliertypes.ToList();

            return(Json(CustomersSuppliersType, JsonRequestBehavior.AllowGet));
        }
        // retrieve all categories
        public JsonResult GetAllCategories()
        {
            SmallMarketDBEntities db = new SmallMarketDBEntities();
            var categories           = db.Categories.ToList();

            return(Json(categories, 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));

            {
            }
        }
        // retrive all units

        public JsonResult GetAllUnits()
        {
            SmallMarketDBEntities db = new SmallMarketDBEntities();
            var units = db.Units.ToList();

            return(Json(units, JsonRequestBehavior.AllowGet));
        }
        protected override void Dispose(bool disposing)
        {
            SmallMarketDBEntities db = new SmallMarketDBEntities();

            db.Dispose();
            base.Dispose(disposing);
        }
        // GET: /Item By Id
        public JsonResult GetItemById(string Id)
        {
            SmallMarketDBEntities db = new SmallMarketDBEntities();
            var itemId    = Convert.ToInt32(Id);
            var getItemId = db.Items.Find(itemId);

            return(Json(getItemId, JsonRequestBehavior.AllowGet));
        }
        public void DeleteItem(int Id)
        {
            SmallMarketDBEntities db = new SmallMarketDBEntities();
            var item = db.Items.FirstOrDefault(x => x.Id == Id);

            db.Items.Remove(item);
            db.SaveChanges();
        }
        //GET: All Customers and suppliers
        public JsonResult CustomersSuppliers()
        {
            List <CustomersSupplier> CustomersSuppliers = new List <CustomersSupplier>();

            using (SmallMarketDBEntities db = new SmallMarketDBEntities())
            {
                CustomersSuppliers = db.CustomersSuppliers.OrderBy(a => a.Name).ToList();
            }
            return(Json(CustomersSuppliers, JsonRequestBehavior.AllowGet));
        }
        //
        //GET: All Items

        public JsonResult AllItems()
        {
            List <Item> items = new List <Item>();

            using (SmallMarketDBEntities db = new SmallMarketDBEntities())
            {
                items = db.Items.OrderBy(a => a.Name).ToList();
            }
            return(Json(items, JsonRequestBehavior.AllowGet));
        }
        // Get: All Customers
        public JsonResult AllCustomersSuppliers()
        {
            SmallMarketDBEntities db   = new SmallMarketDBEntities();
            var customerssuppliersList = from pr in db.CustomersSuppliers

                                         join ty in db.CustomerSuppliertypes
                                         on pr.TypeId equals ty.Id
                                         select new
            {
                pr.Id,
                pr.Name,
                pr.Phone,
                pr.TypeId,
                pr.DiscountPurchasing,
                pr.DiscountSelling,
                TypeName = ty.Name
            };

            return(Json(customerssuppliersList, JsonRequestBehavior.AllowGet));
        }
        // GET: /Items/
        public JsonResult AllItems()
        {
            SmallMarketDBEntities db = new SmallMarketDBEntities();
            var items = from pr in db.Items

                        join ct in db.Categories
                        on pr.CategoryId equals ct.Id
                        join un in db.Units
                        on pr.UnitId equals un.Id
                        select new
            {
                pr.Id,
                pr.Name,
                pr.UnitId,
                pr.CategoryId,
                pr.PurchasePrice,
                pr.SellPrice,
                pr.ValidQuantity,
                UnName  = un.Name,
                CatName = ct.Name
            };

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