//public ActionResult Display(string name) //{ // var pm = new PetManagement(); // var model = pm.GetByName(name); // if (model == null) // return RedirectToAction("NotFound"); // return View(model); //} public JsonResult GetInfo() { var name = (string)RouteData.Values["id"]; var pm = new PetManagement(); var pet = pm.GetByName(name); return(Json(pet, JsonRequestBehavior.AllowGet)); }
public Pet Info(string name) { Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(name)); var pm = new PetManagement(); var pet = pm.GetByName(name); return(pet); }
public ActionResult PictureUpload(PictureModel model) { if (model.PictureFile.ContentLength > 0) { var fileName = Path.GetFileName(model.PictureFile.FileName); var filePath = Server.MapPath("/Content/Uploads"); string savedFileName = Path.Combine(filePath, fileName); model.PictureFile.SaveAs(savedFileName); PetManagement.CreateThumbnail(fileName, filePath, 100, 100, true); } return(View(model)); }
public ActionResult DisplayHttpNotFound() { var name = (string)RouteData.Values["id"]; var pm = new PetManagement(_repository); var model = pm.GetByName(name); if (model == null) { return(HttpNotFound("Pet not found...")); } return(View(model)); }
public ActionResult Display() { var name = (string)RouteData.Values["id"]; var pm = new PetManagement(_repository); var model = pm.GetByName(name); if (model == null) { return(RedirectToAction("NotFound")); } return(View(model)); }
public ActionResult PictureUpload(PictureViewModel picture) { if (picture.PictureFile.ContentLength > 0) { string filePath = Server.MapPath("/Content/Uploads"); string fileName = picture.PictureFile.FileName; string saveFileName = Path.Combine(filePath, fileName); picture.PictureFile.SaveAs(saveFileName); PetManagement.CreateThumbnail(filePath, fileName, picture.ImageHeight, picture.ImageWidth, true); return(RedirectToAction("Index")); } return(View()); }
public ActionResult PictureUpload(PictureModel model) //handles upload of photo { if (model.PictureFile.ContentType != "image/jpeg" && model.PictureFile.ContentType != "image/png") //checking content type { return(View()); } if (model.PictureFile.ContentLength > 0) //checking content file length { var fileName = Path.GetFileName(model.PictureFile.FileName); var filePath = Server.MapPath("/Content/Uploads"); string savedFileName = Path.Combine(filePath, fileName); model.PictureFile.SaveAs(savedFileName); var pm = new PetManagement(); pm.CreateThumbnail(fileName, filePath, 100, 100, true); ViewBag.UploadResult = "Success"; } return(View(model)); }
public void GetByName_ExistingPet_ReturnsPet() { // Arrange string petName = "Fido"; Mock <IRepository> _repository = new Mock <IRepository>(); _repository.Setup(x => x.GetPetByName(It.Is <string>(y => y == "Fido"))).Returns(new Models.Pet { PetName = "Fido" }); var pm = new PetManagement(_repository.Object); // Act var result = pm.GetByName(petName); // Assert // The pet exists Assert.IsNotNull(result); // The pet name is "Fido" Assert.AreEqual(petName, result.PetName); }
public ActionResult PictureUpload(PictureModel model) { if (model.PictureFile.ContentType != "image/jpeg" && model.PictureFile.ContentType != "image/png") { return(View()); } if (model.PictureFile.ContentLength > 0) //looks for length of content file. If not < 0, there is no content { var fileName = Path.GetFileName(model.PictureFile.FileName); var filePath = Server.MapPath("/Content/Uploads"); string savedFileName = Path.Combine(filePath, fileName); model.PictureFile.SaveAs(savedFileName); var pm = new PetManagement(); pm.CreateThumbnail(fileName, filePath, 100, 100, true); ViewBag.UploadResult = "Sucess"; } return(View(model)); }