示例#1
0
 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));
     }
 }
示例#2
0
        private void PopulateOwners(int?id)
        {
            var context  = new VetSystemContext();
            var petOwner = context.Owners.Where(s => s.Id == id);

            ViewBag.OwnerId = new SelectList(petOwner, "Id", "Name");
        }
示例#3
0
        private void PopulateAnimalTypes()
        {
            var context        = new VetSystemContext();
            var animalSubTypes = context.AnimalTypes.Where(s => s.Name != null);

            ViewBag.AnimalTypeId = new SelectList(animalSubTypes, "Id", "Name");
        }
示例#4
0
        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());
        }
示例#5
0
        public IActionResult Details(int?id)
        {
            List <DoctorSpecialties> doctorSpecialties = new List <DoctorSpecialties>();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            using (var context = new VetSystemContext())
            {
                var doc = context.Doctors.Where(s => s.Id == id).FirstOrDefault();
                if (doc == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                var departments = context.DoctorSpecialtiesDoctors.Where(x => x.DoctorId == id);

                foreach (var item in departments)
                {
                    var findName = context.DoctorSpecialties.Where(x => x.Id == item.DoctorSpecialtiesId).FirstOrDefault();
                    doctorSpecialties.Add(findName);
                }



                DoctorDetailsModel ddm = new DoctorDetailsModel
                {
                    Name        = doc.Name,
                    Departments = doctorSpecialties
                };
                return(View(ddm));
            }
        }
示例#6
0
        public IActionResult About()
        {
            using (var context = new VetSystemContext())
            {
            }

            ViewData["Message"] = "Your application description page.";

            return(View());
        }
示例#7
0
        public IEnumerable <SelectListItem> GetAllAnimalTypes()
        {
            var context     = new VetSystemContext();
            var AnimalTypes = context.AnimalTypes.Where(x => x.Name != null);

            foreach (var item in AnimalTypes)
            {
                yield return(new SelectListItem {
                    Text = item.Name, Value = item.Id.ToString()
                });
            }
        }
示例#8
0
        public JsonResult AnimalList(int id)
        {
            var context = new VetSystemContext();
            List <SelectListItem> li = new List <SelectListItem>();
            var test = context.AnimalTypes.Where(x => x.Id == id).ToList();

            foreach (var item in test)
            {
                li.Add(new SelectListItem {
                    Text = item.Name, Value = item.Id.ToString()
                });
            }
            return(Json(li));
        }
示例#9
0
        public IActionResult Create()
        {
            CreateOwnerModel cm      = new CreateOwnerModel();
            var context              = new VetSystemContext();
            List <SelectListItem> li = new List <SelectListItem>();
            var test = context.AnimalTypes.Where(x => x.Id != null).ToList();

            foreach (var item in test)
            {
                li.Add(new SelectListItem {
                    Text = item.Name, Value = item.Id.ToString()
                });
            }
            ViewData["animalTypes"] = li;
            return(View(cm));
        }
示例#10
0
 public IActionResult Edit(int?id)
 {
     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));
         }
         return(View(petOwner));
     }
 }
示例#11
0
        // GET: /<controller>/
        public IActionResult Index(string searchString, string phoneFilter, string emailFilter)
        {
            ViewBag.CurrentFilter = searchString;
            ViewBag.PhoneFilter   = phoneFilter;
            ViewBag.EmailFilter   = emailFilter;


            using (var context = new VetSystemContext())
            {
                var petOwner = context.Owners.Where(s => s.Name != null);

                if (!String.IsNullOrEmpty(searchString) || !String.IsNullOrEmpty(phoneFilter) || !String.IsNullOrEmpty(emailFilter))
                {
                    petOwner = context.Owners.Where(s => s.Name == searchString || s.Phone == phoneFilter || s.Email == emailFilter);
                }
                return(View(petOwner.ToPagedList(1, 100)));
            }
        }
示例#12
0
        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));
        }
示例#13
0
        public IActionResult Details(int?id)
        {
            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));
                }
                var pets = context.Pets.Where(p => p.OwnerId == id).ToList();

                PetOwnerModel pom = new PetOwnerModel
                {
                    Name = petOwner.Name,
                    Pets = pets
                };
                return(View(pom));
            }
        }