public ActionResult Inventory_RequestData()
        {
            var gridModel = new InventoryGridModel();

            SetupInventoryGridModel(gridModel.InventoryGrid);

            var invs = (from inv in db.Inventory
                        join unit in db.UnitOfMeasures on inv.UnitOfMeasure equals unit.Id into invunit
                        from iu in invunit.DefaultIfEmpty()
                        select new
            {
                inv.Id,
                inv.Code,
                inv.Name,
                inv.Comment,
                inv.UnitOfMeasure,
                inv.Specs,
                UnitName = iu.Name
            }).ToList();
            var invs2 = invs.Select(s => new
            {
                s.Id,
                s.Code,
                s.Name,
                s.Comment,
                UnitOfMeasure = s.UnitOfMeasure.HasValue ? s.UnitOfMeasure.ToString() : "",
                s.Specs,
                s.UnitName
            }).ToList();

            return(gridModel.InventoryGrid.DataBind(invs2.ToList().AsQueryable()));
        }
        public ActionResult Inventory_EditData(DXInfo.Models.Inventory inv)
        {
            var gridModel = new InventoryGridModel();

            SetupInventoryGridModel(gridModel.InventoryGrid);

            if (gridModel.InventoryGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow)
            {
                using (var context = db)
                {
                    inv.Id = Guid.NewGuid();
                    context.Inventory.Add(inv);
                    context.SaveChanges();
                }
            }
            if (gridModel.InventoryGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                using (var context = db)
                {
                    var oldinv = context.Inventory.Where(w => w.Id == inv.Id).FirstOrDefault();
                    oldinv.Code          = inv.Code;
                    oldinv.Name          = inv.Name;
                    oldinv.Comment       = inv.Comment;
                    oldinv.UnitOfMeasure = inv.UnitOfMeasure;
                    oldinv.Specs         = inv.Specs;
                    context.SaveChanges();
                }
            }
            return(RedirectToAction("Inventory"));
        }
        public ActionResult Inventory()
        {
            var gridModel = new InventoryGridModel();

            SetupInventoryGridModel(gridModel.InventoryGrid);
            return(View(gridModel));
        }