protected void BtnAdd_Click(object sender, EventArgs e) { string petcategoryID = tbPetCategoryID.Text.Trim().ToString(); string categoryName = tbCategoryName.Text.Trim().ToString(); string categoryInfo = tbCategoryInfo.Text.Trim().ToString(); CTPetCategory category = new CTPetCategory(); category.petCategoryID = petcategoryID; category.petCategoryName = categoryName; category.petCategoryInfo = categoryInfo; PetCategory petcategory = new PetCategory(); int insertStatus = 0; insertStatus = petcategory.InsertPetCategory(category); if (insertStatus != 0) { Response.Write("<script>alert('添加成功!')</script>"); } else { Response.Write("<script>alert('添加失败!')</script>"); } }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(string [] selectedCategories) { var newPet = new Pet(); if (selectedCategories != null) { newPet.PetCategories = new List <PetCategory>(); foreach (var cat in selectedCategories) { var catToAdd = new PetCategory { CategoryID = int.Parse(cat) }; newPet.PetCategories.Add(catToAdd); } } if (await TryUpdateModelAsync <Pet>( newPet, "Pet", i => i.Name, i => i.Breed, i => i.Age, i => i.AvailableDate, i => i.LocationID, i => i.Photo)) { _context.Pet.Add(newPet); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCategoryData(_context, newPet); return(Page()); }
//单击save按钮 protected void btnSave_Click(object sender, EventArgs e) { string petCategoryID = tbEditPetCategoryID.Text.Trim().ToString(); string petCategoryInfo = tbEditPetCategoryInfo.Text.Trim().ToString(); string petCategoryName = tbEditPetCategoryName.Text.Trim().ToString(); bool isVisible = bool.Parse(cbIsvisible.Checked.ToString()); CTPetCategory tpetcategory = new CTPetCategory(); tpetcategory.petCategoryID = petCategoryID; tpetcategory.petCategoryInfo = petCategoryInfo; tpetcategory.petCategoryName = petCategoryName; tpetcategory.IsVisible = isVisible; PetCategory petcategory = new PetCategory(); int insertStatus = petcategory.EditPetCategory(tpetcategory); if (insertStatus != 0) { LoadData(); Response.Write("<script>alert('update成功!')</script>"); } else { Response.Write("<script>alert('update失败!')</script>"); } }
public ActionResult DeleteConfirmed(long id) { PetCategory petCategory = db.PetCategories.Find(id); db.PetCategories.Remove(petCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Category,CName,CreateDateTime")] PetCategory petCategory) { if (ModelState.IsValid) { db.Entry(petCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(petCategory)); }
private void LoadData() { List <CTPetCategory> list = new List <CTPetCategory>(); PetCategory petcategory = new PetCategory(); list = petcategory.GetPetCategoryList(); GridView1.DataSource = list; GridView1.DataKeyNames = new string[] { "petCategoryID" }; GridView1.DataBind(); }
public ActionResult Create([Bind(Include = "Id,Category,CName,CreateDateTime")] PetCategory petCategory) { if (ModelState.IsValid) { db.PetCategories.Add(petCategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(petCategory)); }
// GET: PetCategories/Delete/5 public ActionResult Delete(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PetCategory petCategory = db.PetCategories.Find(id); if (petCategory == null) { return(HttpNotFound()); } return(View(petCategory)); }
//单击删除按钮 protected void BtnDelete_Click(object sender, EventArgs e) { PetCategory petcategory = new PetCategory(); for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBoxs"); if (cbox.Checked == true) { string sqlstr = GridView1.DataKeys[i].Value.ToString(); petcategory.DeletePetCategory(sqlstr); } } LoadData(); }
public IActionResult DeletePetCat([FromBody] string id) { PetCategoryDAO dao = new PetCategoryDAO(_context); PetCategory dto = _context.PetCategory.Find(id); string msg; if (dao.Remove(dto)) { msg = "Delete pet category success"; } else { msg = "Delete pet category failed. It may contains some other categories."; } return(new JsonResult(msg)); }
private void LoadPetCategory() { List <CTPetCategory> petcategoryList = new List <CTPetCategory>(); PetCategory petcategory = new PetCategory(); petcategoryList = petcategory.GetPetCategoryList(); dpCategory.DataSource = petcategoryList; dpCategory.DataTextField = "petCategoryName"; dpCategory.DataValueField = "petCategoryID"; dpCategory.DataBind(); ddlPetCategory.DataSource = petcategoryList; ddlPetCategory.DataTextField = "petCategoryName"; ddlPetCategory.DataValueField = "petCategoryID"; ddlPetCategory.DataBind(); ddlPetCategory.Items.Insert(0, new ListItem("", "")); }
public IActionResult UpdatePetCat([FromBody] DTO.PetCategory petCat) { PetCategoryDAO dao = new PetCategoryDAO(_context); PetCategory dto = new PetCategory { PetCatId = petCat.PetCatId, PetType = petCat.PetType }; string msg; if (dao.Update(dto)) { msg = "Update pet category success"; } else { msg = "Update pet category failed"; } return(new JsonResult(msg)); }
public bool Remove(PetCategory dto) { _context.PetCategory.Remove(dto); return(_context.SaveChanges() != 0); }
public bool Update(PetCategory dto) { _context.PetCategory.Update(dto); return(_context.SaveChanges() != 0); }
public bool Insert(PetCategory dto) { _context.PetCategory.Add(dto); return(_context.SaveChanges() != 0); }