Beispiel #1
0
        /*
         * // SUMMARY
         * // Edit or Delete Data from JSON FILE and updates the DBInstance and JSON File with the new data
         * // Return: bool (True/False)
         */
        public bool edit_delete_item(Item item, string action, List <DataGrid> dgList, UIRuntime runtime)
        {
            bool success = false;

            //UpdateDBObject the databaseobject to get the most recent data
            DBInstance = UpdateDBObject();

            try
            {
                var pastItem = DBInstance.Items.FindIndex(x => x.id == item.id);

                if (action == "edit")
                {
                    DBInstance.Items[pastItem] = item;
                    success = SaveDB(DBInstance);
                }
                else if (action == "delete")
                {
                    DBInstance.Items.RemoveAt(pastItem);
                    success = SaveDB(DBInstance);
                }
                runtime.PopulateAllDataGrids(dgList, DBInstance);
                return(success);
            }
            catch (Exception es)
            {
                MessageBox.Show("Error mientras se editaba el item. Error: " + es.Message);
                return(success);
            }
        }
Beispiel #2
0
        /*
         * // SUMMARY
         * // Insert data of a new item on JSON FILE writing the current data and updates the DBInstance with the new data
         * // Return: bool (True/False)
         */
        public bool CreateItem(Item Newitem, List <DataGrid> dgList, UIRuntime runtime)
        {
            bool success = false;

            //UpdateDBObject the databaseobject to get the most recent data
            DBInstance = UpdateDBObject();

            try
            {
                DBInstance.Items.Add(Newitem);
                success = SaveDB(DBInstance);
                runtime.PopulateAllDataGrids(dgList, DBInstance);
                return(success);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(success);
            }
        }