예제 #1
0
        internal List<IStateNews> Search(DateTime dateFrom, DateTime dateTo, string Heading, string StateCode)
        {
            IDataReader objDataReader = null;
            List<IStateNews> objNewsList = null;
            IStateNews objNews = null;

            var dbHelper = DBHelper.Instance;
            try
            {
                dbHelper.AddInParameter("@DateFrom", dateFrom.ToString("yyyy-MM-dd"));
                dbHelper.AddInParameter("@DateTo", dateTo.ToString("yyyy-MM-dd"));
                dbHelper.AddInParameter("@Heading", "%" + Heading + "%", DbType.String);
                dbHelper.AddInParameter("@StateCode", StateCode, DbType.String);
                objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SearchStateNews, CommandType.StoredProcedure);

                if (objDataReader != null)
                {
                    objNewsList = new List<IStateNews>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objNews = new StateNews();

                            if (!objDataReader.IsDBNull(0))
                                objNews.NewsID = objDataReader.GetString(0);

                            if (!objDataReader.IsDBNull(1))
                                objNews.EditorID = objDataReader.GetString(1);

                            if (!objDataReader.IsDBNull(2))
                                objNews.DisplayOrder = objDataReader.GetInt32(2);

                            if (!objDataReader.IsDBNull(3))
                                objNews.Heading = objDataReader.GetString(3);

                            if (!objDataReader.IsDBNull(4))
                                objNews.ShortDescription = objDataReader.GetString(4);

                            if (!objDataReader.IsDBNull(5))
                                objNews.NewsDescription = objDataReader.GetString(5);

                            if (!objDataReader.IsDBNull(6))
                                objNews.LanguageID = objDataReader.GetInt32(6);

                            if (!objDataReader.IsDBNull(7))
                                objNews.StateCode = objDataReader.GetString(7);

                            if (!objDataReader.IsDBNull(8))
                                objNews.StateName = objDataReader.GetString(8);

                            if (!objDataReader.IsDBNull(9))
                                objNews.IsApproved = objDataReader.GetInt32(9);

                            if (!objDataReader.IsDBNull(10))
                                objNews.IsActive = objDataReader.GetInt32(10);

                            if (!objDataReader.IsDBNull(11))
                                objNews.IsTopNews = objDataReader.GetInt32(11);

                            if (!objDataReader.IsDBNull(12))
                                objNews.DttmCreated = objDataReader.GetDateTime(12);

                            if (!objDataReader.IsDBNull(13))
                                objNews.DttmModified = objDataReader.GetDateTime(13);

                            objNewsList.Add(objNews);
                        }

                    }
                    while (objDataReader.NextResult());
                }

                if (!objDataReader.IsClosed)
                    objDataReader.Close();
            }
            catch (Exception objExp)
            {
                throw objExp;
            }
            finally
            {
                dbHelper.ClearAllParameters();
                dbHelper.CloseConnection();
                dbHelper.Dispose();
            }

            return objNewsList;
        }
