コード例 #1
0
 public void Add(Breed breed)
 {
     using (var context = new LupiDbContext())
     {
         context.Breeds.Add(breed);
         context.SaveChanges();
     }
 }
コード例 #2
0
 // 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();
     }
 }
コード例 #3
0
 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);
     }
 }
コード例 #4
0
 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);
     }
 }