Ejemplo n.º 1
0
 private Work CreateModel(WorkBindingModel model, Work work)
 {
     work.WorkerId  = model.WorkerId;
     work.WorkName  = model.WorkName;
     work.WorkPrice = model.WorkPrice;
     return(work);
 }
Ejemplo n.º 2
0
 public void Insert(WorkBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         context.Works.Add(CreateModel(model, new Work()));
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        public void CreateWork(WorkBindingModel model)
        {
            var element = _workStorage.GetElement(new WorkBindingModel
            {
                WorkName = model.WorkName
            });

            _workStorage.Insert(model);
        }
Ejemplo n.º 4
0
 public void Update(WorkBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         var element = context.Works.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Такого ремонта нет");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 public WorkViewModel GetElement(WorkBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new CTODatabase())
     {
         var work = context.Works.Include(rec => rec.Worker)
                    .FirstOrDefault(rec => rec.Id == model.Id || rec.WorkName == model.WorkName);
         return(work != null?CreateViewModel(work) : null);
     }
 }
Ejemplo n.º 6
0
        public void Delete(WorkBindingModel model)
        {
            var element = _workStorage.GetElement(new WorkBindingModel
            {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Работа не найдена");
            }
            _workStorage.Delete(model);
        }
Ejemplo n.º 7
0
 public List <WorkViewModel> Read(WorkBindingModel model)
 {
     if (model == null)
     {
         return(_workStorage.GetFullList());
     }
     if (model.Id.HasValue || model.WorkName != null)
     {
         return(new List <WorkViewModel> {
             _workStorage.GetElement(model)
         });
     }
     return(_workStorage.GetFilteredList(model));
 }
Ejemplo n.º 8
0
 public void Delete(WorkBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         Work element = context.Works.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Works.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Такого ремонта нет");
         }
     }
 }
Ejemplo n.º 9
0
 public List <WorkViewModel> GetFilteredList(WorkBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new CTODatabase())
     {
         return(context.Works.Include(rec => rec.Worker)
                .Select(rec => new WorkViewModel
         {
             Id = rec.Id,
             WorkerId = rec.WorkerId,
             WorkName = rec.WorkName,
             WorkPrice = rec.WorkPrice
         })
                .ToList());
     }
 }
Ejemplo n.º 10
0
 public void DeleteWork(WorkBindingModel model) => _work.Delete(model);
Ejemplo n.º 11
0
 public void UpdateWork(WorkBindingModel model) => _work.UpdateWork(model);
Ejemplo n.º 12
0
 public void CreateWork(WorkBindingModel model) => _work.CreateWork(model);
Ejemplo n.º 13
0
 public void UpdateWork(WorkBindingModel model)
 {
     _workStorage.Update(model);
 }