示例#1
0
 public bool UpdateData(MultiModel multiModel)
 {
     try
     {
         databaseContext.Entry(multiModel.PersonDataTable).State = EntityState.Modified;
         databaseContext.SaveChanges();
         return(true);
     }
     catch (Exception Ex)
     {
         LogWriter.Exception("Error updating data.", Ex);
         return(false);
     }
 }
示例#2
0
 public bool AddData(MultiModel multiModel)
 {
     try
     {
         multiModel.PersonDataTable.AddressData = multiModel.AddressDataTable;
         multiModel.PersonDataTable.DetailsData = multiModel.DetailsDataTable;
         databaseContext.PersonData.Add(multiModel.PersonDataTable);
         databaseContext.SaveChanges();
         SQLConnection.UpdateTableCount(1);
         return(true);
     }
     catch (Exception Ex)
     {
         LogWriter.Exception("Error updating data.", Ex);
         return(false);
     }
 }
        private void Testing5_Click(object sender, RoutedEventArgs e)
        {
            SQLFunctions sqlFunctions = new SQLFunctions(SQLConnection.DatabaseContext);
            MultiModel   multiModel   = new MultiModel()
            {
                PersonDataTable  = new PersonData(),
                AddressDataTable = new AddressData(),
                DetailsDataTable = new DetailsData(),
            };

            multiModel.Firstname = "Test Add";
            multiModel.Lastname  = "Last";
            multiModel.City      = "Some Test City";
            multiModel.Age       = "100";

            sqlFunctions.AddData(multiModel);
            showRecords("Add");
        }
示例#4
0
        public bool DeleteData(MultiModel multiModel)
        {
            try
            {
                // Although my SQL table is set to cascade, I am going to be safe and delete the tables individually.
                databaseContext.Entry(multiModel.AddressDataTable).State = EntityState.Deleted;
                databaseContext.Entry(multiModel.DetailsDataTable).State = EntityState.Deleted;
                databaseContext.SaveChanges();

                databaseContext.Entry(multiModel.PersonDataTable).State = EntityState.Deleted;
                databaseContext.SaveChanges();

                SQLConnection.UpdateTableCount(-1);
                return(true);
            }
            catch (Exception Ex)
            {
                LogWriter.Exception("Error updating data.", Ex);
                return(false);
            }
        }