Exemple #1
0
        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 ActionResult Edit(int id, int petId, PetVaccination model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                model.VaccinationId = id;
                model.Vaccination   = null;

                if (_context.PetVaccination.Any(pv => pv.VaccinationId == id && pv.PetId == petId))
                {
                    _context.PetVaccination.Attach(model);
                    _context.Entry(model).State = EntityState.Modified;
                }
                else
                {
                    _context.PetVaccination.Add(model);
                }

                _context.SaveChanges();

                var url = TempData["ReturnUrl"];
                if (null == url)
                {
                    return(RedirectToAction("Details", "Pet", new { id = petId }));
                }
                else
                {
                    return(Redirect(url.ToString()));
                }
            }
        }