Esempio n. 1
0
        //------------------------------------------------------
        //
        //------------------------------------------------------
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (var context = new SinglePageAppEntities())
                {
                    var newCategory = new Category
                    {
                        Title        = txtTitle.Text,
                        Description  = txtDescription.Text,
                        CreationDate = DateTime.Now
                    };
                    context.Categories.Add(newCategory);
                    context.SaveChanges();
                }

                divFormContainer.Visible = false;
                ltrMessage.Text          = "تم الاضافة الحمد لله";
                alertBox.Visible         = true;
            }
            catch {
                alertBox.InnerText = "Error happend ya halawa";
                alertBox.Visible   = true;

                //throw new Exception("");
            }
        }
        //------------------------------------------------------
        //btnSave_Click
        //------------------------------------------------------
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                int id = Convert.ToInt32(Request.QueryString["id"]);
                using (var context = new SinglePageAppEntities())
                {
                    var post = context.Posts.Where(p => p.PostID == id).FirstOrDefault();
                    post.Title       = txtTitle.Text;
                    post.Description = txtDescription.Text;
                    context.SaveChanges();
                }

                divFormContainer.Visible = false;
                ltrMessage.Text          = "تم التعديل الحمد لله";
                alertBox.Visible         = true;
            }
            catch
            {
                alertBox.InnerText = "Error happend ya halawa";
                alertBox.Visible   = true;

                //throw new Exception("");
            }
        }
 private void LoadData()
 {
     using (var context = new SinglePageAppEntities())
     {
         drCategories.DataSource = context.Categories.ToList();
         drCategories.DataBind();
     }
 }
        private void Delete()
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);

            using (var context = new SinglePageAppEntities())
            {
                var category = context.Categories.Where(c => c.CategoryID == id).FirstOrDefault();
                context.Categories.Remove(category);
                context.SaveChanges();
            }
        }
        //------------------------------------------------------


        protected override void Delete()
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);

            using (var context = new SinglePageAppEntities())
            {
                var post = context.Posts.Where(c => c.PostID == id).FirstOrDefault();
                context.Posts.Remove(post);
                context.SaveChanges();
            }
        }
Esempio n. 6
0
        private void LoadData()
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);

            using (var context = new SinglePageAppEntities())
            {
                var category = context.Categories.Where(e => e.CategoryID == id).FirstOrDefault();
                txtTitle.Text       = category.Title;
                txtDescription.Text = category.Description;
            }
        }
 //------------------------------------------------------
 //LoadCategories
 //------------------------------------------------------
 private void LoadCategories()
 {
     using (var context = new SinglePageAppEntities())
     {
         var categoryList = context.Categories.ToList();
         ddlCategories.DataSource     = categoryList;
         ddlCategories.DataValueField = "CategoryID";
         ddlCategories.DataTextField  = "Title";
         ddlCategories.DataBind();
         ddlCategories.Items.Insert(0, new ListItem("choose category", "-1"));
     }
 }
        protected void ddlCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedCategoryID = Convert.ToInt32(ddlCategories.SelectedValue);

            using (var context = new SinglePageAppEntities())
            {
                //------------------------------------------------------
                drPosts.DataSource = context.Posts.Where(p => p.CategoryID == selectedCategoryID || selectedCategoryID <= 0).ToList();
                drPosts.DataBind();
                //------------------------------------------------------
            }
        }
 //------------------------------------------------------
 //
 //------------------------------------------------------
 private void LoadData()
 {
     using (var context = new SinglePageAppEntities())
     {
         var categoryList = context.Categories.ToList();
         ddlCategories.DataSource     = categoryList;
         ddlCategories.DataValueField = "CategoryID";
         ddlCategories.DataTextField  = "Title";
         ddlCategories.DataBind();
         foreach (var item in categoryList)
         {
             DropDownList1.Items.Add(new ListItem {
                 Text = item.Title, Value = item.CategoryID.ToString()
             });
             Select1.Items.Add(new ListItem {
                 Text = item.Title, Value = item.CategoryID.ToString()
             });
         }
     }
 }
Esempio n. 10
0
        //------------------------------------------------------
        //LoadData
        //------------------------------------------------------
        private void LoadData()
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);

            using (var context = new SinglePageAppEntities())
            {
                //------------------------------------------------------
                //LoadCategories
                //------------------------------------------------------
                var categoryList = context.Categories.ToList();
                ddlCategories.DataSource     = categoryList;
                ddlCategories.DataValueField = "CategoryID";
                ddlCategories.DataTextField  = "Title";
                ddlCategories.DataBind();
                //------------------------------------------------------
                var post = context.Posts.Where(e => e.PostID == id).FirstOrDefault();
                txtTitle.Text       = post.Title;
                txtDescription.Text = post.Description;
                //------------------------------------------------------
            }
        }
        //------------------------------------------------------
        //LoadData
        //------------------------------------------------------
        private void LoadData()
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);

            using (var context = new SinglePageAppEntities())
            {
                //------------------------------------------------------
                //LoadCategories
                //------------------------------------------------------
                var categoryList = context.Categories.ToList();
                ddlCategories.DataSource     = categoryList;
                ddlCategories.DataValueField = "CategoryID";
                ddlCategories.DataTextField  = "Title";
                ddlCategories.DataBind();
                ddlCategories.Items.Insert(0, new ListItem("choose category", "-1"));
                //------------------------------------------------------
                drPosts.DataSource = context.Posts.ToList();
                drPosts.DataBind();
                //------------------------------------------------------
            }
        }
Esempio n. 12
0
        //------------------------------------------------------
        //
        //------------------------------------------------------
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string filesPath = Path.GetExtension(fuImage.FileName);
                // ItemsFiles.FileExtension = Path.GetExtension(fuPhoto.FileName);
                if (fuImage.HasFile)
                {
                    string serverPath = Server.MapPath("/App_Files/");

                    fuImage.SaveAs(serverPath + fuImage.FileName);
                }
                using (var context = new SinglePageAppEntities())
                {
                    var newPost = new Post
                    {
                        Title        = txtTitle.Text,
                        Description  = txtDescription.Text,
                        CategoryID   = Convert.ToInt32(ddlCategories.SelectedValue),
                        CreationDate = DateTime.Now
                    };
                    context.Posts.Add(newPost);
                    context.SaveChanges();
                }

                divFormContainer.Visible = false;
                ltrMessage.Text          = "تم الاضافة الحمد لله";
                alertBox.Visible         = true;
            }
            catch (Exception ex) {
                alertBox.InnerText = "Error happend ya halawa";
                alertBox.Visible   = true;

                //throw new Exception("");
            }
        }