예제 #1
0
        public ActionResult WarehouseEditRows(Warehouse editedItem)
        {
            // Get the grid and database models
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();

            // If we are in "Edit" mode
            if (gridModel.WarehouseGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                // Get the data from and find the item corresponding to the edited row
                Warehouse item = (from x in datacontextModel.Warehouses
                                    where x.WarehouseId == editedItem.WarehouseId
                                    select x).First<Warehouse>();

                // update the item information
                UpdateWarehouse(item, editedItem);

                datacontextModel.SaveChanges();
            }

            if (gridModel.WarehouseGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow)
            {
                // since we are adding a new item, create a new istance
                Warehouse item = new Warehouse();
                // set the new item information
                UpdateWarehouse(item, editedItem);

                datacontextModel.Warehouses.Add(item);
                datacontextModel.SaveChanges();
            }
            if (gridModel.WarehouseGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                Warehouse item = (from x in datacontextModel.Warehouses
                                    where x.WarehouseId == editedItem.WarehouseId
                                    select x)
                               .First<Warehouse>();

                // delete the record
                datacontextModel.Warehouses.Remove(item);
                datacontextModel.SaveChanges();
            }

            return RedirectToAction("Warehouse", "MyCompany");
        }
예제 #2
0
 private void UpdateWarehouse(Warehouse item, Warehouse editedItem)
 {
     item.Name = editedItem.Name;
     item.Code = editedItem.Code;
     item.Address = editedItem.Address;
     item.Comment = editedItem.Comment;
     if (editedItem.WarehouseId != editedItem.ParentId)
         item.ParentId = editedItem.ParentId;
 }