public async Task<ActionResult> Insert(AdvertismentModal advertise)
        {
            var dbHelpre = DBHelper.Instance;
            dbHelpre.BeginTransaction();

            return await Task.Run(() =>
            {
                try
                {
                    bool IsValid = false;
                    ViewBag.Message = "Insert New Avertisment.";

                    if (ModelState.IsValid)
                    {
                        var objAdvertise = new Advertisment();

                        objAdvertise.Heading = advertise.Heading.Trim();
                        objAdvertise.WebUrl = advertise.WebUrl.Trim();
                        objAdvertise.WebLink = advertise.WebLink.Trim();
                        objAdvertise.ShortDesc = advertise.ShortDesc.Trim();
                        objAdvertise.DisplayOrder = advertise.DisplayOrder;
                        objAdvertise.IsActive = advertise.IsActive ? 1 : 0;
                        objAdvertise.IsApproved = advertise.IsApproved ? 1 : 0;
                        objAdvertise.Position = (Int32)Position.PageRight;
                        objAdvertise.AdvertismentType = (Int32)AdvertismentType.TopNewsAdd;

                        var fileName = string.Empty;
                        if (advertise.Image != null && advertise.Image.ContentLength > 0)
                        {
                            fileName = new Random().Next(1000000000).ToString() + Path.GetFileName(advertise.Image.FileName);
                            objAdvertise.ImgUrl = ImagePath.TopTenAdvertisment + "/" + fileName;
                        }

                        AdvertismentDB.Instance.Insert(ref dbHelpre, objAdvertise);

                        if (!string.IsNullOrEmpty(fileName))
                        {
                            IsValid = SaveImage(ImagePath.TopTenAdvertisment, fileName, advertise.Image);
                        }

                        if (!IsValid)
                        {
                            dbHelpre.RollbackTransaction();
                            ModelState.AddModelError("INSERT", "Oops ! There is some error.");
                            ViewBag.Message = "Oops ! There is some error.";
                        }

                        if (IsValid)
                        {
                            dbHelpre.CommitTransaction();
                            ViewBag.Message = "Advertise Successfully Ceated..";
                            ModelState.Clear();
                            advertise = new AdvertismentModal();
                        }
                    }
                    else
                    {
                        //ModelState.AddModelError("INSERT", "Oops ! There is some error.");
                        ViewBag.Message = "Oops ! There is some error.";
                    }
                }
                catch (Exception ex)
                {
                    dbHelpre.RollbackTransaction();
                    throw ex;
                }
                finally
                {
                    dbHelpre.ClearAllParameters();
                    dbHelpre.CloseConnection();
                    dbHelpre.Dispose();
                }

                return View(advertise);
            });

        }
Ejemplo n.º 2
0
        public List<IAdvertisment> SelectAll(System.Int32 AdvertismentType, System.Int32 IsActive = -1, System.Int32 IsApproved = -1)
        {
            IDataReader objDataReader = null;
            List<IAdvertisment> objAdvertismentList = null;
            IAdvertisment objAdvertisment = null;

            DBHelper dbInstance = DBHelper.Instance;
            try
            {
                dbInstance.AddInParameter("@AddType", AdvertismentType, DbType.Int32);
                dbInstance.AddInParameter("@IsActive", IsActive, DbType.Int32);
                dbInstance.AddInParameter("@IsApproved", IsApproved, DbType.Int32);

                objDataReader = dbInstance.ExecuteDataReader(ProcedureName.SelectAllAdvertisment, CommandType.StoredProcedure);

                if (objDataReader != null)
                {
                    objAdvertismentList = new List<IAdvertisment>();
                    do
                    {
                        while (objDataReader.Read())
                        {
                            objAdvertisment = new Advertisment();

                            if (!objDataReader.IsDBNull(0))
                                objAdvertisment.AdvertismentID = objDataReader.GetString(0);

                            if (!objDataReader.IsDBNull(1))
                                objAdvertisment.DisplayOrder = objDataReader.GetInt32(1);

                            if (!objDataReader.IsDBNull(2))
                                objAdvertisment.Heading = objDataReader.GetString(2);

                            if (!objDataReader.IsDBNull(3))
                                objAdvertisment.WebUrl = objDataReader.GetString(3);

                            if (!objDataReader.IsDBNull(4))
                                objAdvertisment.WebLink = objDataReader.GetString(4);

                            if (!objDataReader.IsDBNull(5))
                                objAdvertisment.ShortDesc = objDataReader.GetString(5);

                            if (!objDataReader.IsDBNull(6))
                                objAdvertisment.ImgUrl = objDataReader.GetString(6);

                            if (!objDataReader.IsDBNull(7))
                                objAdvertisment.AdvertismentType = objDataReader.GetInt32(7);

                            if (!objDataReader.IsDBNull(8))
                                objAdvertisment.Position = objDataReader.GetInt32(8);

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

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

                            if (!objDataReader.IsDBNull(11))
                                objAdvertisment.DttmCreated = objDataReader.GetDateTime(11);

                            if (!objDataReader.IsDBNull(12))
                                objAdvertisment.DttmModified = objDataReader.GetDateTime(12);

                            objAdvertismentList.Add(objAdvertisment);
                        }

                    }
                    while (objDataReader.NextResult());
                }

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

            return objAdvertismentList;
        }