Esempio n. 1
0
        public List <ITopNews> Search(DateTime dateFrom, DateTime dateTo, string Heading)
        {
            IDataReader     objDataReader  = null;
            List <ITopNews> objTopNewsList = null;
            ITopNews        objTopNews     = 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);
                objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SearchNews, CommandType.StoredProcedure);

                if (objDataReader != null)
                {
                    objTopNewsList = new List <ITopNews>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objTopNews = new TopNews();

                            if (!objDataReader.IsDBNull(0))
                            {
                                objTopNews.TopNewsID = objDataReader.GetString(0);
                            }

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

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

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

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

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

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

                            if (!objDataReader.IsDBNull(7))
                            {
                                objTopNews.IsApproved = objDataReader.GetInt32(7);
                            }

                            if (!objDataReader.IsDBNull(8))
                            {
                                objTopNews.IsActive = objDataReader.GetInt32(8);
                            }

                            if (!objDataReader.IsDBNull(9))
                            {
                                objTopNews.DttmCreated = objDataReader.GetDateTime(9);
                            }

                            if (!objDataReader.IsDBNull(10))
                            {
                                objTopNews.DttmModified = objDataReader.GetDateTime(10);
                            }

                            objTopNewsList.Add(objTopNews);
                        }
                    }while (objDataReader.NextResult());
                }

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

            return(objTopNewsList);
        }
Esempio n. 2
0
        public async Task <ITopNews> Select(string NewsID)
        {
            return(await Task.Run(() =>
            {
                ITopNews objTopNews = null;
                IDataReader objDataReader = null;
                var dbHelper = DBHelper.Instance;
                try
                {
                    dbHelper.AddInParameter("@NewsID", NewsID, DbType.String);
                    objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SelectTopNews, CommandType.StoredProcedure);

                    if (objDataReader != null)
                    {
                        while (objDataReader.Read())
                        {
                            objTopNews = new TopNews();

                            if (!objDataReader.IsDBNull(0))
                            {
                                objTopNews.TopNewsID = objDataReader.GetString(0);
                            }

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

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

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

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

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

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

                            if (!objDataReader.IsDBNull(7))
                            {
                                objTopNews.IsApproved = objDataReader.GetInt32(7);
                            }

                            if (!objDataReader.IsDBNull(8))
                            {
                                objTopNews.IsActive = objDataReader.GetInt32(8);
                            }

                            if (!objDataReader.IsDBNull(9))
                            {
                                objTopNews.DttmCreated = objDataReader.GetDateTime(9);
                            }

                            if (!objDataReader.IsDBNull(10))
                            {
                                objTopNews.DttmModified = objDataReader.GetDateTime(10);
                            }

                            if (!objDataReader.IsDBNull(11))
                            {
                                objTopNews.ImageUrl = objDataReader.GetString(11);
                            }

                            if (!objDataReader.IsDBNull(12))
                            {
                                objTopNews.ImageCaption = objDataReader.GetString(12);
                            }
                        }
                    }

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

                return objTopNews;
            }));
        }
Esempio n. 3
0
        public List <ITopNews> SelectTopNewsForActivate()
        {
            IDataReader     objDataReader  = null;
            List <ITopNews> objTopNewsList = null;
            ITopNews        objTopNews     = null;

            DBHelper dbHelper = new DBHelper();

            try
            {
                objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SelectAllTopNews, CommandType.StoredProcedure);

                if (objDataReader != null)
                {
                    objTopNewsList = new List <ITopNews>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objTopNews = new TopNews();

                            if (!objDataReader.IsDBNull(0))
                            {
                                objTopNews.TopNewsID = objDataReader.GetString(0);
                            }

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

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

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

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

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

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

                            if (!objDataReader.IsDBNull(7))
                            {
                                objTopNews.IsApproved = objDataReader.GetInt32(7);
                            }

                            if (!objDataReader.IsDBNull(8))
                            {
                                objTopNews.IsActive = objDataReader.GetInt32(8);
                            }

                            if (!objDataReader.IsDBNull(9))
                            {
                                objTopNews.DttmCreated = objDataReader.GetDateTime(9);
                            }

                            if (!objDataReader.IsDBNull(10))
                            {
                                objTopNews.DttmModified = objDataReader.GetDateTime(10);
                            }

                            if (!objDataReader.IsDBNull(11))
                            {
                                objTopNews.ImageUrl = objDataReader.GetString(11);
                            }

                            if (!objDataReader.IsDBNull(12))
                            {
                                objTopNews.ImageCaption = objDataReader.GetString(12);
                            }

                            objTopNewsList.Add(objTopNews);
                        }
                    }while (objDataReader.NextResult());
                }

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

            return(objTopNewsList);
        }
