public IActionResult Add(AddPetViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; if (model.Photo != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } //Breed newBreed = // context.Breeds.Single(c => c.ID == model.BreedID); // Add the new cheese to my existing cheeses Pet newPet = new Pet { Name = model.Name, OwnerId = model.OwnerId, Weight = model.Weight, BreedName = model.BreedName, PhotoPath = uniqueFileName, Gender = model.Gender, Color = model.Color, Birthday = model.Birthday, Microchipped = model.Microchipped, Fixed = model.Fixed }; context.Pets.Add(newPet); context.SaveChanges(); return(Redirect("/Pet")); } return(View(model)); }
public IActionResult Add(AddWalkViewModel addWalkViewModel) { if (ModelState.IsValid) { Walk newWalk = new Walk { Distance = addWalkViewModel.Distance, Poop = addWalkViewModel.Poop, Pee = addWalkViewModel.Pee, Date = addWalkViewModel.Date, Time = addWalkViewModel.Time, Notes = addWalkViewModel.Notes, }; context.Walks.Add(newWalk); context.SaveChanges(); return(Redirect("/Walk")); } return(View(addWalkViewModel)); }