Пример #1
0
        private static void newsupdate(long _news_id, bool blnIsFocus, int intNewMode)
        {
            MainDB objDb = new MainDB();

            objDb.BeginTransaction();
            try {
                NewsRow          objRow;
                NewsPublishedRow publishedRow = null;
                bool             IsPublished  = false;
                String           cpmode       = HttpContext.Current.Request.QueryString["cpmode"];
                if (cpmode.IndexOf("publishedlist") >= 0 || cpmode.IndexOf("removedlist") >= 0)
                {
                    IsPublished = true;
                }

                //using (MainDB objDb = new MainDB())
                //{
                objRow = objDb.NewsCollection.GetByPrimaryKey(_news_id);

                if (IsPublished)
                {
                    publishedRow = objDb.NewsPublishedCollection.GetByPrimaryKey(_news_id);
                }
                //}
                if (objRow != null)
                {
                    //thuc hien doi trang thai cua tin - luu thong tin modified thanh ngay gio hien tai.
                    //objRow.News_Status = _news_status;
                    objRow.News_isFocus      = blnIsFocus;
                    objRow.News_Mode         = intNewMode;
                    objRow.News_ModifiedDate = DateTime.Now;

                    if (IsPublished && publishedRow != null)
                    {
                        publishedRow.News_isFocus     = blnIsFocus;
                        publishedRow.News_Mode        = intNewMode;
                        publishedRow.News_ModifedDate = DateTime.Now;
                    }

                    //using (MainDB objDb = new MainDB())
                    //{
                    objDb.NewsCollection.Update(objRow);

                    if (IsPublished && publishedRow != null)
                    {
                        objDb.NewsPublishedCollection.Update(publishedRow);
                    }
                    //}
                }

                // Commit Transaction
                objDb.CommitTransaction();
            }
            catch (Exception ex) {
                objDb.RollbackTransaction();
            }
            finally {
                objDb.Close();
            }
        }
        /// <summary>
        /// 生成一个新的钱包
        /// </summary>
        /// <returns></returns>
        DBModels.Wallet CreateWallet()
        {
            string account = null;

            using (var db = new MainDB())
            {
                //generate account number
                while (account == null)
                {
                    account = new Random().Next(10000000, 99999999).ToString();
                    if (db.Wallet.Any(m => m.Account == account))
                    {
                        //account exists,generate account number again
                        account = null;
                    }
                }

                db.BeginTransaction();

                try
                {
                    var wallet = new DBModels.Wallet()
                    {
                        Account = account,
                        Secret  = Guid.NewGuid().ToString("N")
                    };
                    db.Insert(wallet);

                    #region 创建BTC平台密钥
                    BTC_Client btc_client = new BTC_Client();
                    byte[]     key1, key2;
                    btc_client.CreatePlatformKey(out key1, out key2);

                    var walletInfo = new DBModels.WalletCyptoCoinInfo()
                    {
                        Key1     = key1,
                        Key2     = key2,
                        WalletId = wallet.id,
                        Currency = "BTC",
                    };
                    db.Insert(walletInfo);
                    #endregion


                    db.CommitTransaction();

                    return(wallet);
                }
                catch
                {
                    db.RollbackTransaction();
                    throw;
                }
            }
        }