Esempio n. 4
0
        public List<ITopNews> Search(DateTime dateFrom, DateTime dateTo, string Heading)
        {
            IDataReader objDataReader = null;
            List<ITopNews> objTopNewsList = null;
            ITopNews objTopNews = 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);
                objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SearchNews, CommandType.StoredProcedure);

                if (objDataReader != null)
                {
                    objTopNewsList = new List<ITopNews>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objTopNews = new TopNews();

                            if (!objDataReader.IsDBNull(0))
                                objTopNews.TopNewsID = objDataReader.GetString(0);

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

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

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

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

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

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

                            if (!objDataReader.IsDBNull(7))
                                objTopNews.IsApproved = objDataReader.GetInt32(7);

                            if (!objDataReader.IsDBNull(8))
                                objTopNews.IsActive = objDataReader.GetInt32(8);

                            if (!objDataReader.IsDBNull(9))
                                objTopNews.DttmCreated = objDataReader.GetDateTime(9);

                            if (!objDataReader.IsDBNull(10))
                                objTopNews.DttmModified = objDataReader.GetDateTime(10);

                            objTopNewsList.Add(objTopNews);
                        }

                    }
                    while (objDataReader.NextResult());
                }

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

            return objTopNewsList;
        }
Esempio n. 5
0
        public List<ITopNews> SelectTopNewsForActivate()
        {
            IDataReader objDataReader = null;
            List<ITopNews> objTopNewsList = null;
            ITopNews objTopNews = null;

            DBHelper dbHelper = new DBHelper();
            try
            {
                objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SelectAllTopNews, CommandType.StoredProcedure);

                if (objDataReader != null)
                {
                    objTopNewsList = new List<ITopNews>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objTopNews = new TopNews();

                            if (!objDataReader.IsDBNull(0))
                                objTopNews.TopNewsID = objDataReader.GetString(0);

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

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

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

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

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

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

                            if (!objDataReader.IsDBNull(7))
                                objTopNews.IsApproved = objDataReader.GetInt32(7);

                            if (!objDataReader.IsDBNull(8))
                                objTopNews.IsActive = objDataReader.GetInt32(8);

                            if (!objDataReader.IsDBNull(9))
                                objTopNews.DttmCreated = objDataReader.GetDateTime(9);

                            if (!objDataReader.IsDBNull(10))
                                objTopNews.DttmModified = objDataReader.GetDateTime(10);

                            if (!objDataReader.IsDBNull(11))
                                objTopNews.ImageUrl = objDataReader.GetString(11);

                            if (!objDataReader.IsDBNull(12))
                                objTopNews.ImageCaption = objDataReader.GetString(12);

                            objTopNewsList.Add(objTopNews);
                        }

                    }
                    while (objDataReader.NextResult());
                }

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

            return objTopNewsList;
        }
