// GET: Variety public ActionResult Index(int kindSN, int page = 1, int pageSize = 10) { List <Comm_Variety> varietyList = VarietyModel.getVarietyListByKindSN(kindSN); var result = varietyList.OrderBy(o => o.SN).ToPagedList(); ViewBag.kindSN = kindSN; return(View(result)); }
public JsonResult getVarietyList(int kindSN) { List <Comm_Variety> varietyList = new List <Comm_Variety>(); if (kindSN != 0) { varietyList = VarietyModel.getVarietyListByKindSN(kindSN); varietyList.Insert(0, new Comm_Variety() { SN = 0, varietyName = "品種" }); } else { varietyList.Add(new Comm_Variety() { SN = 0, varietyName = "品種" }); } return(Json(varietyList, JsonRequestBehavior.AllowGet)); }
// GET: Pet/Edit/5 public ActionResult Edit(int?SN) { if (SN == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Comm_Pet pet = PetModel.getPetBySN(Convert.ToInt32(SN)); if (pet == null) { return(HttpNotFound()); } List <Comm_Customer> customerList = CustomerModel.getCustomerList(); List <Comm_Kind> kindList = KindModel.getKindList(); List <Comm_Variety> varietyList = VarietyModel.getVarietyListByKindSN(pet.kindSN); ViewBag.customerSN = new SelectList(customerList, "SN", "customerName", pet.customerSN); ViewBag.kindSN = new SelectList(kindList, "SN", "kindName", pet.kindSN); ViewBag.varietySN = new SelectList(varietyList, "SN", "varietyName", pet.varietySN); return(View(pet)); }
public ActionResult Edit(int?SN, int?customerSN, string petName, int?petGender, int?kindSN, int?varietySN, string petRemark) { try { if (SN == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Comm_Pet pet = PetModel.getPetBySN(Convert.ToInt32(SN)); if (pet == null) { return(HttpNotFound()); } #region Validation if (customerSN == null) { ModelState.AddModelError("customerSN", "請選擇飼主"); } if (petName == string.Empty) { ModelState.AddModelError("petName", "請輸入寵物名稱"); } if (petGender == null) { ModelState.AddModelError("petGender", "請選擇寵物性別"); } if (kindSN == null) { ModelState.AddModelError("kindSN", "請選擇物種"); } if (varietySN == null) { ModelState.AddModelError("varietySN", "請選擇品種"); } if (!ModelState.IsValid) { List <Comm_Customer> customerList = CustomerModel.getCustomerList(); List <Comm_Kind> kindList = KindModel.getKindList(); List <Comm_Variety> varietyList = VarietyModel.getVarietyListByKindSN(pet.kindSN); ViewBag.customerSN = new SelectList(customerList, "SN", "customerName", pet.customerSN); ViewBag.kindSN = new SelectList(kindList, "SN", "kindName", pet.kindSN); ViewBag.varietySN = new SelectList(varietyList, "SN", "varietyName", pet.varietySN); return(View(pet)); } #endregion Boolean gender = false; if (petGender == 1) { gender = true; } pet.customerSN = Convert.ToInt32(customerSN); pet.petName = petName; pet.petGender = gender; pet.kindSN = Convert.ToInt32(kindSN); pet.varietySN = Convert.ToInt32(varietySN); pet.petRemark = petRemark; return(RedirectToAction("Index")); } catch { return(View()); } }