public async Task <IActionResult> Edit(Owner model) { if (!ModelState.IsValid) { Veterinarian tempVet = new Veterinarian(); var veterinarians = await tempVet.GetVeterinarians(); ViewData["VetList"] = new SelectList(veterinarians, "VeterinarianId", "Name"); return(View(model)); } else { if (model.Phone != null) { model.Phone = model.Phone.Replace(" ", string.Empty).Replace("(", string.Empty).Replace(")", string.Empty).Replace("-", string.Empty).Replace(".", string.Empty); } if (model.CellPhone != null) { model.CellPhone = model.CellPhone.Replace(" ", string.Empty).Replace("(", string.Empty).Replace(")", string.Empty).Replace("-", string.Empty).Replace(".", string.Empty); } if (model.PostalCode != null) { model.PostalCode = model.PostalCode.Replace(" ", string.Empty).Replace("-", string.Empty); } _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("Details", new { @id = model.OwnerId })); } }
public async Task <IActionResult> Create() { Veterinarian tempVet = new Veterinarian(); var veterinarians = await tempVet.GetVeterinarians(); ViewData["VetList"] = new SelectList(veterinarians, "VeterinarianId", "Name"); return(View()); }
public async Task <IActionResult> Edit(int ownerId) { Veterinarian tempVet = new Veterinarian(); var veterinarians = await tempVet.GetVeterinarians(); ViewData["VetList"] = new SelectList(veterinarians, "VeterinarianId", "Name"); var model = _context.Owner.Where(o => o.OwnerId == ownerId).FirstOrDefault(); return(View(model)); }
public async Task <IActionResult> Create(Owner model) { if (!ModelState.IsValid) { Veterinarian tempVet = new Veterinarian(); var veterinarians = await tempVet.GetVeterinarians(); ViewData["VetList"] = new SelectList(veterinarians, "VeterinarianId", "Name"); return(View(model)); } else { if (model.Phone != null) { model.Phone = model.Phone.Replace(" ", string.Empty).Replace("(", string.Empty).Replace(")", string.Empty).Replace("-", string.Empty).Replace(".", string.Empty); } if (model.CellPhone != null) { model.CellPhone = model.CellPhone.Replace(" ", string.Empty).Replace("(", string.Empty).Replace(")", string.Empty).Replace("-", string.Empty).Replace(".", string.Empty); } if (model.PostalCode != null) { model.PostalCode = model.PostalCode.Replace(" ", string.Empty).Replace("-", string.Empty); } if (model.VeterinarianId != 0) { model.Veterinarian = null; } else { if (model.Veterinarian.Name == null) { model.Veterinarian = null; } model.VeterinarianId = null; } _context.Owner.Add(model); _context.SaveChanges(); return(RedirectToAction("Login", "Home")); } }