public static objCM.SessionLike ToModelObj(this dataCM.SessionLike source) { return(new objCM.SessionLike() { CreatedBy = source.CreatedBy, CreatedUtcDate = source.CreatedUtcDate, DataVersion = source.DataVersion, IsDeleted = source.IsDeleted, ModifiedBy = source.ModifiedBy, ModifiedUtcDate = source.ModifiedUtcDate, SessionId = source.SessionId, UserProfileId = source.UserProfileId, }); }
public async Task <bool> ToggleSessionLikeAsync(int sessionId, string sessionIdUserProfileId) { var dataResult = await conn.Table <dataModel.SessionLike>().Where(x => x.SessionIdUserProfileId == sessionIdUserProfileId).FirstOrDefaultAsync(); if (dataResult != null) { // Data record was previously created. dataResult.IsDeleted = !dataResult.IsDeleted; dataResult.ModifiedUtcDate = DateTime.UtcNow; return(1 == await conn.InsertOrReplaceAsync(dataResult)); } else { // Create new data record. if (Preferences.Get(Consts.CURRENT_USER_PROFILE_ID, 0) != 0) { var user = await GetUserByUserProfileIdAsync(Preferences.Get(Consts.CURRENT_USER_PROFILE_ID, 0)); if (user != null) { dataResult = new dataModel.SessionLike() { CreatedBy = user.UserProfileId.ToString(), CreatedUtcDate = DateTime.UtcNow, DataVersion = 1, IsDeleted = false, ModifiedBy = user.UserProfileId.ToString(), ModifiedUtcDate = DateTime.UtcNow, UserProfileId = user.UserProfileId, SessionId = sessionId, SessionIdUserProfileId = sessionIdUserProfileId //$"{sessionId}{user.UserProfileId.ToString()}" }; return(1 == await conn.InsertAsync(dataResult)); } else { Debug.WriteLine("Can't find user in SQLite"); Analytics.TrackEvent($"SetSessionLikeAsync - Can't find user in SQLite - id: {Preferences.Get(Consts.CURRENT_USER_PROFILE_ID, 0)}"); } } else { Debug.WriteLine("No User Logged In"); Analytics.TrackEvent($"SetSessionLikeAsync - No user is logged in"); } } return(false); }