Ejemplo n.º 1
0
        public async Task <UserModel?> GetUserModel(string googleId)
        {
            LoggingService.Trace("Querying UsersDatabase.SaveUserModel");

            if (string.IsNullOrEmpty(googleId))
            {
                return(null);
            }

            var databaseConnection = await GetDatabaseConnection <UserDatabaseModel>().ConfigureAwait(false);

            var dbLock = databaseConnection.GetConnection().Lock();

            try
            {
                var userDatabaseModel = databaseConnection.GetConnection().GetWithChildren <UserDatabaseModel>(googleId);

                return(userDatabaseModel != null?
                       UserDatabaseModel.ToUserModel(userDatabaseModel) :
                           null);
            }
            catch (Exception e)
            {
                LoggingService.Error(e, "Error Querying UsersDatabase.GetUserModel");
                return(null);
            }
            finally
            {
                dbLock.Dispose();
            }
        }
Ejemplo n.º 2
0
        public async Task <int> SaveUserModel(UserModel userModel)
        {
            LoggingService.Trace("Querying UsersDatabase.SaveUserModel");

            var databaseConnection = await GetDatabaseConnection <UserDatabaseModel>().ConfigureAwait(false);

            var dbLock = databaseConnection.GetConnection().Lock();

            try
            {
                var userDatabaseModel = UserDatabaseModel.ToUserDatabaseModel(userModel);

                databaseConnection.GetConnection().InsertOrReplaceWithChildren(userDatabaseModel, true);

                return(0);
            }
            catch (Exception e)
            {
                LoggingService.Error(e, "Error Querying UsersDatabase.SaveUserModel");
                return(1);
            }
            finally
            {
                dbLock.Dispose();
            }
        }
Ejemplo n.º 3
0
 public static UserModel ToUserModel(UserDatabaseModel userDatabaseModel)
 {
     try
     {
         return(new UserModel()
         {
             GoogleId = userDatabaseModel.GoogleId,
             EnlId = userDatabaseModel.EnlId,
             IngressName = userDatabaseModel.IngressName,
             Level = userDatabaseModel.Level,
             LocationKey = userDatabaseModel.LocationKey,
             RocksVerified = userDatabaseModel.RocksVerified,
             VVerified = userDatabaseModel.VVerified,
             Blacklisted = userDatabaseModel.Blacklisted,
             ProfileImage = userDatabaseModel.ProfileImage,
             Raid = userDatabaseModel.Raid,
             Risc = userDatabaseModel.Risc,
             Telegram = string.IsNullOrWhiteSpace(userDatabaseModel.Telegram) ? new TelegramModel() : JsonConvert.DeserializeObject <TelegramModel>(userDatabaseModel.Telegram),
             Teams = userDatabaseModel.Teams ?? new List <UserTeamModel>(),
             Ops = userDatabaseModel.Ops ?? new List <OpModel>(),
             Assignments = userDatabaseModel.Assignments ?? new List <AssignmentModel>()
         });
     }
     catch (Exception)
     {
         return(null);
     }
 }