public Breed GetByID(Guid id)
 {
     using (var context = new LupiDbContext())
     {
         return(context.Breeds.FirstOrDefault(p => p.Id == id));
     }
 }
Beispiel #2
0
 public IEnumerable <Breed> GetAll()
 {
     using (var context = new LupiDbContext())
     {
         return(context.Breeds);
     }
 }
 public void Add(Breed breed)
 {
     using (var context = new LupiDbContext())
     {
         context.Breeds.Add(breed);
         context.SaveChanges();
     }
 }
 public IEnumerable <Breed> GetAll()
 {
     using (var context = new LupiDbContext())
     {
         List <Breed> breeds = context.Breeds.ToList();
         return(breeds);
     }
 }
 // POST: api/Breeds
 public void Post([FromBody] Breed breed)
 {
     using (LupiDbContext context = new LupiDbContext())
     {
         Guid breedId = Guid.NewGuid();
         breed.Id = breedId;
         context.Breeds.Add(breed);
         context.SaveChanges();
     }
 }
 // GET: api/Breeds/5
 public HttpResponseMessage Get(Guid id)
 {
     using (LupiDbContext context = new LupiDbContext())
     {
         Breed breed = context.Breeds.Find(id);
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, breed);
         response.Headers.CacheControl = new CacheControlHeaderValue()
         {
             MaxAge = TimeSpan.FromMinutes(20)
         };
         return(response);
     }
 }
 // GET: api/Breeds
 public HttpResponseMessage Get()
 {
     using (LupiDbContext context = new LupiDbContext())
     {
         IEnumerable <Breed> breeds   = context.Breeds.ToList();
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, breeds);
         response.Headers.CacheControl = new CacheControlHeaderValue()
         {
             MaxAge = TimeSpan.FromMinutes(20)
         };
         return(response);
     }
 }
 public bool DeleteById(Guid id)
 {
     using (var context = new LupiDbContext())
     {
         Breed breed = context.Breeds.FirstOrDefault(p => p.Id == id);
         if (breed == null)
         {
             return(false);
         }
         context.Breeds.Remove(breed);
         context.SaveChanges();
         return(true);
     }
 }
 public bool Update(Guid id, Breed newBreed)
 {
     using (var context = new LupiDbContext())
     {
         Breed originalBreed = context.Breeds.FirstOrDefault(p => p.Id == id);
         if (originalBreed == null)
         {
             return(false);
         }
         originalBreed.HairColors = newBreed.HairColors;
         originalBreed.HairType   = newBreed.HairType;
         originalBreed.Name       = newBreed.Name;
         context.SaveChanges();
         return(true);
     }
 }