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();
            }
        }
Example #2
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 #3
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();
            }
        }
        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
        }
        [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 #6
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 #7
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
        }
Example #8
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
        }
Example #9
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 #10
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 #11
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 #12
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())); }
        }