Beispiel #1
0
 public static Person GetItemById(int id)
 {
     using (PitmanContext context = new PitmanContext())
     {
         return context.Persons.FirstOrDefault(o => o.Id == id);
     }
 }
Beispiel #2
0
 public static List<Person> GetAllItems()
 {
     using (PitmanContext context = new PitmanContext())
     {
         return context.Persons.OrderByDescending(o => o.Id).ToList();
     }
 }
Beispiel #3
0
 public static bool DeleteItem(int id)
 {
     using (PitmanContext context = new PitmanContext())
     {
         Person entity = context.Persons.FirstOrDefault(o => o.Id == id);
         if (entity != null)
         {
             context.Entry(entity).State = EntityState.Deleted;
             return context.SaveChanges() > 0;
         }
     }
     return false;
 }
Beispiel #4
0
 public static bool AddOrUpdate(Person model)
 {
     using (PitmanContext context = new PitmanContext())
     {
         if (model.Id > 0)
         {
             context.Persons.Attach(model);
             context.Entry(model).State = EntityState.Modified;
             return context.SaveChanges() > 0;
         }
         else
         {
             context.Persons.Add(model);
             return context.SaveChanges() > 0;
         }
     }
 }