Exemple #1
0
        /// <summary>
        /// Cập nhật mật khẩu mới
        /// </summary>
        /// <param name="_username"></param>
        /// <param name="_newPassword"></param>
        public static Boolean updateUserPassword(string _username, string _newPassword)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var user = DB.tblUsers.Single(u => u.Username == _username);

                    user.Note = "New password: " + _newPassword;
                    user.Password = encryptPassword(_newPassword);

                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }

            return true;
        }
Exemple #2
0
        /// <summary>
        /// Xét trạng thái của user
        /// 0: Non-Active (mới đăng ký thành viên)
        /// 1: Active (Trạng thái hoạt động bình thường)
        /// 2: Warning (khi gửi bài bị báo xấu)
        /// 31: KIA 3 ngày
        /// 32: KIA 1 tuần
        /// 33: KIA 2 tuần
        /// 34: KIA 3 tuần
        /// 35: KIA 1 tháng
        /// </summary>
        /// <param name="username"></param>
        /// <param name="_state"></param>
        /// <returns></returns>
        public static Boolean setUserState(string username, int _state)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            using (TransactionScope ts = new TransactionScope())
            {
                var record = DB.tblUsers.Single(TB => TB.Username == username);
                record.State = _state;
                DB.SubmitChanges();

                ts.Complete();
            }

            return true;
        }
Exemple #3
0
        /// <summary>
        /// Cập nhật user
        /// </summary>
        /// <param name="_username"></param>
        /// <param name="update"></param>
        /// <returns></returns>
        public static Boolean updateUser(string _username, tblUser update)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var user = DB.tblUsers.Single(u => u.Username == _username);

                    user.Password = update.Password;
                    user.DisplayName = update.DisplayName;
                    user.Email = update.Email;
                    user.Type = update.Type;
                    user.Role = update.Role;
                    user.Permission = update.Permission;
                    user.State = update.State;
                    user.RegisterDate = update.RegisterDate;
                    user.NumberOfArticles = update.NumberOfArticles;
                    user.Note = update.Note;

                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
Exemple #4
0
        /// <summary>
        /// Thêm một user mới
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public static Boolean insertUser(tblUser record)
        {
            LTDHDataContext DB = new LTDHDataContext(strPathDB);

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    DB.tblUsers.InsertOnSubmit(record);

                    DB.SubmitChanges();

                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
Exemple #5
0
        /// <summary>
        /// Đăng ký user mới
        /// </summary>
        /// <param name="_username"></param>
        /// <param name="_displayName"></param>
        /// <param name="_email"></param>
        /// <param name="_sex"></param>
        /// <param name="_password"></param>
        /// <returns></returns>
        public static Boolean register(string _username,
            string _displayName,
            string _email,
            Boolean _sex,
            string _password)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    tblUser user = new tblUser();
                    user.Username = _username;
                    user.DisplayName = _displayName;
                    user.Sex = _sex;
                    user.Email = _email;
                    user.Password = encryptPassword(_password);
                    user.Note = "Password: "******"Normal";
                    user.RegisterDate = DateTime.Today;
                    user.NumberOfArticles = 0;
                    user.State = 0;

                    DB.tblUsers.InsertOnSubmit(user);
                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }

            return true;
        }
Exemple #6
0
        /// <summary>
        /// Xét loại bài viết
        /// 0 - Bài giảng
        /// 1 - Đề thi
        /// 2 - Bài tập
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="_type"></param>
        /// <returns></returns>
        public static Boolean setType(int ID, int _type)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            using (TransactionScope ts = new TransactionScope())
            {
                var record = DB.tblEnglishes.Single(TB => TB.ID == ID);
                record.Type = _type;
                DB.SubmitChanges();

                ts.Complete();
            }

            return true;
        }
Exemple #7
0
        /// <summary>
        /// Cập nhật bài viết
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="update"></param>
        /// <returns></returns>
        public static Boolean updateEnglish(int _id, tblEnglish update)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var english = DB.tblEnglishes.Single(e => e.ID == _id);

                    english.Title = update.Title;
                    english.Type = update.Type;
                    english.Contents = update.Contents;
                    english.Author = update.Author;
                    english.Posted = update.Posted;
                    english.State = update.State;
                    english.Point = update.Point;
                    english.Tag = update.Tag;

                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
Exemple #8
0
        /// <summary>
        /// Xét ngày đăng tin
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="_posted"></param>
        /// <returns></returns>
        public static Boolean setPosted(int ID, DateTime _posted)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            using (TransactionScope ts = new TransactionScope())
            {
                var record = DB.tblEnglishes.Single(TB => TB.ID == ID);
                record.Posted = _posted;
                DB.SubmitChanges();

                ts.Complete();
            }

            return true;
        }
        /// <summary>
        /// Cập nhật bài viết
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        public static Boolean updateInformatic(int _id, tblInformatic update)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var informatic = DB.tblInformatics.Single(info => info.ID == _id);
                    informatic.Title = update.Title;
                    informatic.Type = update.Type;
                    informatic.Chapeau = update.Chapeau;
                    informatic.Contents = update.Contents;
                    informatic.Author = update.Author;
                    informatic.Posted = update.Posted;
                    informatic.State = update.State;
                    informatic.Point = update.Point;
                    informatic.Tag = update.Tag;

                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// Xét tiêu đề
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="_title"></param>
        /// <returns></returns>
        public static Boolean setTitle(int ID, string _title)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            using (TransactionScope ts = new TransactionScope())
            {
                var record = DB.tblInformatics.Single(TB => TB.ID == ID);
                record.Title = _title;
                DB.SubmitChanges();

                ts.Complete();
            }

            return true;
        }
Exemple #11
0
        /// <summary>
        /// Cập nhật tin tức
        /// </summary>
        /// <param name="recordUpdate"></param>
        /// <returns></returns>
        public static Boolean updateNews(int newsID, tblNew recordUpdate)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var news = DB.tblNews.Single(n => n.ID == newsID);
                    news.Title = recordUpdate.Title;
                    news.Chapaeu = recordUpdate.Chapaeu;
                    news.Contents = recordUpdate.Contents;
                    news.Posted = recordUpdate.Posted;
                    news.Author = recordUpdate.Author;

                    DB.SubmitChanges();
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
Exemple #12
0
        /// <summary>
        /// Xét nội dung tin tức
        /// </summary>
        /// <param name="newsID"></param>
        /// <param name="strContent"></param>
        /// <returns></returns>
        public static Boolean setContent(int newsID, string strContent)
        {
            LTDHDataContext DB = new LTDHDataContext(@strPathDB);

            using (TransactionScope ts = new TransactionScope())
            {
                var record = DB.tblNews.Single(TB => TB.ID == newsID);
                record.Contents = strContent;
                DB.SubmitChanges();

                ts.Complete();
            }

            return true;
        }