public IActionResult AddPet(int?id, [Bind("Name, Email, Phone, Password")] Owners owner) { PopulateOwners(id); PopulateAnimalTypes(); PopulateAnimalSubTypes(); if (owner == null) { throw new ArgumentNullException(nameof(owner)); } try { using (var context = new VetSystemContext()) { context.Owners.Add(owner); context.SaveChanges(); } } catch { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View()); }
public IActionResult EditPost(int?id, string name, string email, string phone) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var context = new VetSystemContext()) { var petOwner = context.Owners.Where(s => s.Id == id).FirstOrDefault(); if (petOwner == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { petOwner.Name = name; petOwner.Email = email; petOwner.Phone = phone; context.SaveChanges(); } catch { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } return(View(petOwner)); } }
public IActionResult Create([Bind("Name, Email, Phone, Password, AnimalType, AnimalSubType, AnimalName")] CreateOwnerModel customer) { CreateOwnerModel cm = new CreateOwnerModel(); if (customer == null) { throw new ArgumentNullException(nameof(customer)); } try { Owners o = new Owners(); o.Name = customer.Name; o.Password = customer.Password; o.Email = customer.Email; o.Phone = customer.Phone; using (var context = new VetSystemContext()) { context.Owners.Add(o); context.SaveChanges(); Pets pet = new Pets { Name = customer.AnimalName, OwnerId = o.Id, AnimalSubTypeId = int.Parse(customer.AnimalSubType), AnimalTypeId = int.Parse(customer.AnimalType) }; context.Pets.Add(pet); context.SaveChanges(); } } catch (Exception e) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(cm)); }