예제 #2
0
        internal List<IStateNews> SelectToApprove()
        {
            IDataReader objDataReader = null;
            List<IStateNews> objNewsList = null;
            IStateNews objNews = null;

            var dbHelper = DBHelper.Instance;
            try
            {
                objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SelectStateNewsToApprove, CommandType.StoredProcedure);

                if (objDataReader != null)
                {
                    objNewsList = new List<IStateNews>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objNews = new StateNews();

                            if (!objDataReader.IsDBNull(0))
                                objNews.NewsID = objDataReader.GetString(0);

                            if (!objDataReader.IsDBNull(1))
                                objNews.EditorID = objDataReader.GetString(1);

                            if (!objDataReader.IsDBNull(2))
                                objNews.DisplayOrder = objDataReader.GetInt32(2);

                            if (!objDataReader.IsDBNull(3))
                                objNews.Heading = objDataReader.GetString(3);

                            if (!objDataReader.IsDBNull(4))
                                objNews.ShortDescription = objDataReader.GetString(4);

                            if (!objDataReader.IsDBNull(5))
                                objNews.NewsDescription = objDataReader.GetString(5);

                            if (!objDataReader.IsDBNull(6))
                                objNews.LanguageID = objDataReader.GetInt32(6);

                            if (!objDataReader.IsDBNull(7))
                                objNews.StateCode = objDataReader.GetString(7);

                            if (!objDataReader.IsDBNull(8))
                                objNews.StateName = objDataReader.GetString(8);

                            if (!objDataReader.IsDBNull(9))
                                objNews.IsApproved = objDataReader.GetInt32(9);

                            if (!objDataReader.IsDBNull(10))
                                objNews.IsActive = objDataReader.GetInt32(10);

                            if (!objDataReader.IsDBNull(11))
                                objNews.IsTopNews = objDataReader.GetInt32(11);

                            if (!objDataReader.IsDBNull(12))
                                objNews.DttmCreated = objDataReader.GetDateTime(12);

                            if (!objDataReader.IsDBNull(13))
                                objNews.DttmModified = objDataReader.GetDateTime(13);

                            if (!objDataReader.IsDBNull(14))
                                objNews.ImageUrl = objDataReader.GetString(14);

                            if (!objDataReader.IsDBNull(15))
                                objNews.ImageCaption = objDataReader.GetString(15);

                            if (!objDataReader.IsDBNull(16))
                                objNews.ImageCaptionLink = objDataReader.GetString(16);

                            objNewsList.Add(objNews);
                        }

                    }
                    while (objDataReader.NextResult());
                }

                if (!objDataReader.IsClosed)
                    objDataReader.Close();
            }
            catch (Exception objExp)
            {
                throw objExp;
            }
            finally
            {
                dbHelper.ClearAllParameters();
                dbHelper.CloseConnection();
                dbHelper.Dispose();
            }

            return objNewsList;
        }
예제 #3
0
        internal List <IStateNews> Search(DateTime dateFrom, DateTime dateTo, string Heading, string StateCode)
        {
            IDataReader       objDataReader = null;
            List <IStateNews> objNewsList   = null;
            IStateNews        objNews       = null;

            var dbHelper = DBHelper.Instance;

            try
            {
                dbHelper.AddInParameter("@DateFrom", dateFrom.ToString("yyyy-MM-dd"));
                dbHelper.AddInParameter("@DateTo", dateTo.ToString("yyyy-MM-dd"));
                dbHelper.AddInParameter("@Heading", "%" + Heading + "%", DbType.String);
                dbHelper.AddInParameter("@StateCode", StateCode, DbType.String);
                objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SearchStateNews, CommandType.StoredProcedure);

                if (objDataReader != null)
                {
                    objNewsList = new List <IStateNews>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objNews = new StateNews();

                            if (!objDataReader.IsDBNull(0))
                            {
                                objNews.NewsID = objDataReader.GetString(0);
                            }

                            if (!objDataReader.IsDBNull(1))
                            {
                                objNews.EditorID = objDataReader.GetString(1);
                            }

                            if (!objDataReader.IsDBNull(2))
                            {
                                objNews.DisplayOrder = objDataReader.GetInt32(2);
                            }

                            if (!objDataReader.IsDBNull(3))
                            {
                                objNews.Heading = objDataReader.GetString(3);
                            }

                            if (!objDataReader.IsDBNull(4))
                            {
                                objNews.ShortDescription = objDataReader.GetString(4);
                            }

                            if (!objDataReader.IsDBNull(5))
                            {
                                objNews.NewsDescription = objDataReader.GetString(5);
                            }

                            if (!objDataReader.IsDBNull(6))
                            {
                                objNews.LanguageID = objDataReader.GetInt32(6);
                            }

                            if (!objDataReader.IsDBNull(7))
                            {
                                objNews.StateCode = objDataReader.GetString(7);
                            }

                            if (!objDataReader.IsDBNull(8))
                            {
                                objNews.StateName = objDataReader.GetString(8);
                            }

                            if (!objDataReader.IsDBNull(9))
                            {
                                objNews.IsApproved = objDataReader.GetInt32(9);
                            }

                            if (!objDataReader.IsDBNull(10))
                            {
                                objNews.IsActive = objDataReader.GetInt32(10);
                            }

                            if (!objDataReader.IsDBNull(11))
                            {
                                objNews.IsTopNews = objDataReader.GetInt32(11);
                            }

                            if (!objDataReader.IsDBNull(12))
                            {
                                objNews.DttmCreated = objDataReader.GetDateTime(12);
                            }

                            if (!objDataReader.IsDBNull(13))
                            {
                                objNews.DttmModified = objDataReader.GetDateTime(13);
                            }

                            objNewsList.Add(objNews);
                        }
                    }while (objDataReader.NextResult());
                }

                if (!objDataReader.IsClosed)
                {
                    objDataReader.Close();
                }
            }
            catch (Exception objExp)
            {
                throw objExp;
            }
            finally
            {
                dbHelper.ClearAllParameters();
                dbHelper.CloseConnection();
                dbHelper.Dispose();
            }

            return(objNewsList);
        }
