public ActionResult Edit(int id) { using (var ctx = new ApplicationDbContext()) { ViewBag.ShelterList = ctx.Shelters.Select (s => new SelectListItem() { Text = s.ShelterName, Value = s.ShelterId.ToString() } ).ToList(); } var service = new DogService(); var detail = service.GetDogById(id); var model = new DogEdit { DogId = detail.DogId, DogName = detail.DogName, DogBreed = detail.DogBreed, DogSex = detail.DogSex, DogWeight = detail.DogWeight, DogAge = detail.DogAge, DogPrice = detail.DogPrice, DogImage = detail.DogImage, ShelterId = detail.ShelterId }; return(View(model)); }
public bool UpdateDog(DogEdit model) { using (var ctx = new ApplicationDbContext()) { var dog = ctx.Dogs.Single(d => d.DogId == model.DogId); dog.DogName = model.DogName; dog.Weight = model.Weight; dog.Breed = model.Breed; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateDogService(); var detail = service.GetDogById(id); var model = new DogEdit { Name = detail.Name, ClientId = detail.ClientId }; return(View(model)); }
public bool UpdateDog(DogEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Dogs .Single(e => e.DogId == model.DogId); entity.Name = model.Name; entity.ClientId = model.ClientId; return(ctx.SaveChanges() == 1); } }
//edit dog public IHttpActionResult Put(int id, [FromBody] DogEdit dog) { GetById(id); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateDogServices(); if (!service.UpdateDog(dog)) { return(InternalServerError()); } return(Ok("The nature of this dog has been altered! (ノ◕ヮ◕)ノ*:・゚✧ ")); }
public bool UpdateDog(DogEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Dogs .Single(e => e.DogId == model.DogId); entity.DogName = model.DogName; entity.DogBreed = model.DogBreed; entity.DogSex = model.DogSex; entity.DogWeight = model.DogWeight; entity.DogAge = model.DogAge; entity.DogImage = model.DogImage; entity.DogPrice = model.DogPrice; entity.ShelterId = model.ShelterId; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, DogEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.DogId != id) { ModelState.AddModelError("", "Id incorrect"); return(View(model)); } if (CreateDogService().UpdateDog(model)) { TempData["SaveResult"] = "Dog has been updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Error creating a Dog"); return(View(model)); }
//update dog public bool UpdateDog(DogEdit model) { Dog oldDog = GetDogById(model.DogId); if (oldDog != null) { oldDog.IsChipped = model.IsChipped; oldDog.EnergyLevel = model.EnergyLevel; oldDog.Size = model.Size; oldDog.Name = model.Name; oldDog.Breed = model.Breed; oldDog.Age = model.Age; oldDog.AboutMe = model.AboutMe; oldDog.ShelterId = model.ShelterId; return(_context.SaveChanges() == 1); } else { return(false); } }
public ActionResult Edit(int id, DogEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.DogId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = new DogService(); if (service.UpdateDog(model)) { TempData["SaveResult"] = "Your dog was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your dog could not be updated."); return(View(model)); }