/* * method to add a single UserAlert to UserAlert to * database - passed from Main Activity * -- don't use this to repopulate adapter from database (ticks) */ public static int AddNewUserAlertToDatabase(UserAlert userAlert) { int userAlertID = 0; using (SQLiteConnection conn = new SQLiteConnection(DBLocation)) { try { // insert new UserAlert into database // this won't insert the 'ignored' C# DateTime into the database (only TICKS stored) conn.Insert(userAlert); userAlertID = userAlert.UserAlertID; // display output for testing Log.Debug("DEBUG", "\n\nINSERTED Single User Alert - ID: " + userAlert.UserAlertID.ToString()); Log.Debug("DEBUG", "\n\nINSERTED Single User Alert - ToString:\n" + userAlert.ToString()); Log.Debug("DEBUG", "FINISHED\n\n\n"); } catch { userAlertID = 0; } Log.Debug("DEBUG", "FINISHED\n\n\n"); } // IMPORTANT - set object properties to null - to clear existing data out // - otherwise you get duplicate entries in the UserAlerts database UserAlertsActivity.SelectedNewsObject_PassedFrom_MainActivity = null; UserAlertsActivity.SelectedUserAlert_PassedFrom_PersonalAlertsActivity = null; return(userAlertID); }
public static List <UserAlert> DummyDataForUserAlert() { UserAlert userAlert1 = new UserAlert() { UserAlertID = 1, IsPersonalAlert = false, DateAndTime = new DateTime(2018, 1, 15, 10, 15, 0), DateInTicks = 636516081000000000, CountryChar = "USD", MarketImpact = "High", Title = "Non Farm Payroll" }; UserAlert userAlert2 = new UserAlert() { UserAlertID = 2, IsPersonalAlert = false, DateAndTime = new DateTime(2018, 2, 20, 13, 20, 0), DateInTicks = 636547296000000000, CountryChar = "GBP", MarketImpact = "Low", Title = "Meeting 1" }; UserAlert userAlert3 = new UserAlert() { UserAlertID = 3, IsPersonalAlert = false, DateAndTime = new DateTime(2018, 3, 3, 14, 30, 0), DateInTicks = 636556842000000000, CountryChar = "EUR", MarketImpact = "Medium", Title = "Interest Rate" }; UserAlert userAlert4 = new UserAlert() { UserAlertID = 4, IsPersonalAlert = false, DateAndTime = new DateTime(2018, 8, 6, 11, 00, 0), DateInTicks = 636691500000000000, CountryChar = "AUD", MarketImpact = "Low", Title = "Car Sales monthly" }; // Create UserAlert List List <UserAlert> userAlertsList = new List <UserAlert> { // Add dummy data to User Alert List userAlert1, userAlert2, userAlert3, userAlert4 }; // Return List return(userAlertsList); }// end DummyDataForUserAlert
// method to convert newsObject to userAlert object public static UserAlert ConvertNewsObjectToUserAlert(NewsObject newsObject) { UserAlert userAlert = new UserAlert { // don't assign ID - SQLite will do this automatically when object is inserted into DB Title = newsObject.Title, CountryChar = newsObject.CountryChar, MarketImpact = newsObject.MarketImpact, DateAndTime = newsObject.DateAndTime, DateInTicks = newsObject.DateInTicks, IsPersonalAlert = false, // because this is converting a market event DescriptionOfPersonalEvent = string.Empty }; return(userAlert); }