コード例 #1
0
        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()));
                }
            }
        }
コード例 #2
0
        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"));
            }
        }
コード例 #3
0
        public IActionResult CheckIn(int id, IFormCollection form)
        {
            ViewBag.Vaccinations = _context.Vaccination.ToList();
            var checkedIds = form["VaccinationChecked"].ToList();

            List <PetVaccination> petVaccinations = new List <PetVaccination>();

            ViewBag.PetVaccinations = petVaccinations;

            bool allVaccines   = false;
            bool anyVacExpired = false;

            foreach (var vac in ViewBag.Vaccinations)
            {
                DateTime expiryDate;

                bool vaccinationChecked = checkedIds.Contains(vac.VaccinationId.ToString());

                if (DateTime.TryParse(form["Vaccination:" + vac.VaccinationId], out expiryDate))
                {
                    PetVaccination pv = new PetVaccination();
                    pv.VaccinationId      = vac.VaccinationId;
                    pv.ExpiryDate         = expiryDate;
                    pv.VaccinationChecked = vaccinationChecked;
                    petVaccinations.Add(pv);
                    if (expiryDate < DateTime.Today)
                    {
                        anyVacExpired = true;
                    }
                }
            }


            if (checkedIds.Count() >= 6)
            {
                allVaccines = true;
            }

            if (!allVaccines || anyVacExpired)
            {
                return(RedirectToAction("CheckIn", new { id = id }));
            }
            else
            {
                var petRes  = _context.PetReservation.Find(id);
                var res     = _context.Reservation.Find(petRes.ReservationId);
                var pet     = _context.Pet.Find(petRes.PetId);
                var petVacs = _context.PetVaccination.Where(x => x.PetId == pet.PetId).ToList();

                res.Status = 3;

                foreach (var singlePetVac in petVacs)
                {
                    singlePetVac.VaccinationChecked = true;
                    _context.PetVaccination.Update(singlePetVac);
                }
                _context.Reservation.Update(res);
                _context.Pet.Update(pet);
                _context.SaveChanges();
                return(RedirectToAction("Contract", new { id = id }));
            }
        }
コード例 #4
0
        public ActionResult Create(Pet model, int?ownerId, IFormCollection form)
        {
            int userId = Convert.ToInt32(User.Identity.Name);

            if (ownerId == null)
            {
                ownerId = userId;
            }

            if (!User.IsInRole("Clerk") && userId != ownerId)
            {
                return(Forbid());
            }

            ViewBag.Vaccinations = _context.Vaccination.ToList();
            ViewBag.Owner        = _context.Owner.Find(ownerId);

            model.OwnerId = ownerId.Value;

            var vaccinations = _context.Vaccination.ToList();

            ViewBag.Vaccinations = vaccinations;

            var checkedIds = form["VaccinationChecked"].ToList();

            List <PetVaccination> petVaccinations = new List <PetVaccination>();

            ViewBag.PetVaccinations = petVaccinations;


            foreach (var vac in vaccinations)
            {
                DateTime expiryDate;

                bool vaccinationChecked = checkedIds.Contains(vac.VaccinationId.ToString());

                if (DateTime.TryParse(form["Vaccination:" + vac.VaccinationId], out expiryDate))
                {
                    PetVaccination pv = new PetVaccination();
                    petVaccinations.Add(pv);
                    pv.VaccinationId      = vac.VaccinationId;
                    pv.ExpiryDate         = expiryDate;
                    pv.VaccinationChecked = vaccinationChecked;
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                try {
                    var owner = _context.Owner.Where(o => o.OwnerId == ownerId);
                    model.OwnerId = ownerId.Value;

                    _context.Pet.Add(model);
                    _context.SaveChanges();

                    foreach (var pv in petVaccinations)
                    {
                        pv.PetId = model.PetId;
                        _context.PetVaccination.Add(pv);
                    }

                    _context.SaveChanges();

                    return(RedirectToAction(nameof(Index)));
                } catch {
                    return(View(model));
                }
            }
        }
コード例 #5
0
        public IActionResult Create(int?id, PRSMR model, int?Pet_1, int?Pet_2, int?Pet_3)
        {
            var                   ownerId         = (int)HttpContext.Session.GetInt32("ownerId");
            List <int?>           petIds          = new List <int?>();
            List <PetReservation> petReservations = new List <PetReservation>();

            if (Pet_1 != null)
            {
                petIds.Add(Pet_1);
            }
            if (Pet_2 != null)
            {
                petIds.Add(Pet_2);
            }
            if (Pet_3 != null)
            {
                petIds.Add(Pet_3);
            }
            ViewData["Pets"] = _context.Pet.Where(p => p.OwnerId == ownerId).ToList();


            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                var         transaction = _context.Database.BeginTransaction();
                var         resId       = _context.Reservation.Max(p => p.ReservationId) + 1;
                Reservation res         = model.PetReservation.Reservation;
                res.ReservationId = resId;
                _context.Reservation.Add(res);
                _context.Database.ExecuteSqlInterpolated($"USE HVK_ZZTop SET IDENTITY_INSERT dbo.Reservation ON;");
                _context.SaveChanges();
                _context.Database.ExecuteSqlInterpolated($"USE HVK_ZZTop SET IDENTITY_INSERT dbo.Reservation OFF;");
                foreach (int petid in petIds)
                {
                    PetReservation petRes = new PetReservation();

                    var petResId = _context.PetReservation.Max(p => p.PetReservationId) + 1;

                    petRes.ReservationId = resId;

                    petRes.PetId = petid;

                    petRes.PetReservationId = petResId;


                    petRes.PetReservationService.Add(new PetReservationService {
                        ServiceId = 1
                    });

                    if (model.Walk)
                    {
                        petRes.PetReservationService.Add(new PetReservationService {
                            ServiceId = 2
                        });
                    }

                    if (model.PlayTime)
                    {
                        petRes.PetReservationService.Add(new PetReservationService {
                            ServiceId = 5
                        });
                    }

                    if (model.Medication.Name != null)
                    {
                        var medId = _context.Medication.Max(p => p.MedicationId) + 1;
                        petRes.PetReservationService.Add(new PetReservationService {
                            ServiceId = 4
                        });
                        model.Medication.MedicationId = medId;
                        _context.Medication.Add(model.Medication);
                        _context.Database.ExecuteSqlInterpolated($"USE HVK_ZZTop SET IDENTITY_INSERT dbo.Medication ON;");
                        _context.SaveChanges();
                        _context.Database.ExecuteSqlInterpolated($"USE HVK_ZZTop SET IDENTITY_INSERT dbo.Medication OFF;");
                    }
                    _context.PetReservation.Add(petRes);
                    _context.Database.ExecuteSqlInterpolated($"USE HVK_ZZTop SET IDENTITY_INSERT dbo.PetReservation ON;");
                    _context.SaveChanges();
                    _context.Database.ExecuteSqlInterpolated($"USE HVK_ZZTop SET IDENTITY_INSERT dbo.PetReservation OFF");
                }
                transaction.Commit();

                return(RedirectToAction(nameof(Index)));
            }
        }