Exemple #1
0
        public IEnumerable <IImageDetail> SelectImageList(string NewsID)
        {
            IDataReader         objDataReader      = null;
            List <IImageDetail> objImageDetailList = null;
            IImageDetail        objImageDetail     = null;

            var dbHelper = DBHelper.Instance;

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

                if (objDataReader != null)
                {
                    objImageDetailList = new List <IImageDetail>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objImageDetail = new ImageDetail();

                            if (!objDataReader.IsDBNull(0))
                            {
                                objImageDetail.ImageID = objDataReader.GetString(0);
                            }

                            if (!objDataReader.IsDBNull(1))
                            {
                                objImageDetail.ImageUrl = objDataReader.GetString(1);
                            }

                            if (!objDataReader.IsDBNull(2))
                            {
                                objImageDetail.ImageType = objDataReader.GetInt32(2);
                            }

                            if (!objDataReader.IsDBNull(3))
                            {
                                objImageDetail.IsFirst = objDataReader.GetInt32(3);
                            }

                            if (!objDataReader.IsDBNull(4))
                            {
                                objImageDetail.IsActive = objDataReader.GetInt32(4);
                            }

                            if (!objDataReader.IsDBNull(5))
                            {
                                objImageDetail.DttmCreated = objDataReader.GetDateTime(5);
                            }

                            if (!objDataReader.IsDBNull(6))
                            {
                                objImageDetail.DttmModified = objDataReader.GetDateTime(6);
                            }


                            objImageDetailList.Add(objImageDetail);
                        }
                    }while (objDataReader.NextResult());
                }

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

            return(objImageDetailList);
        }
        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);
            });
        }
        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 IEnumerable<IImageDetail> SelectInterNewsImageList(string NewsID)
        {
            IDataReader objDataReader = null;
            List<IImageDetail> objImageDetailList = null;
            IImageDetail objImageDetail = null;

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

                if (objDataReader != null)
                {
                    objImageDetailList = new List<IImageDetail>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objImageDetail = new ImageDetail();

                            if (!objDataReader.IsDBNull(0))
                                objImageDetail.ImageID = objDataReader.GetString(0);

                            if (!objDataReader.IsDBNull(1))
                                objImageDetail.ImageUrl = objDataReader.GetString(1);

                            if (!objDataReader.IsDBNull(2))
                                objImageDetail.ImageType = objDataReader.GetInt32(2);

                            if (!objDataReader.IsDBNull(3))
                                objImageDetail.IsFirst = objDataReader.GetInt32(3);

                            if (!objDataReader.IsDBNull(4))
                                objImageDetail.IsActive = objDataReader.GetInt32(4);

                            if (!objDataReader.IsDBNull(5))
                                objImageDetail.DttmCreated = objDataReader.GetDateTime(5);

                            if (!objDataReader.IsDBNull(6))
                                objImageDetail.DttmModified = objDataReader.GetDateTime(6);

                            objImageDetailList.Add(objImageDetail);
                        }

                    }
                    while (objDataReader.NextResult());
                }

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

            return objImageDetailList;
        }