Пример #3
0
        private static void newsupdate(long _news_id, int _news_status)
        {
            NewsRow objRow;
            int     old_news_status = -1;
            int     _cat_id         = -1;

            MainDB objDb = new MainDB();

            objDb.BeginTransaction();
            string strAction = "";

            try {
                objRow = objDb.NewsCollection.GetByPrimaryKey(_news_id);
                string _news_title = objRow.News_Title.Trim();
                old_news_status = objRow.News_Status;

                _cat_id = objRow.Cat_ID;
                int type_log_action = LogAction.LogType_BaiViet;

                if (objRow != null)
                {
                    //thuc hien doi trang thai cua tin - luu thong tin modified thanh ngay gio hien tai.
                    objRow.News_Status       = _news_status;
                    objRow.News_ModifiedDate = DateTime.Now;
                    objRow.News_Approver     = HttpContext.Current.User.Identity.Name;
                    //thuc hien luu thong tin vao action.
                    ActionRow objArow = new ActionRow();
                    //Gui len. Neu la xoa tam thi khong luu action
                    if (_news_status == 1)
                    {
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gửi bài chờ biên tập";
                        objArow.ActionType    = 1;
                        strAction             = "<b>" + _news_title.Replace("'", "") + "</b> " + LogAction.LogAction_GuiChoBT + " bởi " + HttpContext.Current.User.Identity.Name;
                    }
                    if (_news_status == 2)
                    {
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gửi bài chờ duyệt";
                        objArow.ActionType    = 2;
                        strAction             = "<b>" + _news_title.Replace("'", "") + "</b> " + LogAction.LogAction_GuiChoBT + " bởi " + HttpContext.Current.User.Identity.Name;
                    }

                    NewsPublishedRow objpublishRow = new NewsPublishedRow();
                    if (_news_status == 3)
                    {
                        objRow.News_Approver = HttpContext.Current.User.Identity.Name;
                        if (objRow.IsNews_PublishDateNull == false && objRow.News_PublishDate.Year != 9999 && objRow.News_PublishDate.Year != 2000)
                        {
                            objRow.News_PublishDate = DateTime.Now;
                        }

                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " xuất bản bài";
                        objArow.ActionType    = 3;
                        strAction             = "<b>" + _news_title.Replace("'", "") + "</b> " + LogAction.LogAction_XB + " bởi " + HttpContext.Current.User.Identity.Name;
                        type_log_action       = LogAction.LogType_BaiViet_XB;

                        //thuc hien chuyen du lieu qua bang newspublished

                        objpublishRow.News_ID          = objRow.News_ID;
                        objpublishRow.Cat_ID           = objRow.Cat_ID;
                        objpublishRow.News_Subtitle    = objRow.News_Subtitle;
                        objpublishRow.News_Title       = objRow.News_Title;
                        objpublishRow.News_Image       = objRow.News_Image;
                        objpublishRow.News_Source      = objRow.News_Source;
                        objpublishRow.News_InitContent = objRow.News_InitialContent;
                        objpublishRow.News_Content     = objRow.News_Content;
                        objpublishRow.News_Athor       = objRow.News_Author;
                        objpublishRow.News_Approver    = objRow.News_Approver;
                        objpublishRow.News_Status      = 3;

                        if (objRow.IsNews_PublishDateNull == true || objRow.News_PublishDate.Year == 9999 || objRow.News_PublishDate.Year == 2000)
                        {
                            objRow.News_PublishDate = DateTime.Now;
                        }
                        objpublishRow.News_PublishDate = objRow.News_PublishDate;

                        objpublishRow.News_isFocus = objRow.News_isFocus;
                        objpublishRow.News_Mode    = objRow.News_Mode;
                        objpublishRow.isComment    = objRow.isComment;
                        objpublishRow.isUserRate   = objRow.isUserRate;
                        objpublishRow.Template     = objRow.Template;
                        objpublishRow.Icon         = objRow.Icon;
                        //objpublishRow.News_Relation = objRow.News_Relation;
                    }
                    if (_news_status == 5)
                    {
                        ActionRow objLastestArow = NewslistHelper.getLastestAction(Convert.ToInt64(_news_id));
                        objArow.Reciver_ID    = objLastestArow.Sender_ID;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " trả lại bài";
                        strAction             = "<b>" + _news_title.Replace("'", "") + "</b> " + LogAction.LogAction_TraLai + " bởi " + HttpContext.Current.User.Identity.Name;
                        objArow.ActionType    = getLastestStatus(_news_id);

                        if (old_news_status == 3)
                        {
                            type_log_action = LogAction.LogType_BaiViet_XB;
                        }
                    }
                    //xoa tam
                    if (_news_status == 6)
                    {
                        objArow.Reciver_ID    = HttpContext.Current.User.Identity.Name;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " xoá tạm bài";
                        strAction             = "<b>" + _news_title.Replace("'", "") + "</b> " + LogAction.LogAction_XoaTam + " bởi " + HttpContext.Current.User.Identity.Name;
                        objArow.ActionType    = getLastestStatus(_news_id);
                    }
                    //gui bai tu backlist len
                    if (_news_status == -1)
                    {
                        int intLastStaus = getLastestStatus(_news_id);
                        objArow.Reciver_ID    = HttpContext.Current.User.Identity.Name;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gửi bài";
                        strAction             = "<b>" + _news_title.Replace("'", "") + "</b> " + LogAction.LogAction_GuiBai + " bởi " + HttpContext.Current.User.Identity.Name;
                        objRow.News_Status    = intLastStaus;
                        objArow.ActionType    = intLastStaus;
                    }
                    if (_news_status == 7)
                    {
                        int intLastStaus = getLastestStatus(_news_id);
                        objArow.ActionType    = intLastStaus;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gỡ bỏ bài";
                        strAction             = "<b>" + _news_title.Replace("'", "") + "</b> " + LogAction.LogAction_GoBai + " bởi " + HttpContext.Current.User.Identity.Name;
                        type_log_action       = LogAction.LogType_BaiViet_XB;


                        objpublishRow = objDb.NewsPublishedCollection.GetByPrimaryKey(_news_id);
                        if (objpublishRow != null)
                        {
                            objDb.NewsPublishedCollection.DeleteByPrimaryKey(_news_id);
                        }
                    }

                    objArow.News_ID   = _news_id;
                    objArow.Sender_ID = HttpContext.Current.User.Identity.Name;

                    objArow.CreateDate = DateTime.Now;


                    objDb.ActionCollection.Insert(objArow);
                    objDb.NewsCollection.Update(objRow);
                    if (_news_status == 3)
                    {
                        objDb.NewsPublishedCollection.Insert(objpublishRow);
                    }

                    // Commit Transaction
                    objDb.CommitTransaction();
                }
            }
            catch (Exception ex) {
                objDb.RollbackTransaction();
            }
            finally {
                objDb.Close();
            }
        }