예제 #4
0
        internal IEnumerable <IStateNews> SelectStateNewsForApi()
        {
            IDataReader       objDataReader = null;
            List <IStateNews> objNewsList   = null;
            IStateNews        objNews       = null;

            var dbHelper = DBHelper.Instance;

            try
            {
                //dbHelper.AddInParameter("@StateCode", StateCode, DbType.String);
                objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SelectStateNewsForApi, CommandType.StoredProcedure);

                if (objDataReader != null)
                {
                    objNewsList = new List <IStateNews>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objNews = new StateNews();

                            if (!objDataReader.IsDBNull(0))
                            {
                                objNews.NewsID = objDataReader.GetString(0);
                            }

                            if (!objDataReader.IsDBNull(1))
                            {
                                objNews.EditorID = objDataReader.GetString(1);
                            }

                            if (!objDataReader.IsDBNull(2))
                            {
                                objNews.DisplayOrder = objDataReader.GetInt32(2);
                            }

                            if (!objDataReader.IsDBNull(3))
                            {
                                objNews.Heading = objDataReader.GetString(3);
                            }

                            if (!objDataReader.IsDBNull(4))
                            {
                                objNews.ShortDescription = objDataReader.GetString(4);
                            }

                            if (!objDataReader.IsDBNull(5))
                            {
                                objNews.NewsDescription = objDataReader.GetString(5);
                            }

                            if (!objDataReader.IsDBNull(6))
                            {
                                objNews.LanguageID = objDataReader.GetInt32(6);
                            }

                            if (!objDataReader.IsDBNull(7))
                            {
                                objNews.StateCode = objDataReader.GetString(7);
                            }

                            if (!objDataReader.IsDBNull(8))
                            {
                                objNews.StateName = objDataReader.GetString(8);
                            }

                            if (!objDataReader.IsDBNull(9))
                            {
                                objNews.IsApproved = objDataReader.GetInt32(9);
                            }

                            if (!objDataReader.IsDBNull(10))
                            {
                                objNews.IsActive = objDataReader.GetInt32(10);
                            }

                            if (!objDataReader.IsDBNull(11))
                            {
                                objNews.IsTopNews = objDataReader.GetInt32(11);
                            }

                            if (!objDataReader.IsDBNull(12))
                            {
                                objNews.DttmCreated = objDataReader.GetDateTime(12);
                            }

                            if (!objDataReader.IsDBNull(13))
                            {
                                objNews.DttmModified = objDataReader.GetDateTime(13);
                            }

                            if (!objDataReader.IsDBNull(14))
                            {
                                objNews.ImageUrl = objDataReader.GetString(14);
                            }

                            if (!objDataReader.IsDBNull(15))
                            {
                                objNews.ImageCaption = objDataReader.GetString(15);
                            }

                            if (!objDataReader.IsDBNull(16))
                            {
                                objNews.ImageCaptionLink = objDataReader.GetString(16);
                            }

                            objNewsList.Add(objNews);
                        }
                    }while (objDataReader.NextResult());
                }

                if (!objDataReader.IsClosed)
                {
                    objDataReader.Close();
                }
            }
            catch (Exception objExp)
            {
                throw objExp;
            }
            finally
            {
                dbHelper.ClearAllParameters();
                dbHelper.CloseConnection();
                dbHelper.Dispose();
            }

            return(objNewsList);//.FindAll(v => v.DttmCreated.Date == DateTime.Now.Date || v.DttmCreated.Date.AddDays(-1) == DateTime.Now.Date.AddDays(-1)); ;
        }
