public IActionResult EditProfile(EditProfileViewModel model) { if (ModelState.IsValid) { Pet pet = context.Pets.Find(model.ID); pet.Name = model.Name; pet.Birthday = model.Birthday; pet.Color = model.Color; pet.Weight = model.Weight; pet.Gender = model.Gender; pet.BreedName = model.BreedName; pet.Microchipped = model.Microchipped; pet.Fixed = model.Fixed; pet.PhotoPath = model.ExistingPhotoPath; if (model.Photo != null) { if (model.ExistingPhotoPath != null) { string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath); System.IO.File.Delete(filePath); } pet.PhotoPath = ProcessUploadedFile(model); } context.Update(pet); context.SaveChanges(); return(RedirectToAction("index")); } return(View(model)); }
public IActionResult Edit(EditWalkViewModel model) { if (ModelState.IsValid) { Walk walk = context.Walks.Find(model.ID); walk.ID = model.ID; walk.Distance = model.Distance; walk.Poop = model.Poop; walk.Pee = model.Pee; walk.Date = model.Date; walk.Time = model.Time; walk.Notes = model.Notes; context.Update(walk); context.SaveChanges(); return(RedirectToAction("index")); } return(View(model)); }