public ActionResult Create(Tbl_Pets tbl_Pets, HttpPostedFileBase ImageUpload) { try { if (ModelState.IsValid) { string filename = Path.GetFileNameWithoutExtension(ImageUpload.FileName); string extension = Path.GetExtension(ImageUpload.FileName); filename = filename + extension; tbl_Pets.img_location = "~/Models/img/" + filename; filename = Path.Combine(Server.MapPath("~/Models/img/"), filename); ImageUpload.SaveAs(filename); db.Tbl_Pets.Add(tbl_Pets); db.SaveChanges(); return(RedirectToAction("List")); } return(View(tbl_Pets)); } catch (Exception e) { return(View(e.Message)); } }
public ActionResult adopt(int id) { try { Tbl_Pets p = db.Tbl_Pets.Find(id); int cost = Convert.ToInt32(p.Pet_Price); int userid = Convert.ToInt32(Session["id"]); Tbl_User u = db.Tbl_User.Find(userid); int h = u.Wallet - cost; if ((h) > 0) { db.taken(p.PetID); db.amount(u.UserID, h); Session["amount"] = h; ViewBag.SuccessMessage = "Thank You for Your Adoption!The amount has been debited from your Wallet"; Session["SuccessMessage"] = "Thank You for Your Adoption!The amount has been debited from your Wallet"; TempData["SuccessMessage"] = "Thank You for Your Adoption!The amount has been debited from your Wallet"; return(RedirectToAction("Index", "USER")); } ViewBag.FailureMessage = "Sorry You dont have sufficient balance. Please recharge and try again"; Session["FailureMessage"] = "Sorry You dont have sufficient balance. Please recharge and try again"; TempData["FailureMessage"] = "Sorry You dont have sufficient balance. Please recharge and try again"; return(RedirectToAction("Recharge")); } catch (Exception e) { return(View(e.Message)); } }
public ActionResult changeleft1() { try { int id1 = Convert.ToInt32(TempData["id1"]); int id2 = Convert.ToInt32(TempData["id2"]); int h = id1; animals1 aa2 = db.animals1.Find(id2); aa2.ranking++; db.SaveChanges(); animals1 aa1; Random r = new Random(); do { id1 = r.Next(101, 106); aa1 = db.animals1.Find(id1); } while ((id1 == id2) || (id1 == h) || (aa1 == null)); aa1 = db.animals1.Find(id1); Tbl_Pets p1 = db.Tbl_Pets.Find(aa1.pet_id); Tbl_Pets p2 = db.Tbl_Pets.Find(aa2.pet_id); TempData["message1"] = p1.img_location; TempData["id1"] = id1; TempData["message2"] = p2.img_location; TempData["id2"] = id2; return(RedirectToAction("Show2")); } catch (Exception e) { return(View(e.Message)); } }
public ActionResult Edit(Tbl_Pets tbl_Pets, HttpPostedFileBase ImageUpload) { try { if (!ModelState.IsValid) { if (ImageUpload == null) { tb.PetID = tbl_Pets.PetID; tb.Pet_Breed = tbl_Pets.Pet_Breed; tb.Pet_Category = tbl_Pets.Pet_Category; tb.Pet_Price = tbl_Pets.Pet_Price; tb.Sex = tbl_Pets.Sex; tb.Height = tbl_Pets.Height; tb.Weights = tbl_Pets.Weights; db.Entry(tbl_Pets).State = EntityState.Modified; //db.SaveChanges(); return(RedirectToAction("List")); } else { string filename = Path.GetFileNameWithoutExtension(ImageUpload.FileName); string extension = Path.GetExtension(ImageUpload.FileName); filename = filename + extension; tbl_Pets.img_location = "~/Images/" + filename; tb.PetID = tbl_Pets.PetID; tb.Pet_Breed = tbl_Pets.Pet_Breed; tb.Pet_Category = tbl_Pets.Pet_Category; tb.Pet_Price = tbl_Pets.Pet_Price; tb.Sex = tbl_Pets.Sex; tb.Height = tbl_Pets.Height; tb.Weights = tbl_Pets.Weights; filename = Path.Combine(Server.MapPath("~/Images/"), filename); ImageUpload.SaveAs(filename); db.Entry(tbl_Pets).State = EntityState.Modified; //db.SaveChanges(); return(RedirectToAction("List")); } } return(View(tbl_Pets)); } catch (Exception e) { Response.Write("cannot edit"); } return(RedirectToAction("List")); }
public ActionResult Show1() { try { Random r = new Random(); int id1, id2; animals1 aa1; animals1 aa2; do { id1 = r.Next(101, 117); id2 = r.Next(101, 117); aa1 = db.animals1.Find(id1); aa2 = db.animals1.Find(id2); } while ((id1 == id2) || (aa1 == null) || (aa2 == null)); //TempData["lcount"] = 0; //TempData["rcount"] = 0; TempData["id2"] = id2; TempData["id1"] = id1; Tbl_Pets a1 = db.Tbl_Pets.Find(aa1.pet_id); Tbl_Pets a2 = db.Tbl_Pets.Find(aa2.pet_id); TempData["message1"] = a1.img_location; TempData["message2"] = a2.img_location; return(View()); } catch (Exception e) { return(View(e.Message)); } }
// GET: Pets/Delete/5 #region Delete public ActionResult Delete1(int?id) { try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tbl_Pets t = db.Tbl_Pets.Find(id); db.Tbl_Pets.Remove(t); db.SaveChanges(); return(RedirectToAction("List")); } catch (Exception e) { return(View(e.Message)); } }
public ActionResult Adoption_Fish() { Tbl_Pets pets = new Tbl_Pets(); string[] category = new string[] { "fish", "Fish" }; try { var result = from cat in db.Tbl_Pets where cat.Pet_Category == "fish" || cat.Pet_Category == "Fish" && cat.taken == "Not" select cat; return(View(result.ToList())); } catch (Exception) { Response.Write("Something went wrong"); } return(View()); }
// GET: Pets/Details/5 #region Details public ActionResult Details(int?id) { try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tbl_Pets tbl_Pets = db.Tbl_Pets.Find(id); if (tbl_Pets == null) { return(HttpNotFound()); } return(View(tbl_Pets)); } catch (Exception e) { return(View(e.Message)); } }
// GET: Pets/Edit/5 #region Edit // GET: Pets/Edit/5 public ActionResult Edit(int?id) { try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tbl_Pets tbl_Pets = db.Tbl_Pets.Find(id); if (tbl_Pets == null) { return(HttpNotFound()); } return(View(tbl_Pets)); } catch (Exception e) { Response.Write("cannot edit"); } return(RedirectToAction("List")); }
public ActionResult Adoption_Dog() { Tbl_Pets pets = new Tbl_Pets(); Tbl_User user = new Tbl_User(); var userid = Session["id"]; user = db.Tbl_User.Find(userid); ViewBag.Amount = Convert.ToUInt32(user.Wallet); string[] category = new string[] { "dog", "Dogs" }; try { var result = (from cat in db.Tbl_Pets where cat.Pet_Category == "Dog" || cat.Pet_Category == "Dogs" || cat.Pet_Category == "dogs" || cat.Pet_Category == "dog" && cat.taken == "Not" select cat); return(View(result.ToList())); } catch (Exception) { Response.Write("Something went wrong"); } return(View()); }