示例#1
0
        public ActionResult Create([Bind(Include = "Id,SerialNum,AnimalCategory,AnimalName,BirthDate,Breed,OwnerName,OwnerStreet,OwnerState,OwnerZip,OwnerPhoneNum,PhotoUrl")] Pet pet)
        {
            if (ModelState.IsValid)
            {
                db.Pet.Add(pet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(pet));
        }
示例#2
0
        public ActionResult Create([Bind(Include = "ID,Name,Description,DateRecieved,Quantity,Price")] Pet pet)
        {
            if (ModelState.IsValid)
            {
                db.Pets.Add(pet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(pet));
        }
        public ActionResult Create([Bind(Include = "dId,dName")] Doctor doctor)
        {
            if (ModelState.IsValid)
            {
                db.Doctors.Add(doctor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(doctor));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "aNo,dId,cId,rNo,aDate")] Appointments appointments)
        {
            if (ModelState.IsValid)
            {
                db.Appointments.Add(appointments);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(appointments));
        }
        public ActionResult Create([Bind(Include = "rNo")] Room room)
        {
            if (ModelState.IsValid)
            {
                db.Rooms.Add(room);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(room));
        }
示例#6
0
        public ActionResult Create([Bind(Include = "cId,cName,cAddress")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
        public ActionResult Create(Pet pet)
        {
            if (ModelState.IsValid)
            {
                db.Pets.Add(pet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(pet));
        }
示例#8
0
        public IEnumerable <User> GetAll()
        {
            IEnumerable <User> userList = _context.Users.Include(u => u.Animals).ToList();

            bool modified = false;

            foreach (User user in userList)
            {
                foreach (Animal animal in user.Animals)
                {
                    // Update the effects of time before to return the animals of the user
                    if (animal.UpdateEffectsOfTime())
                    {
                        _context.Animals.Update(animal);
                        modified = true;
                    }
                }
            }
            if (modified)
            {
                _context.SaveChanges();
            }

            return(userList);
        }
示例#9
0
        public UsersController(PetDBContext context, AnimalsController animalsController)
        {
            _context           = context;
            _animalsController = animalsController;

            if (_context.Users.Count() == 0)
            {
                User newUser = new User {
                    Name = "Noah the Zookeeper"
                };
                _context.Users.Add(newUser);
                _context.SaveChanges();
                // Add one animal to the user
                AddAnimalToUser(newUser.Id);
            }
        }
示例#10
0
        public IActionResult Create([FromBody] Animal animal)
        {
            if (animal == null)
            {
                return(BadRequest());
            }

            _context.Animals.Add(animal);
            _context.SaveChanges();

            return(CreatedAtRoute("GetAnimals", new { id = animal.Id }, animal));
        }
示例#11
0
        public IHttpActionResult PostFoundPet(FoundPet foundPet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //Pet pet = db2.Pets.Find(foundPet.PetID);
            Pet pet = db2.Pets.Single(p => p.ID == foundPet.PetID);

            if (pet == null)
            {
                return(NotFound());
            }


            foundPet.FounderID = User.Identity.GetUserId();
            foundPet.FoundDate = DateTime.Now;
            db.FoundPets.Add(foundPet);

            db.SaveChanges();
            pet.FoundID = foundPet.ID;
            db2.SaveChanges();
            return(CreatedAtRoute("DefaultApi", new { id = foundPet.ID }, foundPet));
        }