public ActionResult DayCare(Tbl_DayCare tbl_DayCare, FormCollection frm) { var category = frm["PetCategory"].ToString(); var service = frm["Service_id"].ToString(); //if (string.IsNullOrEmpty(frm["PetCategory"])|| string.IsNullOrEmpty(frm["Service_id"])) //{ // ModelState.AddModelError("PetCategory", "Please select some pet category"); // ModelState.AddModelError("Service_id", "Please select some services"); //} if (category == "" || service == "") { ModelState.AddModelError("PetCategory", "Please select some pet category"); ModelState.AddModelError("Service_id", "Please select some services"); } else { if (ModelState.IsValid) { try { //var category = frm["PetCategory"].ToString(); //var service = frm["Service_id"].ToString(); tbl_DayCare.PetCategory = category; ViewBag.Service_id = new SelectList(db.Tbl_Service, "Service_Id", "Service_Type", tbl_DayCare.Service_id); ViewBag.UserID = new SelectList(db.Tbl_User, "UserID", "UserName", tbl_DayCare.UserID); var servicetype = (from servicetable in db.Tbl_Service where servicetable.Service_Type == service select servicetable.Service_Id).Single(); tbl_DayCare.Service_id = servicetype; var Userid = Convert.ToInt32(Session["id"]); tbl_DayCare.UserID = Userid; db.Tbl_DayCare.Add(tbl_DayCare); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { return(View(e.Message)); } } } return(View()); }
// GET: Tbl_DayCare/Delete/5 #region delete public ActionResult Delete(int?id) { try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tbl_DayCare tbl_DayCare = db.Tbl_DayCare.Find(id); if (tbl_DayCare == null) { return(HttpNotFound()); } db.Tbl_DayCare.Remove(tbl_DayCare); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { return(View(e.Message)); } }