Esempio n. 6
0
        public async Task<ITopNews> Select(string NewsID)
        {
            return await Task.Run(() =>
            {
                ITopNews objTopNews = null;
                IDataReader objDataReader = null;
                var dbHelper = DBHelper.Instance;
                try
                {
                    dbHelper.AddInParameter("@NewsID", NewsID, DbType.String);
                    objDataReader = dbHelper.ExecuteDataReader(ProcedureName.SelectTopNews, CommandType.StoredProcedure);

                    if (objDataReader != null)
                    {
                        while (objDataReader.Read())
                        {
                            objTopNews = new TopNews();

                            if (!objDataReader.IsDBNull(0))
                                objTopNews.TopNewsID = objDataReader.GetString(0);

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

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

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

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

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

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

                            if (!objDataReader.IsDBNull(7))
                                objTopNews.IsApproved = objDataReader.GetInt32(7);

                            if (!objDataReader.IsDBNull(8))
                                objTopNews.IsActive = objDataReader.GetInt32(8);

                            if (!objDataReader.IsDBNull(9))
                                objTopNews.DttmCreated = objDataReader.GetDateTime(9);

                            if (!objDataReader.IsDBNull(10))
                                objTopNews.DttmModified = objDataReader.GetDateTime(10);

                            if (!objDataReader.IsDBNull(11))
                                objTopNews.ImageUrl = objDataReader.GetString(11);

                            if (!objDataReader.IsDBNull(12))
                                objTopNews.ImageCaption = objDataReader.GetString(12);

                        }
                    }

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

                return objTopNews;
            });
        }
        public async Task<ActionResult> UpdateNews(UpdateNews newForUpdate)
        {
            var dbHelpre = DBHelper.Instance;
            dbHelpre.BeginTransaction();

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

                        var image = new ImageDetail
                        {
                            ImageType = 1,
                            ImageUrl = newForUpdate.ImageUrl,
                            Caption = newForUpdate.Caption,
                            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.TopTenNewsImage + "/" + fileName;
                            image.IsActive = 1;
                            image.IsFirst = 1;
                        }

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

                        if (!string.IsNullOrEmpty(fileName))
                        {

                            if (SaveImage(ImagePath.TopTenNewsImage, fileName, newForUpdate.Image))
                            {
                                if (DeleteImage(ImagePath.TopTenNewsImage, 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.";
                    }

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

                return View(newForUpdate);
            });
        }
        public async Task<ActionResult> InsertNews(CreateNews newForInsert)
        {           
            return await Task.Run(() =>
            {
                var dbHelpre = DBHelper.Instance;
                var BLInstance = TopNewsBL.Instance;
                dbHelpre.BeginTransaction();
                try
                {
                    if (ModelState.IsValid)
                    {
                        var news = new TopNews
                        {
                            Heading = newForInsert.Heading.Trim(),
                            ShortDescription = newForInsert.ShortDesc.Trim(),
                            NewsDescription = string.IsNullOrEmpty(newForInsert.Description) ? string.Empty : newForInsert.Description.Trim(),
                            IsActive = 0,
                            IsApproved = 0
                        };

                        var image = new ImageDetail
                        {
                            ImageType = (int)ImageType.TopNewsImage,
                            ImageUrl = " ",
                            Caption = newForInsert.ImageCaption,
                            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.TopTenNewsImage;
                        var user = (IUsers)this.Session[Constants.UserSessionKey];
                        BLInstance.Insert(ref dbHelpre, news, image, user);

                        if (SaveImage(ImagePath.TopTenNewsImage, fileName, newForInsert.Image))
                        {
                            newForInsert = new CreateNews();
                            ViewBag.Message = "Successfully Inserter.";
                            ModelState.Clear();
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("INSERT", "Oops ! There is some error.");
                        ViewBag.Message = "Oops ! There is some error.";
                    }

                    dbHelpre.CommitTransaction();
                    return View(newForInsert);
                }
                catch (Exception ex)
                {
                    dbHelpre.RollbackTransaction();
                    throw ex;
                }
                finally
                {
                    dbHelpre.Dispose();
                    BLInstance.Dispose();
                }
            });
        }