Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. class AccountTypeDao : IAccountTypeDao
  2.     {
  3.         public void Delete(long id)
  4.         {
  5.             var context = new AutoServiceShopContext();
  6.  
  7.             var user = context.AccountTypees.Where(x => x.Id == id).First();
  8.  
  9.             context.AccountTypees.Remove(user);
  10.             context.SaveChanges();
  11.         }
  12.  
  13.         public void Delete(Data.Entity.AccountType entity)
  14.         {
  15.             var context = new AutoServiceShopContext();
  16.  
  17.             context.AccountTypees.Remove(entity);
  18.             context.SaveChanges();
  19.         }
  20.  
  21.         public void Delete(List<long> idList)
  22.         {
  23.             idList.ForEach(x => Delete(x));
  24.         }
  25.  
  26.         public List<Data.Entity.AccountType> Find()
  27.         {
  28.             var context = new AutoServiceShopContext();
  29.  
  30.             return context.AccountTypees.ToList();
  31.         }
  32.  
  33.         public Data.Entity.AccountType Find(long id)
  34.         {
  35.             var context = new AutoServiceShopContext();
  36.             return context.AccountTypees
  37.                 .Where(x => x.Id.Equals(id))
  38.                 .Single();
  39.         }
  40.  
  41.         public List<Data.Entity.AccountType> FindByField(string field, string value)
  42.         {
  43.             var context = new AutoServiceShopContext();
  44.  
  45.             return context.AccountTypees.Where
  46.                 (entity => entity.GetType().GetProperty(field).GetValue(entity, null).ToString().Equals(value)).ToList();
  47.         }
  48.  
  49.         public Data.Entity.AccountType Save(Data.Entity.AccountType entity)
  50.         {
  51.             var context = new AutoServiceShopContext();
  52.  
  53.             context.AccountTypees.Add(entity);
  54.             context.SaveChanges();
  55.  
  56.             return entity;
  57.         }
  58.  
  59.         public List<Data.Entity.AccountType> Save(List<Data.Entity.AccountType> entity)
  60.         {
  61.             var context = new AutoServiceShopContext();
  62.  
  63.             entity.ForEach(x => context.AccountTypees.Add(x));
  64.  
  65.             context.SaveChanges();
  66.  
  67.             return entity;
  68.         }
  69.  
  70.         public Data.Entity.AccountType Update(Data.Entity.AccountType entity)
  71.         {
  72.             Delete(entity.Id);
  73.             Save(entity);
  74.             return entity;
  75.         }
  76.  
  77.         public List<Data.Entity.AccountType> Update(List<Data.Entity.AccountType> entity)
  78.         {
  79.             entity.ForEach(x => Update(x));
  80.             return entity;
  81.         }
  82.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement