示例#1
0
 internal bool IsUniqueUsername(string username)
 {
     using (var conn = new CookbookEntities())
     {
         return(!conn.tblUserDatas.Any(x => x.Username == username));
     }
 }
示例#2
0
 internal tblUserData LoadUserByUsername(string userName)
 {
     try
     {
         using (var conn = new CookbookEntities())
         {
             return(conn.tblUserDatas.FirstOrDefault(x => x.Username == userName));
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
示例#3
0
 internal bool TryAddNewRecipe(tblRecipe recipe)
 {
     try
     {
         using (var conn = new CookbookEntities())
         {
             conn.tblRecipes.Add(recipe);
             conn.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#4
0
 internal bool TryAddNewUserData(tblUserData userData)
 {
     try
     {
         using (var conn = new CookbookEntities())
         {
             conn.tblUserDatas.Add(userData);
             conn.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#5
0
 internal List <tblRecipe> LoadRecipes()
 {
     try
     {
         using (var conn = new CookbookEntities())
         {
             if (conn.tblRecipes.Any())
             {
                 return(conn.tblRecipes.Include(x => x.tblUserData).ToList());
             }
             return(new List <tblRecipe>());
         }
     }
     catch (Exception)
     {
         return(new List <tblRecipe>());
     }
 }
示例#6
0
        public bool IsCorrectUser(string userName, string password)
        {
            try
            {
                using (var conn = new CookbookEntities())
                {
                    var user = conn.tblUserDatas.FirstOrDefault(x => x.Username == userName);

                    if (user != null)
                    {
                        var passwordFromDb = conn.tblUserDatas.First(x => x.Username == userName).Password;
                        return(SecurePasswordHasher.Verify(password, passwordFromDb));
                    }
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#7
0
        internal bool TryRemoveRecipe(int recipeId)
        {
            try
            {
                using (var conn = new CookbookEntities())
                {
                    var recipeToRemove = conn.tblRecipes.FirstOrDefault(x => x.RecipeID == recipeId);

                    if (recipeToRemove != null)
                    {
                        conn.tblRecipes.Remove(recipeToRemove);
                        conn.SaveChanges();
                        return(true);
                    }
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#8
0
 internal bool TryUpdateRecipe(tblRecipe updatedRecipe)
 {
     try
     {
         using (var conn = new CookbookEntities())
         {
             var recipeToUpdate = conn.tblRecipes.FirstOrDefault(x => x.RecipeID == updatedRecipe.RecipeID);
             if (recipeToUpdate != null)
             {
                 recipeToUpdate.Name         = updatedRecipe.Name;
                 recipeToUpdate.PersonsCount = updatedRecipe.PersonsCount;
                 recipeToUpdate.Type         = updatedRecipe.Type;
                 conn.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }