Example #1
0
        [Route("{key}")] //<--key == petId
        public ActionResult PutEdit(int key, [FromBody] Pets pet)
        {
            pethouseContext db = new pethouseContext();

            try
            {
                Pets petDb = db.Pets.Find(key);
                if (pet != null)
                {
                    petDb.Petname   = pet.Petname;
                    petDb.Birthdate = pet.Birthdate;
                    petDb.Photo     = pet.Photo;
                    petDb.User      = pet.User;
                    petDb.RaceId    = pet.RaceId;
                    petDb.BreedId   = pet.BreedId;
                    db.SaveChanges();

                    return(Ok(petDb.PetId));
                }
                else
                {
                    return(NotFound("No such ID in pets"));
                }
            }
            catch (Exception)
            {
                return(BadRequest("Error"));
            }
            finally
            {
                db.Dispose();
            }
        }
        [Route("{Key}")] //<--key == petId
        public ActionResult PutEdit(int key, [FromBody] Medications med)
        {
            pethouseContext db = new pethouseContext();

            try
            {
                Medications medDb = db.Medications.Find(key);
                if (med != null)
                {
                    medDb.Medname    = med.Medname;
                    medDb.MedDate    = med.MedDate;
                    medDb.MedExpDate = med.MedExpDate;
                    db.SaveChanges();

                    return(Ok(medDb.MedId));
                }
                else
                {
                    return(NotFound("Not found"));
                }
            }
            catch (Exception)
            {
                return(BadRequest("Error"));
            }
            finally
            {
                db.Dispose();
            }
        }
Example #3
0
        //Hae yksi lemmikki lemmikki id:n perusteella
        public Pets GetOnePetbyId(int key)
        {
            pethouseContext db  = new pethouseContext();
            Pets            pet = db.Find <Pets>(key);

            return(pet);
        }
Example #4
0
        [Route("{Key}")] //<--key == petId
        public ActionResult PutEdit(int key, [FromBody] Grooming gro)
        {
            pethouseContext db = new pethouseContext();

            try
            {
                Grooming groDb = db.Grooming.Find(key);
                if (gro != null)
                {
                    groDb.Groomname    = gro.Groomname;
                    groDb.GroomDate    = gro.GroomDate;
                    groDb.GroomExpDate = gro.GroomExpDate;
                    groDb.Comments     = gro.Comments;
                    db.SaveChanges();

                    return(Ok(groDb.GroomId));
                }
                else
                {
                    return(NotFound("Not found"));
                }
            }
            catch (Exception)
            {
                return(BadRequest("Error"));
            }
            finally
            {
                db.Dispose();
            }
        }
Example #5
0
        //Hae yksi rotu
        public Breeds GetOneBreed(int key)
        {
            pethouseContext db    = new pethouseContext();
            Breeds          breed = db.Find <Breeds>(key);

            return(breed);
        }
Example #6
0
        public List <Races> GetAllRaces()
        {
            pethouseContext context = new pethouseContext();
            List <Races>    races   = context.Races.ToList();

            return(races);
        }
