public List<posts_view_model> getAllPosts(string search)
        {
            List<posts_view_model> postsList = new List<posts_view_model>();
            try
            {
                ping_pakistanEntities db = new ping_pakistanEntities();
                var pposts = (from post in db.posts
                              join user in db.users on post.user_id equals user.id
                              join category in db.categories on post.category_id equals category.id
                              where post.is_approved != true && post.is_deleted != true
                              select new posts_view_model
                              {
                                  post_id = post.id,
                                  user_id = post.user_id,
                                  post_text = post.text,
                                  date_added = post.date_added,
                                  agree_count = post.agree_count,
                                  disagree_count = post.disagree_count,
                                  username = user.username,
                                  category_name = category.name,
                                  category_id = category.id
                              });
                postsList = pposts.ToList();
            }
            catch (Exception ex)
            {

            }
            return postsList;
        }
 public users GetUserByUsername(string username)
 {
     try
     {
         ping_pakistanEntities db = new ping_pakistanEntities();
         return db.users.FirstOrDefault(u => u.username == username);
     }
     catch (Exception ex)
     {
         return null;
     }
 }
        public List<users> getUsers(string search)
        {
            List<users> usersList = new List<users>();
            try
            {
                ping_pakistanEntities db = new ping_pakistanEntities();
                usersList = db.users.ToList();
            }
            catch (Exception ex)
            {

            }
            return usersList;
        }
 public int AddUser(users user)
 {
     try
     {
         ping_pakistanEntities db = new ping_pakistanEntities();
         db.users.Add(user);
         db.SaveChanges();
         return user.id;
     }
     catch(Exception ex)
     {
         return -1;
     }
 }
        public List<posts> getPostsByCategoryId(int category_id, string search)
        {
            List<posts> postsList = new List<posts>();
            try
            {
                ping_pakistanEntities db = new ping_pakistanEntities();
                postsList = db.posts.Where(p => p.category_id == category_id && p.is_approved == true && p.is_deleted == true).ToList();
            }
            catch (Exception ex)
            {

            }
            return postsList;
        }
 public posts AddPost(posts post)
 {
     try
     {
         ping_pakistanEntities db = new ping_pakistanEntities();
         db.posts.Add(post);
         db.SaveChanges();
         return post;
     }
     catch (Exception ex)
     {
         return post;
     }
 }
        public List<categories> getAllCategories(string search)
        {
            List<categories> categoryList = new List<categories>();
            try
            {
                ping_pakistanEntities db = new ping_pakistanEntities();
                categoryList = db.categories.ToList();
            }
            catch (Exception ex)
            {

            }
            return categoryList;
        }
 public categories AddCategory(categories category)
 {
     try
     {
         ping_pakistanEntities db = new ping_pakistanEntities();
         db.categories.Add(category);
         db.SaveChanges();
         return category;
     }
     catch (Exception ex)
     {
         return category;
     }
 }
 public bool Authenticate(string username, string password)
 {
     try
     {
         ping_pakistanEntities db = new ping_pakistanEntities();
         var user = db.users.Where(u => u.username == username && u.password == password);
         if (user.Count() > 0)
         {
             return true;
         }
         return false;
     }
     catch (Exception ex)
     {
         return false;
     }
 }
Esempio n. 10
0
        public bool VerifyCode(int user_id, string code)
        {
            bool isVerified = false;
            try
            {
                ping_pakistanEntities db = new ping_pakistanEntities();
                var user = db.users.Where(p => p.id == user_id && p.verification_code == code);
                if(user.Count() > 0)
                {
                    isVerified = true;
                }
            }
            catch(Exception ex)
            {

            }
            return isVerified;
        }
Esempio n. 11
0
 public bool DeletePost(int post_id)
 {
     try
     {
         ping_pakistanEntities db = new ping_pakistanEntities();
         var _post = db.posts.FirstOrDefault(p => p.id == post_id);
         if (_post != null)
         {
             _post.is_deleted = true;
         }
         db.SaveChanges();
         return true;
     }
     catch (Exception ex)
     {
         return false;
     }
 }
Esempio n. 12
0
 public bool UpdateApproveStatus(int post_id, bool status)
 {
     try
     {
         ping_pakistanEntities db = new ping_pakistanEntities();
         var _post = db.posts.FirstOrDefault(p => p.id == post_id);
         if(_post != null)
         {
             _post.is_approved = status;
         }
         db.SaveChanges();
         return true;
     }
     catch (Exception ex)
     {
         return false;
     }
 }