예제 #1
0
        protected void SbmBtn_Click(object sender, EventArgs e)
        {
            CrusadersService.NewsEntity news = new CrusadersService.NewsEntity();

            news.Title = TxtTlt.Text;
            news.Content = TxtCnt.Text;

            if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
            {
                string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
                string SaveLocation = Server.MapPath("/Admin/News/Data/") + fn;
                try
                {
                    File1.PostedFile.SaveAs(SaveLocation);
                    news.Image = fn;
                }
                catch (Exception ex)
                {
                    Response.Write("Error: " + ex.Message);
                    //Note: Exception.Message returns a detailed message that describes the current exception.
                    //For security reasons, we do not recommend that you return Exception.Message to end users in
                    //production environments. It would be better to return a generic error message.
                }

            }

            db.AddToNewsEntities(news);
            db.SaveChanges();
            setCreatedMessage();
            Response.Redirect("Show.aspx");
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["Id"];
            if (!string.IsNullOrEmpty(id))
            {
                if (!IsPostBack)
                {
                    db = Global.CrusadersEntitiesDB();

                    one_news = db.NewsEntities.Where(x => x.Id == int.Parse(id)).First();

                }
            }
            else
            {
                Response.Redirect("News.aspx");
            }

        }
예제 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            db = Global.CrusadersEntitiesDB();
            string id = Request.QueryString["id"];
            if (!string.IsNullOrEmpty(id))
            {
                if (!IsPostBack)
                {
                    news = db.NewsEntities.Where(x => x.Id == int.Parse(id)).First();

                    TxtTlt.Text = news.Title;
                    TxtCnt.Text = news.Content;;
                }
            }
            else
            {
                Response.Redirect("Show.aspx");
            }
        }