Example #7
0
        public List <Breeds> GetAllBreeds()
        {
            pethouseContext context = new pethouseContext();
            List <Breeds>   breeds  = context.Breeds.ToList();

            return(breeds);
        }
        public Users PostStatus(LoginModel input)
        {
            try
            {
                var             userName = input.userName;
                var             passWord = input.passWord;
                pethouseContext context  = new pethouseContext();
                var             user     = (from u in context.Users
                                            where (u.Username == userName) && (u.Password == passWord)
                                            select u).FirstOrDefault();

                if (user == null)
                {
                    context.Dispose();
                    return(null);
                }

                context.Dispose();
                return(user);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
        public ActionResult PostCreateNew([FromBody] Users user)
        {
            pethouseContext db = new pethouseContext(); //Tietokanta yhteytden muodostus

            try
            {
                var exists = (from p in db.Users
                              where p.Username == user.Username
                              select p).Count();
                if (exists > 0)
                {
                    return(BadRequest(false));
                }
                else
                {
                    db.Users.Add(user);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Jokin meni pieleen asiakasta lisättäessä.\nOta yhteyttä Guruun!\n" + ex.ToString()));
            }
            db.Dispose();            //Tietokannan vapautus
            return(Ok(user.UserId)); //Palauttaa vastaluodun uuden lemmikin avainarvon
        }
Example #10
0
        [Route("{Key}")] //<--key == petId
        public ActionResult PutEdit(int key, [FromBody] Vaccines vac)
        {
            pethouseContext db = new pethouseContext();

            try
            {
                Vaccines vacDb = db.Vaccines.Find(key);
                if (vac != null)
                {
                    vacDb.Vacname    = vac.Vacname;
                    vacDb.VacDate    = vac.VacDate;
                    vacDb.VacExpDate = vac.VacExpDate;
                    db.SaveChanges();

                    return(Ok(vacDb.VacId));
                }
                else
                {
                    return(NotFound("Not found"));
                }
            }
            catch (Exception)
            {
                return(BadRequest("Error"));
            }
            finally
            {
                db.Dispose();
            }
        }
Example #11
0
        //Hae kaikki lemmikit käyttäjä id:n perusteella
        public List <Pets> GetAllPetsByUser(int key)
        {
            pethouseContext db   = new pethouseContext();
            List <Pets>     pets = (from p in db.Pets
                                    where p.UserId == key
                                    select p).ToList();

            return(pets);
        }
        public List <Medications> GetAllMedicationsList(int key)
        {
            pethouseContext db           = new pethouseContext();
            var             mediacations = (from p in db.Medications
                                            where p.PetId == key
                                            orderby p.MedDate descending
                                            select p).ToList();

            return(mediacations);
        }
Example #13
0
        //Hae kaikki Rokotukset
        public List <Vaccines> GetAllVaccinesList(int key)
        {
            pethouseContext db       = new pethouseContext();
            var             vaccines = (from p in db.Vaccines
                                        where p.PetId == key
                                        orderby p.VacDate descending
                                        select p).ToList();

            return(vaccines);
        }
Example #14
0
        public List <Grooming> GetAllGroomingList(int key)
        {
            pethouseContext db       = new pethouseContext();
            var             grooming = (from p in db.Grooming
                                        where p.PetId == key
                                        orderby p.GroomDate descending
                                        select p).ToList();

            return(grooming);
        }
Example #15
0
        [Route("user/")] // <-- Routen placeholder
        public ActionResult PostCreateNew([FromBody] Pets pet)
        {
            pethouseContext db = new pethouseContext(); //Tietokanta yhteytden muodostus

            try
            {
                db.Pets.Add(pet);
                db.SaveChanges();
            }
            catch (Exception)
            {
                return(BadRequest("Jokin meni pieleen asiakasta lisättäessä.\nOta yhteyttä Guruun!"));
            }
            db.Dispose();          //Tietokannan vapautus
            return(Ok(pet.PetId)); //Palauttaa vastaluodun uuden lemmikin avainarvon
        }
Example #16
0
        //Hae kaikki Rokotukset
        public int GetAllVaccines(int key)
        {
            pethouseContext db       = new pethouseContext();
            var             vaccines = (from p in db.Vaccines
                                        where p.PetId == key
                                        orderby p.VacDate descending
                                        select p).Count();

            if (vaccines != 0)
            {
                return(vaccines);
            }
            else
            {
                return(0);
            }
        }
Example #17
0
        //Get the latest grooming operation
        public Grooming GetTheLatestGrooming(int key)
        {
            pethouseContext db       = new pethouseContext();
            Grooming        grooming = (from p in db.Grooming
                                        where p.PetId == key
                                        orderby p.GroomDate descending
                                        select p).FirstOrDefault();

            if (grooming != null)
            {
                return(grooming);
            }
            else
            {
                return(null);
            }
        }
Example #18
0
        [HttpPost] //<-- filtteri, joka sallii vain POST-metodit
        //[Route("")]// <-- Routen placeholder
        public ActionResult PostCreateNew([FromBody] Vaccines vac)
        {
            pethouseContext db = new pethouseContext(); //Tietokanta yhteytden muodostus

            try
            {
                db.Vaccines.Add(vac);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                string virhe = ex.GetType().Name.ToString() + ": " + ex.Message.ToString();
                return(BadRequest("Jokin meni pieleen asiakasta lisättäessä.\nOta yhteyttä Guruun!\n" + virhe));
            }
            db.Dispose();          //Tietokannan vapautus
            return(Ok(vac.PetId)); //Palauttaa vastaluodun uuden objektin avainarvon
        }
        public Medications GetTheLatestMedication(int key)
        {
            pethouseContext db          = new pethouseContext();
            Medications     medications = (from p in db.Medications
                                           where p.PetId == key
                                           orderby p.MedDate descending
                                           select p).FirstOrDefault();

            if (medications != null)
            {
                return(medications);
            }
            else
            {
                return(null);
            }
        }
Example #20
0
        //Hae kaikki Rokotukset
        public Vaccines GetTheLatestVaccine(int key)
        {
            pethouseContext db       = new pethouseContext();
            Vaccines        vaccines = (from p in db.Vaccines
                                        where p.PetId == key
                                        orderby p.VacDate descending
                                        select p).FirstOrDefault();

            if (vaccines != null)
            {
                return(vaccines);
            }
            else
            {
                return(null);
            }
        }
Example #21
0
        //Get the ammount of grooming items
        public int GetAllGrooming(int key)
        {
            pethouseContext db       = new pethouseContext();
            var             grooming = (from p in db.Grooming
                                        where p.PetId == key
                                        orderby p.GroomDate descending
                                        select p).Count();

            if (grooming != 0)
            {
                return(grooming);
            }
            else
            {
                return(0);
            }
        }
Example #22
0
        [HttpPost] //<-- filtteri, joka sallii vain POST-metodit
        //[Route("")]// <-- Routen placeholder
        public ActionResult PostCreateNew([FromBody] Grooming grooming)
        {
            pethouseContext db = new pethouseContext(); //Tietokanta yhteytden muodostus

            try
            {
                db.Grooming.Add(grooming);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                string virhe = ex.GetType().Name.ToString() + ": " + ex.Message.ToString();
                return(BadRequest("Request failed with error:\n" + virhe));
            }
            db.Dispose();               //Tietokannan vapautus
            return(Ok(grooming.PetId)); //Palauttaa vastaluodun uuden objektin avainarvon
        }
        public int GetAllMedications(int key)
        {
            pethouseContext db          = new pethouseContext();
            var             medications = (from p in db.Medications
                                           where p.PetId == key
                                           orderby p.MedDate descending
                                           select p).Count();

            if (medications != 0)
            {
                return(medications);
            }
            else
            {
                return(0);
            }
        }
Example #24
0
        public ActionResult DeleteVaccine(int?key)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            pethouseContext db = new pethouseContext();

            try
            { Vaccines vaccine = db.Vaccines.Find(key);
              db.Remove(vaccine);
              db.SaveChanges(); }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            return(Ok());
        }
Example #25
0
        public ActionResult DeleteGrooming(int?key)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            pethouseContext db = new pethouseContext();

            try
            {
                Grooming grooming = db.Grooming.Find(key);
                db.Remove(grooming);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            return(Ok());
        }
Example #26
0
        public ActionResult DeleteAllVaccines(int?key)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            pethouseContext db = new pethouseContext();

            try
            {
                Vaccines vaccineRow = db.Vaccines.Where(s => s.PetId == key).FirstOrDefault();
                db.Remove(vaccineRow);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            return(Ok());
        }
Example #27
0
        public ActionResult DeleteOnePet(int?key)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            pethouseContext db  = new pethouseContext();
            Pets            pet = db.Pets.Find(key);

            try
            {
                if (pet != null)
                {
                    db.Pets.Remove(pet);
                    db.SaveChanges();
                    return(Ok("Pet " + key + " removed"));
                }
                else
                {
                    return(NotFound("Pet " + key + " not found."));
                }
            }catch (Exception ex) { return(BadRequest(ex.ToString())); }
        }