예제 #5
0
        internal IStateNews Select(string NewsID)
        {
            IStateNews  objNews       = null;
            IDataReader objDataReader = null;
            var         dbHelper      = DBHelper.Instance;

            try
            {
                dbHelper.AddInParameter("@NewsID", NewsID, DbType.String);
                objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SelectStateNews, CommandType.StoredProcedure);

                if (objDataReader != null)
                {
                    while (objDataReader.Read())
                    {
                        objNews = new StateNews();

                        if (!objDataReader.IsDBNull(0))
                        {
                            objNews.NewsID = objDataReader.GetString(0);
                        }

                        if (!objDataReader.IsDBNull(1))
                        {
                            objNews.EditorID = objDataReader.GetString(1);
                        }

                        if (!objDataReader.IsDBNull(2))
                        {
                            objNews.DisplayOrder = objDataReader.GetInt32(2);
                        }

                        if (!objDataReader.IsDBNull(3))
                        {
                            objNews.Heading = objDataReader.GetString(3);
                        }

                        if (!objDataReader.IsDBNull(4))
                        {
                            objNews.ShortDescription = objDataReader.GetString(4);
                        }

                        if (!objDataReader.IsDBNull(5))
                        {
                            objNews.NewsDescription = objDataReader.GetString(5);
                        }

                        if (!objDataReader.IsDBNull(6))
                        {
                            objNews.LanguageID = objDataReader.GetInt32(6);
                        }

                        if (!objDataReader.IsDBNull(7))
                        {
                            objNews.StateCode = objDataReader.GetString(7);
                        }

                        if (!objDataReader.IsDBNull(8))
                        {
                            objNews.IsApproved = objDataReader.GetInt32(8);
                        }

                        if (!objDataReader.IsDBNull(9))
                        {
                            objNews.IsActive = objDataReader.GetInt32(9);
                        }

                        if (!objDataReader.IsDBNull(10))
                        {
                            objNews.IsTopNews = objDataReader.GetInt32(10);
                        }

                        if (!objDataReader.IsDBNull(11))
                        {
                            objNews.DttmCreated = objDataReader.GetDateTime(11);
                        }

                        if (!objDataReader.IsDBNull(12))
                        {
                            objNews.DttmModified = objDataReader.GetDateTime(12);
                        }

                        if (!objDataReader.IsDBNull(13))
                        {
                            objNews.ImageUrl = objDataReader.GetString(13);
                        }

                        if (!objDataReader.IsDBNull(14))
                        {
                            objNews.ImageCaption = objDataReader.GetString(14);
                        }

                        if (!objDataReader.IsDBNull(15))
                        {
                            objNews.ImageCaptionLink = objDataReader.GetString(15);
                        }
                    }
                }

                if (!objDataReader.IsClosed)
                {
                    objDataReader.Close();
                }
            }
            catch (Exception objExp)
            {
                throw objExp;
            }
            finally
            {
                dbHelper.ClearAllParameters();
                dbHelper.CloseConnection();
                dbHelper.Dispose();
            }

            return(objNews);
        }
        public async Task<ActionResult> InsertNews(CreateStateNews newForInsert)
        {
           
            return await Task.Run(() =>
            {
                var dbHelprer = DBHelper.Instance;
                var BLInstance = StateNewsBL.Instance;
                dbHelprer.BeginTransaction();

                try
                {
                    if (ModelState.IsValid)
                    {
                        var news = new StateNews
                        {
                            Heading = newForInsert.Heading.Trim(),
                            ShortDescription = newForInsert.ShortDesc.Trim(),
                            NewsDescription = string.IsNullOrEmpty(newForInsert.Description) ? string.Empty : newForInsert.Description.Trim(),
                            StateCode = newForInsert.StateCode,
                            IsTopNews = newForInsert.IsTopTenNews ? 1 : 0,
                            IsActive = 0,
                            IsApproved = 0
                        };

                        var image = new ImageDetail
                        {
                            ImageType = (int)ImageType.TopNewsImage,
                            ImageUrl = " ",
                            Caption = newForInsert.Caption,
                            CaptionLink = newForInsert.CaptionLink,
                            IsActive = 0,
                            IsFirst = 0
                        };

                        var fileName = string.Empty;
                        if (newForInsert.Image != null && newForInsert.Image.ContentLength > 0)
                        {
                            fileName = new Random().Next(1000000000).ToString() + Path.GetFileName(newForInsert.Image.FileName);
                            image.ImageUrl = ImagePath.TopTenNewsImage + "/" + fileName;
                            image.IsActive = 1;
                            image.IsFirst = 1;
                        }

                        string dirPath = ImagePath.StateNewsImage;
                        var user = (IUsers)this.Session[Constants.UserSessionKey];
                        BLInstance.Insert(ref dbHelprer, news, image, user);

                        if (SaveImage(ImagePath.StateNewsImage, fileName, newForInsert.Image))
                        {
                            newForInsert = new CreateStateNews();
                            newForInsert.States.AddRange(StateCodeBL.Instance.SelectStates());
                            ViewBag.Message = "Successfully Inserter.";
                            ModelState.Clear();
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("INSERT", "Oops ! There is some error.");
                        ViewBag.Message = "Oops ! There is some error.";
                    }

                    dbHelprer.CommitTransaction();
                    return View(newForInsert);
                }
                catch (Exception ex)
                {
                    dbHelprer.RollbackTransaction();
                    throw ex;
                }
                finally
                {
                    dbHelprer.Dispose();
                    BLInstance.Dispose();
                }
            });
        }
        public async Task<ActionResult> UpdateNews(UpdateNews newForUpdate)
        {
            var dbHelpre = DBHelper.Instance;
            dbHelpre.BeginTransaction();

            return await Task.Run(() =>
            {
                try
                {
                    bool IsNotValid = false;
                    ViewBag.Message = "Update new news.";
                    if (ModelState.IsValid)
                    {
                        var news = new StateNews
                        {
                            NewsID = newForUpdate.NewsID,
                            Heading = newForUpdate.Heading.Trim(),
                            StateCode = newForUpdate.StateCode,
                            ShortDescription = newForUpdate.ShortDesc.Trim(),
                            NewsDescription = string.IsNullOrEmpty(newForUpdate.Description) ? string.Empty : newForUpdate.Description.Trim(),
                            IsActive = newForUpdate.IsActiveNews ? 1 : 0,
                            IsApproved = newForUpdate.IsApprovedNews ? 1 : 0,
                            IsTopNews = newForUpdate.IsTopTenNews ? 1 : 0,
                            DisplayOrder = 0
                        };

                        var image = new ImageDetail
                        {
                            ImageType = 2,
                            ImageUrl = newForUpdate.ImageUrl,
                            Caption = newForUpdate.Caption,
                            CaptionLink = newForUpdate.CaptionLink,
                            IsActive = 1,
                            IsFirst = 1
                        };

                        var fileName = string.Empty;
                        if (newForUpdate.Image != null && newForUpdate.Image.ContentLength > 0)
                        {
                            fileName = new Random().Next(1000000000).ToString() + Path.GetFileName(newForUpdate.Image.FileName);
                            image.ImageUrl = ImagePath.StateNewsImage + "/" + fileName;
                            image.IsActive = 1;
                            image.IsFirst = 1;
                        }

                        var user = (IUsers)this.Session[Constants.UserSessionKey];
                        StateNewsBL.Instance.UpdateNews(ref dbHelpre, news, image, user);

                        if (!string.IsNullOrEmpty(fileName))
                        {

                            if (SaveImage(ImagePath.StateNewsImage, fileName, newForUpdate.Image))
                            {
                                if (DeleteImage(ImagePath.StateNewsImage, newForUpdate.ImageUrl))
                                {
                                    ViewBag.Message = "Updated successfully.";
                                    ModelState.Clear();
                                }
                                else
                                {
                                    IsNotValid = true;
                                }
                            }
                            else
                            {
                                IsNotValid = true;
                            }
                        }

                        newForUpdate.ImageUrl = image.ImageUrl;

                    }
                    else
                    {
                        IsNotValid = true;
                    }

                    if (IsNotValid)
                    {
                        dbHelpre.RollbackTransaction();
                        ModelState.AddModelError("INSERT", "Oops ! There is some error.");
                        ViewBag.Message = "Oops ! There is some error.";
                    }
                    else
                    {
                        ViewBag.Message = "Updated successfully.";
                        ModelState.Clear();
                    }

                    dbHelpre.CommitTransaction();
                }
                catch (Exception ex)
                {
                    dbHelpre.RollbackTransaction();
                    throw ex;
                }
                finally
                {
                    dbHelpre.ClearAllParameters();
                    dbHelpre.CloseConnection();
                    dbHelpre.Dispose();
                }

                return View(newForUpdate);
            });
        }