//------------------------------------------------------ //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(""); } }
//------------------------------------------------------ // //------------------------------------------------------ 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(""); } }
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(); } }
//------------------------------------------------------ // //------------------------------------------------------ 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(""); } }