Пример #4
0
        public static bool UpdateNews(long _news_id, int _cat_id, string _news_subtitle, string _news_title, string _news_image, string _news_source, string _news_init, string _news_content, bool _news_isfocus, int _news_status, int _news_type, string _related_news, string _other_cat, DateTime _switchtime, bool _isSend, bool _isShowComment, bool _isShowRate, int _template, string _obj_media, string _news_title_image, string _news_icon, string _thread_id)
        {
            bool   toReturn        = false;
            int    old_news_status = -1;
            MainDB objDb           = new MainDB();

            objDb.BeginTransaction();
            NewsRow objrow;


            if (_news_init != null)
            {
                _news_init = _news_init.Replace(System.Environment.NewLine, "<br/>");
            }

            try {
                #region Gan Thread vao bai
                // Gan Thread vao bai

                Threaddetails objThread = new Threaddetails();
                objDb.SelectScalar("Delete ThreadDetail Where News_ID = '" + _news_id + "'");

                if (_thread_id != null)
                {
                    string[] strArThread = _thread_id.Split(',');
                    foreach (string str in strArThread)
                    {
                        objThread.AddnewsThread(_news_id.ToString(), int.Parse(str), objDb);
                    }
                }
                #endregion

                objrow          = objDb.NewsCollection.GetByPrimaryKey(_news_id);
                old_news_status = objrow.News_Status;

                if (objrow != null)
                {
                    #region Gan cac gia tri cho bang News
                    objrow.Cat_ID              = _cat_id;
                    objrow.News_Subtitle       = _news_subtitle;
                    objrow.News_Title          = _news_title;
                    objrow.News_Image          = _news_image;
                    objrow.News_Source         = _news_source;
                    objrow.News_InitialContent = _news_init;
                    objrow.News_Content        = _news_content;
                    objrow.WordCount           = NewsHelper.WordCount(objrow.News_Content);
                    //objrow.User_ID = _poster;
                    //objrow.News_Author = _news_author;
                    objrow.News_isFocus = _news_isfocus;
                    //Trang thai cua tin tuy thuoc vao nguoi bien tap.
                    if (_news_status != -1)
                    {
                        objrow.News_Status = _news_status;
                    }
                    objrow.News_Mode = _news_type;
                    //tin lien quan
                    objrow.News_Relation = _related_news;
                    //if (_news_imgfocus != "" && _news_imgfocus!=null)
                    //objrow.News_FocusImage = _news_imgfocus;
                    if (_other_cat != "")
                    {
                        objrow.News_OtherCat = _other_cat;
                    }

                    DateTime dtPublish = _switchtime;
                    if (objrow.News_Status == 3)
                    {
                        if (dtPublish.Year != 9999)
                        {
                            // Neu khong phai la news da published ma khong chon ngay Xuat ban thi update lai ngay gio
                            if (dtPublish.Year != 2000)
                            {
                                objrow.News_PublishDate = dtPublish;
                            }
                            else
                            {
                                objrow.News_PublishDate = DateTime.Now;
                            }
                        }
                    }

                    objrow.Template       = _template;
                    objrow.News_ImageNote = _news_title_image;

                    objrow.isComment  = _isShowComment;
                    objrow.isUserRate = _isShowRate;
                    objrow.Icon       = _news_icon;


                    objrow.News_ModifiedDate = DateTime.Now;
                    #endregion

                    #region Gan cac gia tri cho bang Action
                    //thuc hien luu thong tin vao action.
                    ActionRow objArow = new ActionRow();
                    objArow.Sender_ID = HttpContext.Current.User.Identity.Name;
                    //Gui len. Neu la xoa tam thi khong luu action - Cho nay can phai xem la gui len hay luu lai?
                    string cpMode = HttpContext.Current.Request.QueryString["cpmode"].Replace("add,", string.Empty);
                    switch (objrow.News_Status)
                    {
                    case 1:
                        if (old_news_status != 1)
                        {
                            objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gửi bài chờ biên tập";
                        }
                        else
                        {
                            objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " nhận biên tập";
                            objArow.Reciver_ID    = HttpContext.Current.User.Identity.Name;
                            ActionRow tem = new ActionRow();
                            tem = getLastestAction(_news_id);
                            objArow.Sender_ID = tem.Sender_ID;
                        }
                        break;

                    case 2:
                        if (old_news_status != 2)
                        {
                            objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gửi bài chờ duyệt";
                        }
                        else
                        {
                            objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " nhận duyệt";
                            objArow.Reciver_ID    = HttpContext.Current.User.Identity.Name;
                            ActionRow tem = new ActionRow();
                            tem = getLastestAction(_news_id);
                            objArow.Sender_ID = tem.Sender_ID;
                        }
                        break;

                    case 3: objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " xuất bản bài"; break;
                    }
                    objArow.ActionType = objrow.News_Status;
                    objArow.News_ID    = _news_id;

                    objArow.CreateDate = DateTime.Now;
                    // chỉ khi tin đổi trạng thái
                    // hoặc
                    // không phải tin ở trong danh sách nhận duyệt, nhận biên tập
                    // thì mới lưu action
                    // [bacth, 11:00 AM 5/31/2008]
                    if (old_news_status != objrow.News_Status || (cpMode.ToLower().Equals("approvalwaitlist") || cpMode.ToLower().Equals("editwaitlist")))
                    {
                        if (objrow.News_Status == 1 || objrow.News_Status == 2 || objrow.News_Status == 3)
                        {
                            objDb.ActionCollection.Insert(objArow);
                        }
                    }

                    #endregion

                    #region Gan cac gia tri cho bang NewsPublished
                    NewsPublishedRow objpublishRow;

                    // Get lai nhung gia tri cua cua News Published
                    objpublishRow = objDb.NewsPublishedCollection.GetByPrimaryKey(_news_id);

                    // Neu khong ton tai news_id trong NewsPUblished thi khoi tao lai
                    if (objpublishRow == null)
                    {
                        objpublishRow = new NewsPublishedRow();
                    }

                    // Gan cac gia tri cho News Published
                    if (_news_status == 3)
                    {
                        objrow.News_Approver = HttpContext.Current.User.Identity.Name;

                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " xuất bản bài";
                        objArow.ActionType    = 3;

                        //thuc hien chuyen du lieu qua bang newspublished
                        objpublishRow.Icon          = _news_icon;
                        objpublishRow.News_ID       = _news_id;
                        objpublishRow.Cat_ID        = _cat_id;
                        objpublishRow.News_Subtitle = _news_subtitle;
                        objpublishRow.News_Title    = _news_title;
                        if (_news_image != "" && _news_image != null)
                        {
                            objpublishRow.News_Image = _news_image;
                        }
                        else
                        {
                            objpublishRow.News_Image = objrow.News_Image;
                        }
                        objpublishRow.News_Source      = _news_source;
                        objpublishRow.News_InitContent = objrow.News_InitialContent;
                        objpublishRow.News_Content     = _news_content;
                        objpublishRow.News_Athor       = objrow.News_Author;
                        objpublishRow.News_Approver    = HttpContext.Current.User.Identity.Name;
                        objpublishRow.News_Status      = 3;

                        if (dtPublish.Year != 9999)
                        {
                            // Neu khong phai la news da published ma khong chon ngay Xuat ban thi update lai ngay gio
                            if (dtPublish.Year != 2000)
                            {
                                objpublishRow.News_PublishDate = dtPublish;
                            }
                            else
                            {
                                objpublishRow.News_PublishDate = DateTime.Now;
                            }
                        }

                        objpublishRow.News_isFocus = _news_isfocus;
                        objpublishRow.News_Mode    = _news_type;
                        if (_related_news != "" && _related_news != null)
                        {
                            objpublishRow.News_Relation = objrow.News_Relation;
                        }
                        else
                        {
                            objpublishRow.News_Relation = _related_news;
                        }
                        if (_other_cat != "" && _other_cat != null)
                        {
                            objpublishRow.News_OtherCat = objrow.News_OtherCat;
                        }
                        else
                        {
                            objpublishRow.News_OtherCat = _other_cat;
                        }

                        objpublishRow.Template       = _template;
                        objpublishRow.isComment      = _isShowComment;
                        objpublishRow.isUserRate     = _isShowRate;
                        objpublishRow.News_ImageNote = _news_title_image;
                    }

                    #endregion

                    if (!objDb.NewsCollection.Update(objrow))
                    {
                        throw new Exception("Không cập nhật được bản tin");
                    }

                    #region Cap nhap vao bang News, Action va  NewsPublished
                    NewsPublishedRow objCurrRow;
                    //neu la send thi moi cap nhat Action



                    if (objrow.News_Status == 3)
                    {
                        //thuc hien xoa neu ton tai tin do va chen moi vao bang xuat ban
                        objCurrRow = objDb.NewsPublishedCollection.GetByPrimaryKey(_news_id);
                        if (objCurrRow != null)
                        {
                            objDb.NewsPublishedCollection.DeleteByPrimaryKey(_news_id);
                        }
                        objDb.NewsPublishedCollection.Insert(objpublishRow);
                    }
                    #endregion

                    #region Cap nhap vao bang MediaObject
                    // Xoa tat ca News_Media cu theo NewsID
                    string strObjectId = NewsMediaHelper.Get_ObjectId_By_NewsId(_news_id);
                    if (strObjectId != null && strObjectId != "")
                    {
                        string[] mediaIds = strObjectId.Split(",".ToCharArray());
                        foreach (string strMediaId in mediaIds)
                        {
                            NewsMediaHelper.Delete_News_Media_ByNewsIdAndObjectId(_news_id, strMediaId, objDb);
                        }
                    }

                    //truong hop co media object
                    if (_obj_media != null && _obj_media != "")
                    {
                        News_MediaRow objMrow  = null;
                        string[]      mediaIds = _obj_media.Split(",".ToCharArray());
                        foreach (string strMediaId in mediaIds)
                        {
                            objMrow           = new News_MediaRow();
                            objMrow.News_ID   = _news_id;
                            objMrow.Object_ID = int.Parse(strMediaId);
                            objDb.News_MediaCollection.Insert(objMrow);
                        }
                    }

                    #endregion

                    objDb.CommitTransaction();
                    toReturn = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally {
                if (HttpContext.Current.Session["newsid"] != null)
                {
                    HttpContext.Current.Session.Remove("newsid");
                }
                objDb.Close();
            }



            return(toReturn);;
        }
Пример #5
0
        public static bool CreateNews(long _news_id, int _cat_id, string _news_subtitle, string _news_title, string _news_image, string _news_source, string _news_init, string _news_content, string _poster, bool _news_isfocus, int _news_status, int _news_type, string _related_news, string _obj_media, string _other_cat, DateTime _switchtime, bool _isShowComment, bool _isShowRate, int _template, string _news_title_image, string _news_icon, string _thread_id)
        {
            bool toReturn = false;

            MainDB objDb = new MainDB();

            objDb.BeginTransaction();

            try {
                #region Gán giá trị cho bảng News
                NewsRow objrow = new NewsRow();
                //strResult = _news_id;
                objrow.News_ID             = _news_id;
                objrow.Cat_ID              = _cat_id;
                objrow.News_Subtitle       = _news_subtitle;
                objrow.News_Title          = _news_title;
                objrow.News_Image          = _news_image;
                objrow.News_Source         = _news_source;
                objrow.News_InitialContent = _news_init;
                objrow.News_Content        = _news_content;
                objrow.News_Author         = _poster;
                //objrow.News_Author = _news_author;
                objrow.News_isFocus = _news_isfocus;
                objrow.News_Status  = _news_status;
                objrow.News_Mode    = _news_type;
                //Danh sach nhung tin lien quan den tin nay
                objrow.News_Relation = _related_news;
                //objrow.News_FocusImage = _news_imgfocus;
                objrow.News_CreateDate   = DateTime.Now;
                objrow.News_ModifiedDate = DateTime.Now;
                objrow.isComment         = _isShowComment;
                objrow.isUserRate        = _isShowRate;
                objrow.Template          = _template;
                objrow.News_ImageNote    = _news_title_image;
                objrow.Icon      = _news_icon;
                objrow.WordCount = NewsHelper.WordCount(objrow.News_Content);
                if (_news_status == 3)
                {
                    if (_switchtime.Year != 2000)
                    {
                        objrow.News_PublishDate = _switchtime;
                    }
                    else
                    {
                        objrow.News_PublishDate = DateTime.Now;
                    }

                    objrow.News_Approver = HttpContext.Current.User.Identity.Name;
                }

                //lay other cat neu co
                if (_other_cat != null && _other_cat != "" && _other_cat != "0")
                {
                    objrow.News_OtherCat = _other_cat;
                }

                #endregion

                #region Gán và Insert giá trị cho bảng Action và NewsPublished
                //Thuc hien cap nhat thong tin vao Action
                ActionRow objArow = new ActionRow();
                objArow.News_ID    = objrow.News_ID;
                objArow.Sender_ID  = HttpContext.Current.User.Identity.Name;
                objArow.ActionType = _news_status;
                objArow.CreateDate = DateTime.Now;
                if (_news_status == 0)
                {
                    objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " Tạo bài viết";
                    objArow.Reciver_ID    = HttpContext.Current.User.Identity.Name;
                }
                if (_news_status == 1)
                {
                    objArow.Comment_Title  = HttpContext.Current.User.Identity.Name + " Tạo bài viết và gửi lên chờ biên tập";
                    objrow.News_SwitchTime = DateTime.Now;
                }
                if (_news_status == 2)
                {
                    objArow.Comment_Title  = HttpContext.Current.User.Identity.Name + " Tạo bài viết và gửi lên chờ duyệt";
                    objrow.News_SwitchTime = DateTime.Now;
                }

                NewsPublishedRow objpublishRow = new NewsPublishedRow();
                if (_news_status == 3)
                {
                    // Chỉ có những tin nào xuất bản thì mới Insert vào bảng News Published
                    objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " Tạo bài viết và xuất bản";


                    //thuc hien xuat ban bai viet

                    objpublishRow.News_ID          = _news_id;
                    objpublishRow.Cat_ID           = _cat_id;
                    objpublishRow.News_Subtitle    = _news_subtitle;
                    objpublishRow.News_Title       = _news_title;
                    objpublishRow.News_Image       = _news_image;
                    objpublishRow.News_Source      = _news_source;
                    objpublishRow.News_InitContent = objrow.News_InitialContent;
                    objpublishRow.News_Content     = _news_content;
                    objpublishRow.News_Athor       = _poster;
                    objpublishRow.News_Approver    = HttpContext.Current.User.Identity.Name;
                    objpublishRow.News_Status      = 3;
                    if (_switchtime.Year != 2000)
                    {
                        objpublishRow.News_PublishDate = _switchtime;
                    }
                    else
                    {
                        objpublishRow.News_PublishDate = DateTime.Now;
                    }
                    objpublishRow.News_isFocus   = _news_isfocus;
                    objpublishRow.News_Mode      = _news_type;
                    objpublishRow.News_Relation  = _related_news;
                    objpublishRow.News_OtherCat  = _other_cat;
                    objpublishRow.Template       = _template;
                    objpublishRow.isComment      = _isShowComment;
                    objpublishRow.isUserRate     = _isShowRate;
                    objpublishRow.News_ImageNote = _news_title_image;
                    objpublishRow.Icon           = _news_icon;

                    objpublishRow.WordCount = objrow.WordCount;
                }

                // thu insert 2 lan
                if (!objDb.NewsCollection.Insert(objrow))
                {
                    objrow.News_ID        = long.Parse(NewsHelper.GenNewsID());
                    objpublishRow.News_ID = objrow.News_ID;
                    objArow.News_ID       = objrow.News_ID;
                    if (!objDb.NewsCollection.Insert(objrow))
                    {
                        throw new Exception("Insert khong thanh cong");
                    }
                }

                objDb.ActionCollection.Insert(objArow);
                if (objrow.News_Status == 3)
                {
                    objDb.NewsPublishedCollection.Insert(objpublishRow);
                }

                #endregion

                #region Gan Thread vao bai
                // Gan Thread vao bai

                if (_thread_id != null && _thread_id != "")
                {
                    Threaddetails objThread   = new Threaddetails();
                    string[]      strArThread = _thread_id.Split(',');
                    foreach (string str in strArThread)
                    {
                        objThread.AddnewsThread(objrow.News_ID.ToString(), Convert.ToInt32(str), objDb);
                    }
                }
                #endregion

                #region Insert vào bảng MediaObject
                //truong hop co media object
                if (_obj_media != null && _obj_media != "")
                {
                    News_MediaRow objMrow  = null;
                    string[]      mediaIds = _obj_media.Split(",".ToCharArray());
                    foreach (string strMediaId in mediaIds)
                    {
                        objMrow           = new News_MediaRow();
                        objMrow.News_ID   = objrow.News_ID;
                        objMrow.Object_ID = Convert.ToInt32(strMediaId);
                        objDb.News_MediaCollection.Insert(objMrow);
                    }
                }
                #endregion

                objDb.CommitTransaction();

                toReturn = true;
            }
            catch (Exception ex) {
                objDb.RollbackTransaction();
                toReturn = false;
                // log to system
                try {
                    string mes = "";
                    mes += "NewsId = " + _news_id + Environment.NewLine;
                    mes += "User_Id = " + HttpContext.Current.User.Identity.Name + Environment.NewLine;
                    mes += "_related_news = " + _related_news + Environment.NewLine;
                    mes += "_other_cat = " + _other_cat + Environment.NewLine;
                    mes += "_thread_id = " + _thread_id + Environment.NewLine;
                    mes += ex.ToString();
                    System.Diagnostics.EventLog.WriteEntry("CreateNews_CMS_LOG", mes);
                }
                catch (Exception e) { }
            }
            finally {
                if (HttpContext.Current.Session["newsid"] != null)
                {
                    HttpContext.Current.Session.Remove("newsid");
                }
                objDb.Close();
            }

            return(toReturn);
        }
Пример #6
0
        private static void UpdateStatus(long newsID, int newsStatus)
        {
            NewsRow objRow;
            int     old_news_status = -1;
            int     _cat_id         = -1;

            MainDB objDb = new MainDB();

            objDb.BeginTransaction();

            try {
                objRow          = objDb.NewsCollection.GetByPrimaryKey(newsID);
                old_news_status = objRow.News_Status;
                _cat_id         = objRow.Cat_ID;

                if (objRow != null)
                {
                    //thuc hien doi trang thai cua tin - luu thong tin modified thanh ngay gio hien tai.
                    objRow.News_Status       = newsStatus;
                    objRow.News_ModifiedDate = DateTime.Now;
                    //thuc hien luu thong tin vao action.
                    ActionRow objArow = new ActionRow();
                    //Gui len. Neu la xoa tam thi khong luu action
                    if (newsStatus == 1)
                    {
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gửi bài chờ biên tập";
                        objArow.ActionType    = 1;
                    }
                    if (newsStatus == 2)
                    {
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gửi bài chờ duyệt";
                        objArow.ActionType    = 2;
                    }

                    NewsPublishedRow objpublishRow = new NewsPublishedRow();
                    if (newsStatus == 3)
                    {
                        objRow.News_Approver = HttpContext.Current.User.Identity.Name;
                        if (objRow.IsNews_PublishDateNull == false && objRow.News_PublishDate.Year != 9999 && objRow.News_PublishDate.Year != 2000)
                        {
                            objRow.News_PublishDate = DateTime.Now;
                        }

                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " xuất bản bài";
                        objArow.ActionType    = 3;

                        //thuc hien chuyen du lieu qua bang newspublished

                        objpublishRow.News_ID          = objRow.News_ID;
                        objpublishRow.Cat_ID           = objRow.Cat_ID;
                        objpublishRow.News_Subtitle    = objRow.News_Subtitle;
                        objpublishRow.News_Title       = objRow.News_Title;
                        objpublishRow.News_Image       = objRow.News_Image;
                        objpublishRow.News_Source      = objRow.News_Source;
                        objpublishRow.News_InitContent = objRow.News_InitialContent;
                        objpublishRow.News_Content     = objRow.News_Content;
                        objpublishRow.News_Athor       = objRow.News_Author;
                        objpublishRow.News_Approver    = objRow.News_Approver;
                        objpublishRow.News_Status      = 3;

                        if (objRow.IsNews_PublishDateNull == true || objRow.News_PublishDate.Year == 9999 || objRow.News_PublishDate.Year == 2000)
                        {
                            objRow.News_PublishDate = DateTime.Now;
                        }
                        objpublishRow.News_PublishDate = objRow.News_PublishDate;

                        objpublishRow.News_isFocus  = objRow.News_isFocus;
                        objpublishRow.News_Mode     = objRow.News_Mode;
                        objpublishRow.isComment     = objRow.isComment;
                        objpublishRow.isUserRate    = objRow.isUserRate;
                        objpublishRow.Template      = objRow.Template;
                        objpublishRow.Icon          = objRow.Icon;
                        objpublishRow.News_Relation = objRow.News_Relation;
                    }
                    if (newsStatus == 5)
                    {
                        ActionRow objLastestArow = getLastestAction(Convert.ToInt64(newsID));
                        objArow.Reciver_ID    = objLastestArow.Sender_ID;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " trả lại bài";

                        objArow.ActionType = getLastestStatus(newsID);
                    }
                    //xoa tam
                    if (newsStatus == 6)
                    {
                        objArow.Reciver_ID    = HttpContext.Current.User.Identity.Name;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " xoá tạm bài";
                        objArow.ActionType    = getLastestStatus(newsID);
                    }
                    //gui bai tu backlist len
                    if (newsStatus == -1)
                    {
                        int intLastStaus = getLastestStatus(newsID);
                        objArow.Reciver_ID    = HttpContext.Current.User.Identity.Name;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gửi bài";
                        objRow.News_Status    = intLastStaus;
                        objArow.ActionType    = intLastStaus;
                    }
                    if (newsStatus == 7)
                    {
                        int intLastStaus = getLastestStatus(newsID);
                        objArow.ActionType    = intLastStaus;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gỡ bỏ bài";

                        // Neu la go bo thi go luon o bang NewsPublished
                        //using (MainDB objDb = new MainDB())
                        //{
                        objpublishRow = objDb.NewsPublishedCollection.GetByPrimaryKey(newsID);
                        if (objpublishRow != null)
                        {
                            objDb.NewsPublishedCollection.DeleteByPrimaryKey(newsID);
                        }
                        //}
                    }

                    objArow.News_ID   = newsID;
                    objArow.Sender_ID = HttpContext.Current.User.Identity.Name;

                    objArow.CreateDate = DateTime.Now;

                    //if (_news_status != 6)
                    objDb.ActionCollection.Insert(objArow);
                    objDb.NewsCollection.Update(objRow);
                    if (newsStatus == 3)
                    {
                        objDb.NewsPublishedCollection.Insert(objpublishRow);
                    }

                    // Commit Transaction
                    objDb.CommitTransaction();


                    //#region Insert vao bang LogInfo để thống kê
                    //Log objLog = new Log();

                    //if (old_news_status != -1 && old_news_status != newsStatus && _cat_id != -1)
                    //{
                    //    string strUser_Id = HttpContext.Current.User.Identity.Name;
                    //    if (newsStatus == 1)
                    //    {
                    //        // Đối với bài chờ biên tập
                    //        objLog.UpdateLogInfo((int)CountKey.Category_Wait_Edit_Content, _cat_id.ToString());
                    //        objLog.UpdateLogInfo((int)CountKey.User_Wait_Edit_Content, strUser_Id);
                    //    }
                    //    else if (newsStatus == 2)
                    //    {
                    //        // Đối với bài chờ duyet
                    //        objLog.UpdateLogInfo((int)CountKey.Category_Wait_Approve_Content, _cat_id.ToString());
                    //        objLog.UpdateLogInfo((int)CountKey.User_Wait_Approve_Content, strUser_Id);
                    //    }
                    //    else if (newsStatus == 3)
                    //    {
                    //        // Đối với bài đã xuất bản
                    //        objLog.UpdateLogInfo((int)CountKey.Category_Approved_Content, _cat_id.ToString());
                    //        objLog.UpdateLogInfo((int)CountKey.User_Approved_Content, strUser_Id);
                    //    }
                    //}
                    //#endregion
                }
            }
            catch (Exception ex) {
                objDb.RollbackTransaction();
            }
            finally {
                objDb.Close();
            }
        }