private Halt CreateModel(HaltBindingModel model, Halt halt)
 {
     halt.Name = model.Name;
     halt.Address = model.Address;
     halt.OperatorID = model.OperatorID;
     return halt;
 }
 public void Insert(HaltBindingModel model)
 {
     using (var context = new TourFirmDatabase())
     {
         context.Halts.Add(CreateModel(model, new Halt()));
         context.SaveChanges();
     }
 }
Exemple #3
0
        public void Delete(HaltBindingModel model)
        {
            var element = _haltStorage.GetElement(new HaltBindingModel {
                ID = model.ID
            });

            if (element == null)
            {
                throw new Exception("Элемент не найден");
            }
            _haltStorage.Delete(model);
        }
        public void Update(HaltBindingModel model)
        {
            using (var context = new TourFirmDatabase())
            {
                var element = context.Halts.FirstOrDefault(rec => rec.ID == model.ID);

                if (element == null)
                {
                    throw new Exception("Элемент не найден");
                }
                CreateModel(model, element);
                context.SaveChanges();
            }
        }
Exemple #5
0
 public List <HaltViewModel> Read(HaltBindingModel model)
 {
     if (model == null)
     {
         return(_haltStorage.GetFullList());
     }
     if (model.ID.HasValue || model.Name != null)
     {
         return(new List <HaltViewModel> {
             _haltStorage.GetElement(model)
         });
     }
     return(_haltStorage.GetFilteredList(model));
 }
        public void Delete(HaltBindingModel model)
        {
            using (var context = new TourFirmDatabase())
            {
                Halt element = context.Halts.FirstOrDefault(rec => rec.ID == model.ID);

                if (element != null)
                {
                    context.Halts.Remove(element);
                    context.SaveChanges();
                }
                else
                {
                    throw new Exception("Элемент не найден");
                }
            }
        }
 public HaltViewModel GetElement(HaltBindingModel model)
 {
     if (model == null)
     {
         return null;
     }
     using (var context = new TourFirmDatabase())
     {
         var halt = context.Halts.FirstOrDefault(rec => rec.Name == model.Name || rec.ID == model.ID);
         return halt != null ? new HaltViewModel
         {
             ID = halt.ID,
             Name = halt.Name,
             Address = halt.Address,
             OperatorID = halt.OperatorID
         } :
         null;
     }
 }
Exemple #8
0
        public void CreateOrUpdate(HaltBindingModel model)
        {
            var element = _haltStorage.GetElement(new HaltBindingModel
            {
                Name = model.Name
            });

            if (element != null && element.ID != model.ID)
            {
                throw new Exception("Данная остановка уже зарегистрирована");
            }
            if (model.ID.HasValue)
            {
                _haltStorage.Update(model);
            }
            else
            {
                _haltStorage.Insert(model);
            }
        }
        public List<HaltViewModel> GetFilteredList(HaltBindingModel model)
        {
            if (model == null)
            {
                return null;
            }

            using (var context = new TourFirmDatabase())
            {
                return context.Halts
                    .Where(rec => (rec.OperatorID == model.OperatorID))
                    .ToList().
                    Select(rec => new HaltViewModel
                    {
                        ID = rec.ID,
                        Name = rec.Name,
                        Address = rec.Address,
                        OperatorID = rec.OperatorID
                    }).ToList();
            }
        }