public ActionResult Create([Bind(Include = "Age,ImagePath,BreedType,PetName,Price,PetType")] PetDetailsViewModel petdetails, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { file.SaveAs(HttpContext.Server.MapPath("~/Images/") + file.FileName); var filepath = HttpContext.Server.MapPath("~/Images/") + file.FileName; PetDetailsDto pet = new PetDetailsDto { Age = petdetails.Age, ImagePath = file.FileName, BreedType = petdetails.BreedType, PetName = petdetails.PetName, Price = petdetails.Price, PetType = petdetails.PetType }; transRepos.Save(pet); } } var xx = GetPetType(); var petType = new SelectList(xx, "TypeId", "PetType"); ViewData["pettype"] = petType; return(View(petdetails)); }
public ActionResult Edit(PetDetailsViewModel petdetails, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { file.SaveAs(HttpContext.Server.MapPath("~/Images/") + file.FileName); var filepath = HttpContext.Server.MapPath("~/Images/") + file.FileName; PetDetailsDto pet = new PetDetailsDto { Age = petdetails.Age, ImagePath = file.FileName, BreedType = petdetails.BreedType, PetName = petdetails.PetName, Price = petdetails.Price, PetType = petdetails.PetType }; transRepos.EditPet(pet, petId); return(RedirectToAction("Index")); } else { ModelState.AddModelError("ImagePath", "Please select a file"); return(RedirectToAction("Edit", "PetDetails", new { id = petId })); } } var xx = GetPetType(); var petType = new SelectList(xx, "TypeId", "PetType", petdetails.PetType); ViewData["pettype"] = petType; return(View(petdetails)); }
public void TestCreatePet() { // assemble var expectedPetDetailsViewModel = CreatePetInputViewModel(); // act Facade.CreatePet(expectedPetDetailsViewModel); // assert PetDetailsViewModel actualPetDetaislViewModel = Facade.FindPet(); actualPetDetaislViewModel.Name.ShouldBeEqualTo(expectedPetDetailsViewModel.Name); }
/// <summary> /// To convert to dto /// </summary> /// <param name="petdetails"></param> /// <param name="file"></param> /// <returns></returns> PetDetailsDto ConvertToDto(PetDetailsViewModel petdetails, HttpPostedFileBase file) { PetDetailsDto pet = new PetDetailsDto { Age = petdetails.Age, ImagePath = file.FileName, BreedType = petdetails.BreedType, PetName = petdetails.PetName, Price = petdetails.Price, PetType = petdetails.PetType, Gender = petdetails.Gender }; return(pet); }
public PetDetailsViewModel GetPetById(int id) { PetDetailsDto pet = transRepos.GetPetById(id); PetDetailsViewModel pt = new PetDetailsViewModel { Age = pet.Age, BreedType = pet.BreedType, PetName = pet.PetName, ImagePath = pet.ImagePath, Price = pet.Price, PetType = pet.PetType }; return(pt); }
/// <summary> /// To get pet by their id /// </summary> /// <param name="id"></param> /// <returns></returns> public PetDetailsViewModel GetPetById(int id) { PetDetailsDto pet = petService.GetPetById(id); PetDetailsViewModel petView = new PetDetailsViewModel { Age = pet.Age, BreedType = pet.BreedType, PetName = pet.PetName, ImagePath = pet.ImagePath, Price = pet.Price, PetType = pet.PetType, Gender = pet.Gender }; return(petView); }
public ActionResult Edit(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { PetDetailsViewModel petview = GetPetById(id); var xx = GetPetType(); petId = id; var petType = new SelectList(xx, "TypeId", "PetType", petview.PetType); ViewData["pettype"] = petType; //return RedirectToAction("Edit","PetDetails",new { petview = petview, id=id}); return(View(petview)); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { var petID = Convert.ToInt32(id); PetDetailsViewModel petview = GetPetById(petID); imagepath = petview.ImagePath; var type = GetPetType(); petId = petID; var petType = new SelectList(type, "TypeId", "PetType", petview.PetType); ViewData["pettype"] = petType; return(View(petview)); } }
public ActionResult Edit(PetDetailsViewModel petdetails, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { file.SaveAs(HttpContext.Server.MapPath("~/Images/") + file.FileName); var filePath = HttpContext.Server.MapPath("~/Images/") + file.FileName; PetDetailsDto pet = new PetDetailsDto { Age = petdetails.Age, ImagePath = file.FileName, BreedType = petdetails.BreedType, PetName = petdetails.PetName, Price = petdetails.Price, PetType = petdetails.PetType, Gender = petdetails.Gender }; petService.EditPet(pet, petId); return(RedirectToAction("Index")); } else if (file == null) { PetDetailsDto pet = new PetDetailsDto { Age = petdetails.Age, ImagePath = imagepath, BreedType = petdetails.BreedType, PetName = petdetails.PetName, Price = petdetails.Price, PetType = petdetails.PetType, Gender = petdetails.Gender }; petService.EditPet(pet, petId); return(RedirectToAction("Index")); } } var type = GetPetType(); var petType = new SelectList(type, "TypeId", "PetType", petdetails.PetType); ViewData["pettype"] = petType; petdetails.ImagePath = imagepath; return(View(petdetails)); }
public ActionResult Create([Bind(Include = "Age,ImagePath,BreedType,PetName,Price,PetType,Gender")] PetDetailsViewModel petdetails, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { file.SaveAs(HttpContext.Server.MapPath("~/Images/") + file.FileName); var filepath = HttpContext.Server.MapPath("~/Images/") + file.FileName; var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".JPG", ".JPEG" }; var checkextension = Path.GetExtension(file.FileName).ToLower(); if (!allowedExtensions.Contains(checkextension)) { ViewBag.ErrorMessage = "Select jpeg or png Image with height and width less than 600"; } else { using (System.Drawing.Image image = System.Drawing.Image.FromStream(file.InputStream, true, true)) { if (image.Width <= 600 && image.Height <= 600) { PetDetailsDto pett = ConvertToDto(petdetails, file); petService.Save(pett); return(RedirectToAction("Index")); } } } } else { ViewBag.ErrorMessage = "Please Select jpeg or png Image with height and width less than 600"; return(View(petdetails)); } } var pet = GetPetType(); var petType = new SelectList(pet, "TypeId", "PetType"); ViewData["pettype"] = petType; return(View(petdetails)); }
public PetDetailsView(PetDetailsViewModel viewModel) { InitializeComponent(); BindingContext = this.viewModel = viewModel; }