Пример #1
0
 public void Insert(FirmBM model)
 {
     using (var context = new DataBaseContext())
     {
         context.Firms.Add(CreateModel(model, new Firm()));
         context.SaveChanges();
     }
 }
Пример #2
0
 public void Update(FirmBM model)
 {
     using (var context = new DataBaseContext())
     {
         var element = context.Firms.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Фирма не найдена");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
Пример #3
0
 public List <FirmVM> GetFilteredList(FirmBM model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new DataBaseContext())
     {
         return(context.Firms
                .Where(rec => rec.Name == model.Name)
                .Select(CreateModel).ToList());
     }
 }
Пример #4
0
 public FirmVM GetElement(FirmBM model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new DataBaseContext())
     {
         var firm = context.Firms
                    .FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name);
         return(firm != null?
                CreateModel(firm) : null);
     }
 }
Пример #5
0
 public void Delete(FirmBM model)
 {
     using (var context = new DataBaseContext())
     {
         Firm element = context.Firms.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Firms.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Фирма не найдена");
         }
     }
 }
Пример #6
0
 private Firm CreateModel(FirmBM model, Firm firm)
 {
     firm.Name    = model.Name;
     firm.Address = model.Address;
     return(firm);
 }