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; } }
[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] 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(); } }
[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(); } }
[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 }
[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 }
[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 }