/// <summary>
        /// Deletes all of the synonyms for a user by id
        /// </summary>
        /// <returns>true or false depending on success</returns>
        public bool DeleteAllSynonymsForUser(int userId)
        {
            List<UserSynonym> uSynModels = GetSynonymForUser(userId);

            using (var db = new BlissBaseContext(testing))
            {
                foreach (UserSynonym model in uSynModels)
                {
                    db.UserSynonyms.Remove(new UserSynonyms
                    {
                        USynID = model.uSynId,
                        USynApproved = model.uSynApproved,
                        USynSynonym = model.uSynSynonym,
                        USynWord = model.uSynWord
                    });
                }
                try
                {
                    db.SaveChanges();
                    return true;
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Exception when deleting all synonyms for user: " + userId);
                    Debug.WriteLine(e.StackTrace);
                    return false;
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Deletes exacly one Symbol by id in Symbols table,
 /// deletes all the entries of the symbol in CompositesOf table
 /// </summary>
 /// <param name="id"></param>
 /// <returns>true false depending on success</returns>
 public bool DeleteExact(int id)
 {
     using (var db = new BlissBaseContext(testing))
     {
         Symbols sym = db.Symbols.Find(id);
         try
         {
             // Deletes the relations where the symbol is a component of
             // a composite symbol
             var compOf = new CompositeOfDAL();
             compOf.DeleteBySymbolID(id);
             // Sets the symbol as a standard type (Deletes it from
             // SymbolTypes table)
             var type = new SymbolTypeDAL();
             type.SetStandardForSymID(id);
             // Deletes the symbol from Symbols table
             db.Symbols.Remove(sym);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             Debug.WriteLine("Exception when remowing symbol: " + id);
             Debug.WriteLine(e.StackTrace);
             return false;
         }
     }
     return true;
 }
예제 #3
0
 /// <summary>
 /// Returns a Language model for all composite symbols that has a
 /// entry in Languages table "aka non international"
 /// </summary>
 /// <returns>List of BlissBase.Model.Language or null</returns>
 public List<Language> GetAllNonInternational()
 {
     using (var db = new BlissBaseContext(testing))
     {
         return db.Languages.Select(l => new Language
         {
             compId = l.CompID,
             langCode = l.LangCode
         }).ToList();
     }
 }
예제 #4
0
 public void TestOpenTestDatabase()
 {
     try
     {
         using (var db = new BlissBaseContext(testing))
         {
         }
     }
     catch (Exception e)
     {
         Assert.Fail(e.StackTrace);
     }
 }
예제 #5
0
        /// <summary>
        /// Returns all composite symbols that is GlobalSynonyms
        /// </summary>
        /// <returns>List of BlissBase.Model.GlobalSynonym or null</returns>
        public List<GlobalSynonym> GetAll()
        {
            using (var db = new BlissBaseContext(testing))
            {

                List<GlobalSynonym> allGlobalSynonyms = db.GlobalSynonyms.Select(g => new GlobalSynonym()
                {
                    gSynId = g.GSynID,
                    gSynSynonym = g.GSynSynonym,
                    gSynWord = g.GSynWord
                }
                    ).ToList();
                return (allGlobalSynonyms.Count == 0) ? allGlobalSynonyms : null;
            }
        }
예제 #6
0
        /// <summary>
        /// Returns all composite symbols that is in UserSynonyms table
        /// </summary>
        /// <returns>List of BlissBase.Model.UserSynonym</returns>
        public List<UserSynonym> GetAll()
        {
            using (var db = new BlissBaseContext(testing))
            {

                List<UserSynonym> allUserSynonyms = db.UserSynonyms.Select(u => new UserSynonym()
                {
                    uSynId = u.USynID,
                    uSynSynonym = u.USynSynonym,
                    uSynWord = u.USynWord,
                    uListUserId = u.UserID,
                    uSynApproved = u.USynApproved
                }).ToList();
                return (allUserSynonyms.Count == 0) ? allUserSynonyms : null;
            }
        }
 /// <summary>
 /// Deletes all the symbols in the RawSymbolsImport table
 /// </summary>
 /// <returns>true or false depending on success</returns>
 public bool DeleteAll()
 {
     using (var db = new BlissBaseContext(testing))
     {
         try
         {
             db.Database.ExecuteSqlCommand("TRUNCATE TABLE [RawSymbolsImport]");
             db.SaveChanges();
         }
         catch (Exception e)
         {
             Debug.WriteLine("Exception trying to TRUNCATE table RawSymbolsImport");
             Debug.WriteLine(e.StackTrace);
             return false;
         }
     }
     return true;
 }
 /// <summary>
 /// Deletes the row in the CompositScores table
 /// that corresponds to the given id. 
 /// Returns true if successfull, else false
 /// </summary>
 /// <param name="id"></param>
 /// <returns>true or false depending on success</returns>
 public bool RemoveScoreFor(int id)
 {
     using (var db = new BlissBaseContext(testing))
     {
         try
         {
             var toRemove = db.CompositeScores.Find(id);
             db.CompositeScores.Remove(toRemove);
             return true;
         }
         catch (Exception e)
         {
             Debug.WriteLine("Exception when trying to delete score for id: " + id);
             Debug.WriteLine(e.StackTrace);
             return false;
         }
     }
 }
예제 #9
0
 /// <summary>
 /// Deletes row in UserSynonyms where UsynSynonym == id
 /// For the synonym found, the CompositeSymbol with CompId == id
 /// will be deleted
 /// </summary>
 /// <param name="id"></param>
 /// <returns>true or false</returns>
 public bool DeleteSynonym(int id)
 {
     using (var db = new BlissBaseContext(testing))
     {
         try
         {
             UserSynonyms toRemove = db.UserSynonyms.Find(id);
             db.UserSynonyms.Remove(toRemove);
             db.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             Debug.WriteLine("Exception when deleting user synonym: " + id);
             Debug.WriteLine(e.StackTrace);
             return false;
         }
     }
 }
예제 #10
0
 /// <summary>
 /// Returns score for a compositeSymbol by id as int
 /// Returns 0 if no score exists for given id
 /// </summary>
 /// <param name="id"></param>
 /// <returns>score as int or 0</returns>
 public int GetScoreFor(int id)
 {
     using (var db = new BlissBaseContext(testing))
     {
         int score;
         try
         {
             score = db.CompositeScores.Find(id).CompScore;
         }
         catch (Exception e)
         {
             Debug.WriteLine("A exception was thrown when checking score for CompositeSymbol: " + id +
                 " 'symbol might not have a score set yet!', check stacktrace");
             Debug.WriteLine(e.StackTrace);
             return 0;
         }
         return score;
     }
 }
예제 #11
0
 /// <summary>
 /// Gets all entries in SymbolTypes
 /// </summary>
 /// <returns>List of BlissBase.Model.SymbolType or null</returns>
 public List<SymbolType> GetAllNonStandard()
 {
     try
     {
         using (var db = new BlissBaseContext(testing))
         {
             return db.SymbolTypes.Select(t => new SymbolType
             {
                 symId = t.SymID,
                 typeIndicator = t.TypeIndicator
             }).ToList();
         }
     } catch (Exception e)
     {
         Debug.WriteLine("An exception was thrown when trying to get all entries in SymbolTypes.");
         Debug.WriteLine(e.StackTrace);
         return null;
     }
 }
예제 #12
0
 /// <summary>
 /// Removes a users admin privileges
 /// </summary>
 /// <param name="id"></param>
 /// <returns>true or false depending on success,
 /// if user is currently not an admin true is returned</returns>
 public bool DisableUserAdmin(int id)
 {
     Admins toRemove = GetExcactByUserId(id);
     if (toRemove != null)
     {
         try
         {
             using (BlissBaseContext db = new BlissBaseContext(testing))
             {
                 db.Admins.Remove(toRemove);
                 db.SaveChanges();
             }
         }
         catch (Exception e)
         {
             Debug.WriteLine("A exception was thrown when remowing admin permissions for user: " + id);
             Debug.WriteLine(e.StackTrace);
             return false;
         }
     }
     return true;
 }
예제 #13
0
 /// <summary>
 /// Deletes all rows in CompositesOf table by CompID
 /// </summary>
 /// <param name="composit"></param>
 /// <returns>true or false depending on success</returns>
 public bool DeleteByCompositeSymbol(CompositeSymbol composit)
 {
     using (var db = new BlissBaseContext(testing))
     {
         var composedOf = db.CompositesOf.Where(c => c.CompID == composit.compId);
         foreach (CompositesOf comp in composedOf)
         {
             db.CompositesOf.Remove(comp);
         }
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             Debug.WriteLine("Exception occured when deleting composed of composite relation");
             Debug.WriteLine(e.StackTrace);
             return false;
         }
         return true;
     }
 }
예제 #14
0
        /// <summary>
        /// Checks if username currently exists
        /// </summary>
        /// <param name="username"></param>
        /// <returns>true or false</returns>
        public bool CheckIfUsernameExists(string username)
        {
            using (var db = new BlissBaseContext(testing))
            {
                var users = db.Users.Select(u => new User
                {
                    userId = u.UserID,
                    username = u.UserName,
                    userFirstName = u.UserFirstName,
                    userLastName = u.UserLastName,
                    userApproved = u.UserApproved
                }).ToList();

                foreach (User user in users)
                {
                    if (user.username == username)
                    {
                        return true;
                    }
                }

                return false;
            }
        }
예제 #15
0
 /// <summary>
 /// Gets an exact user with all information
 /// as a Users table row
 /// </summary>
 /// <param name="id"></param>
 /// <returns>BlissBase.DAL.Users or null</returns>
 internal Users GetExactRow(int id)
 {
     using (var db = new BlissBaseContext(testing))
     {
         return db.Users.Find(id);
     }
 }
예제 #16
0
 /// <summary>
 /// Takes a users id and bool status as parameters. Updates the given user's
 /// UserApproved status and sets it to status
 /// </summary>
 /// <param name="id"></param>
 /// <param name="status"></param>
 /// <returns>true or false depending on success</returns>
 public bool UpdateUserApproved(int id, bool status)
 {
     try
     {
         using (var db = new BlissBaseContext(testing))
         {
             Users toApprove = db.Users.Find(id);
             toApprove.UserApproved = status;
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("An exception was thrown when changing userId: " + id +
             " to approved status = " + status);
         Debug.WriteLine(e.StackTrace);
         return false;
     }
 }
예제 #17
0
        /// <summary>
        /// Takes a pasword and a username as two strings
        /// If user with username exists in BlissBase.DAL.Users table
        /// then the salt is collected and the password checked if match
        /// Returns the user as User object or null. If the user exists but
        /// is not approved null is returned
        /// </summary>
        /// <param name="passwd"></param>
        /// <param name="username"></param>
        /// <returns>BlissBase.Model.User or null</returns>
        public User LogInnUser(string passwd, string username)
        {
            using (var db = new BlissBaseContext(testing))
            {
                if (db.Users.Count() == 0)
                {
                    return null;
                }

                User toLogInn = db.Users.Where(u => username == u.UserName).Select(u => new User
                {
                    userId = u.UserID,
                    username = u.UserName,
                    userFirstName = u.UserFirstName,
                    userLastName = u.UserLastName,
                    userPasswd = u.UserPasswd,
                    userSalt = u.UserSalt,
                    userApproved = u.UserApproved
                }).First();

                if (toLogInn.userApproved &&
                        toLogInn.userPasswd == hashString(passwd + toLogInn.userSalt))
                    return toLogInn;
            }
            return null;
        }
예제 #18
0
        /// <summary>
        /// Takes a BlissBase.Model.User and inserts it
        /// to the BlissBase.DAL.Users table.
        /// The user is not approved and is awaiting approval by admin
        /// </summary>
        /// <param name="user"></param>
        /// <returns>true if successfull, else throws Exception</returns>
        public bool InsertUser(User user)
        {
            using (var db = new BlissBaseContext(testing))
            {
                string salt = generateSalt();

                Users toAdd = new Users
                {
                    UserID = user.userId,
                    UserName = user.username,
                    UserFirstName = user.userFirstName,
                    UserLastName = user.userLastName,
                    UserSalt = salt,
                    UserPasswd = hashString(user.userPasswd + salt),
                    UserApproved = false
                };
                try
                {
                    db.Users.Add(toAdd);
                    db.SaveChanges();
                    return true;
                }
                catch
                {
                    throw;
                }
            }
        }
예제 #19
0
 /// <summary>
 /// Gets all the users "whithout password or salt"
 /// </summary>
 /// <returns>List of BlissBase.Model.User or null</returns>
 public List<User> GetAllWithoutPasswd()
 {
     using (var db = new BlissBaseContext(testing))
     {
         return db.Users.Select(u => new User
         {
             userId = u.UserID,
             username = u.UserName,
             userFirstName = u.UserFirstName,
             userLastName = u.UserLastName,
             userApproved = u.UserApproved
         }).ToList();
     }
 }
 /// <summary>
 /// Delete user from UsersSynonymsList table by users Id
 /// </summary>
 /// <param name="userId"></param>
 /// <returns>true or false depending on success</returns>
 public bool DeleteUser(int userId)
 {
     using (var db = new BlissBaseContext(testing))
     {
         try
         {
             UserSynonymList toRemove = FindUser(userId);
             if (toRemove != null)
             {
                 db.UsersSynonymsList.Remove(new UsersSynonymsList
                 {
                     UserID = toRemove.uListUserId
                 });
             }
             db.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             Debug.WriteLine("Exception removing user: "******" synonym list");
             Debug.WriteLine(e.StackTrace);
             return false;
         }
     }
 }
예제 #21
0
        /// <summary>
        /// Sets a non international language for a CompID
        /// </summary>
        /// <param name="compId"></param>
        /// <param name="code"></param>
        /// <returns>true or false depending on success</returns>
        public bool SetLanguageForCompID(int compId, LanguageCodes code)
        {
            var toAdd = new Languages
            {
                CompID = compId,
                LangCode = code
            };

            try
            {
                using (var db = new BlissBaseContext(testing))
                {
                    db.Languages.Add(toAdd);
                    db.SaveChanges();
                    return true;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("An exception was thrown when defining composite symbol: " + compId +
                    " as non international, with LanguageCodes: " + code);
                Debug.WriteLine(e.StackTrace);
                return false;
            }
        }
예제 #22
0
 /// <summary>
 /// Sets a user synonym to approved or not
 /// </summary>
 /// <param name="bit"></param>
 /// <returns>true or false depending on successfulness</returns>
 public bool SetUserSynonymApproved(int uSynId, bool bit)
 {
     using (var db = new BlissBaseContext(testing))
     {
         UserSynonyms toEdit = db.UserSynonyms.Find(uSynId);
         if (toEdit != null)
         {
             try
             {
                 toEdit.USynApproved = bit;
                 db.SaveChanges();
                 return true;
             }
             catch (Exception e)
             {
                 Debug.WriteLine("Exception when approving user synonym: " + uSynId);
                 Debug.WriteLine(e.StackTrace);
             }
         }
     }
     return false;
 }
예제 #23
0
        /// <summary>
        /// Creates and inserts a synonym to the CompositeSymblos, 
        /// and defines it as a UserSynonym
        /// </summary>
        /// <param name="word"></param>
        /// <param name="name"></param>
        /// <param name="components"></param>
        /// <returns>true or false depending on success</returns>
        public bool InsertSynonym(CompositeSymbol word, string name, List<Symbol> components)
        {
            var composite = new CompositeSymbolDAL();

            CompositeSymbol synonym = composite.CreateCompositeByComponents(name, components);
            int synonymId = composite.Insert(synonym, components);

            using (var db = new BlissBaseContext(testing))
            {
                try
                {
                    db.UserSynonyms.Add(new UserSynonyms { USynWord = word.compId, USynSynonym = synonymId });
                    db.SaveChanges();
                    return true;
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Exception when trying to link new user synonym: " + synonymId + " with word: " + word.compId);
                    Debug.WriteLine(e.StackTrace);
                    return false;
                }
            }
        }
예제 #24
0
        /// <summary>
        /// Returns all UserSynonyms for a CompositeSymbol "word"
        /// </summary>
        /// <param name="word"></param>
        /// <returns>List of BlissBase.Model.UserSynonym or null</returns>
        public List<UserSynonym> GetSynonymForWord(CompositeSymbol word)
        {
            List<UserSynonym> allUserSynonymsForWord = new List<UserSynonym>();

            using (var db = new BlissBaseContext(testing))
            {
                allUserSynonymsForWord = db.UserSynonyms.Where(uS => uS.USynWord == word.compId).Select(
                    uS => new UserSynonym
                    {
                        uSynId = uS.USynID,
                        uSynWord = uS.USynWord,
                        uSynSynonym = uS.USynSynonym,
                        uListUserId = uS.UserID,
                        uSynApproved = uS.USynApproved
                    }).ToList();
            }
            return allUserSynonymsForWord.Count == 0 ? null : allUserSynonymsForWord;
        }
예제 #25
0
        /// <summary>
        /// Return all User synonyms for a user's list id "uListUserId"
        /// </summary>
        /// <param name="user"></param>
        /// <returns>List of BlissBase.Model.UserSynonym or null</returns>
        public List<UserSynonym> GetSynonymForUser(UserSynonymList user)
        {
            List<UserSynonym> allSynonymsForUser = new List<UserSynonym>();

            using (var db = new BlissBaseContext(testing))
            {
                allSynonymsForUser = db.UserSynonyms.Where(uS => uS.UserID == user.uListUserId).Select(
                    uS => new UserSynonym
                    {
                        uSynId = uS.USynID,
                        uSynWord = uS.USynWord,
                        uSynSynonym = uS.USynSynonym,
                        uListUserId = uS.UserID,
                        uSynApproved = uS.USynApproved
                    }).ToList();
            }
            return allSynonymsForUser.Count == 0 ? null : allSynonymsForUser;
        }
예제 #26
0
 /// <summary>
 /// Returns exacly one UserSynonym by id
 /// or null if none exists.
 /// </summary>
 /// <param name="id"></param>
 /// <returns>BlissBase.Model.UserSynonym or null</returns>
 public UserSynonym GetExactSynonym(int id)
 {
     using (var db = new BlissBaseContext(testing))
     {
         UserSynonyms row = db.UserSynonyms.Find(id);
         if (row != null)
             return new UserSynonym()
             {
                 uSynId = row.USynID,
                 uSynWord = row.USynWord,
                 uSynSynonym = row.USynSynonym,
                 uListUserId = row.UserID,
                 uSynApproved = row.USynApproved
             };
         return null;
     }
 }
예제 #27
0
 /// <summary>
 /// Updates a CompID's language code. Does not set language for a CompID
 /// only updates.
 /// </summary>
 /// <param name="compId"></param>
 /// <param name="code"></param>
 /// <returns>true or false depending on success</returns>
 public bool UpdateLanguageForCompID(int compId, LanguageCodes code)
 {
     var toUpdate = GetExactRowByCompID(compId);
     try
     {
         using (var db = new BlissBaseContext(testing))
         {
             toUpdate.LangCode = code;
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("A Exception was thrown when trying to update language code for " +
             "CompId: " + compId + ". Might be that composite sybol is defined as international");
         Debug.WriteLine(e.StackTrace);
         return false;
     }
 }
예제 #28
0
 /// <summary>
 /// Finds exact row from Languages table based on CompID
 /// </summary>
 /// <param name="compId"></param>
 /// <returns>BlissBase.DAL.Languages row or null</returns>
 internal Languages GetExactRowByCompID(int compId)
 {
     using (var db = new BlissBaseContext(testing))
     {
         return db.Languages.Find(compId);
     }
 }
예제 #29
0
 /// <summary>
 /// Takes an BlissBase.Model.User and delete it if
 /// it excists
 /// </summary>
 /// <param name="user"></param>
 /// <returns>return true or false depending on success, 
 /// or throws exception</returns>
 public bool DeleteUser(User user)
 {
     using (var db = new BlissBaseContext(testing))
     {
         Users toRemove = db.Users.Find(user.userId);
         if (toRemove != null)
             try
             {
                 db.Users.Remove(toRemove);
                 db.SaveChanges();
                 return true;
             }
             catch
             {
                 throw;
             }
         return false;
     }
 }
예제 #30
0
 /// <summary>
 /// Deletes a CompID from Languages table and effectively
 /// sets it as international
 /// </summary>
 /// <param name="compId"></param>
 /// <returns></returns>
 public bool SetInternationalForCompID(int compId)
 {
     var toRemove = GetExactRowByCompID(compId);
     try
     {
         using (var db = new BlissBaseContext(testing))
         {
             db.Languages.Remove(toRemove);
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("An exception was thrown when defining composite symbol: " + compId +
             " as international");
         Debug.WriteLine(e.StackTrace);
         return false;
     }
 }