Exemplo n.º 1
0
        /// <UpdateAds>
        /// update/change a ImageUrl,Script,ExpiryDate and Status of existing Ads.
        /// </summary>
        /// <param name="ads">Set Values in a Ads Class Property and Pass the Object of Ads Class.(Domain.Ads)</param>
        public void UpdateAds(Ads ads)
        {
            //Creates a database connection and opens up a session
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                //After Session creation, start Transaction. 
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    try
                    {
                        // Proceed action to Delete Data.
                        // And Set the reuired paremeters to find the specific values.
                        session.CreateQuery("Update Ads set ImageUrl =:imageurl,Script=:script,ExpiryDate=:expirydate,Status=:status where Id = :adsid")
                            .SetParameter("script", ads.Script)
                            .SetParameter("imageurl", ads.ImageUrl)
                            .SetParameter("status", ads.Status)
                            .SetParameter("adsid", ads.Id)
                            .SetParameter("expirydate", ads.ExpiryDate)
                            .ExecuteUpdate();
                        transaction.Commit();


                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        // return 0;
                    }
                }//End using transaction.
            }//End using session.
        }
Exemplo n.º 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Ads objAds = new Ads();
                AdsRepository objAdsRepo = new AdsRepository();
                string advImg=string.Empty;
                if (txtUrl.Text != "")
                    objAds.ImageUrl = txtUrl.Text;
                else if (fuAdv.HasFile)
                {
                   // fuAdv.SaveAs(Server.MapPath("/AdvImage/") + fuAdv.FileName);
                    string FileFullPath = Server.MapPath("/Admin/AdvImage/") + fuAdv.FileName;
                    fuAdv.PostedFile.SaveAs(FileFullPath);

                    objAds.ImageUrl = "/Admin/AdvImage/" + fuAdv.FileName;
                }
                if (txtScript.Text != "")
                    objAds.Script = txtScript.Text;

                objAds.Status = bool.Parse(ddlStatus.SelectedValue);
                objAds.EntryDate = DateTime.Now;
                objAds.ExpiryDate = Convert.ToDateTime(datepicker.Text);
                objAds.Id = Guid.Parse(AddUpdateNews());
                if (objAdsRepo.checkAdsExists(txtAdv.Text))
                    objAdsRepo.UpdateAds(objAds);
                else
                    objAdsRepo.AddAds(objAds);
            }
            catch (Exception Err)
            {
                logger.Error(Err.Message);
                Response.Write(Err.Message);
            }
        }
Exemplo n.º 3
0
 public void AddAds(Ads ads)
 {
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             session.Save(ads);
             transaction.Commit();
         }
     }
 }
Exemplo n.º 4
0
 /// <AddAds>
 /// Add a new Advertisement in a Database.
 /// </summary>
 /// <param name="ads">Set Values in a Ads Class Property and Pass the Object of Ads Class.(Domain.Ads)</param>
 public void AddAds(Ads ads)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction. 
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             //Process action to save data.
             session.Save(ads);
             transaction.Commit();
         }//End using transaction.
     }//End using session.
 }
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                if (Session["AdminProfile"] == null)
                {
                    Response.Redirect("Default.aspx");
                }

                if (Request.QueryString != null)
                {
                    if (Request.QueryString["id"] != null)
                    {
                        Ads objAds = new Ads();
                        AdsRepository objAdsRepo = new AdsRepository();

                        objAds = objAdsRepo.getAdsDetailsbyId(Guid.Parse(Request.QueryString["id"]));
                        txtAdv.Text = objAds.Advertisment;
                        txtUrl.Text = objAds.ImageUrl;
                        datepicker.Text = objAds.ExpiryDate.ToString();
                        if (objAds.Status == true)
                        {
                            ddlStatus.SelectedValue = "True";
                        }
                        else
                        {
                            ddlStatus.SelectedValue = "False";
                        }
                    }
                }






            }
        }
Exemplo n.º 6
0
        public void UpdateAds(Ads ads)
        {
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    try
                    {
                        session.CreateQuery("Update Ads set ImageUrl =:imageurl,Script=:script,ExpiryDate=:expirydate,Status=:status where Id = :adsid")
                            .SetParameter("script", ads.Script)
                            .SetParameter("imageurl", ads.ImageUrl)
                            .SetParameter("status", ads.Status)
                            .SetParameter("adsid", ads.Id)
                            .SetParameter("expirydate", ads.ExpiryDate)
                            .ExecuteUpdate();
                        transaction.Commit();

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        // return 0;
                    }
                }
            }
        }