Ejemplo n.º 1
0
 public void Insert(TypeBindingModel model)
 {
     using (var context = new ComputingEquipmentDatabase())
     {
         context.Type.Add(CreateModel(model, new Models.Type()));
         context.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public void Delete(TypeBindingModel model)
        {
            var element = typeStorage.GetElement(new TypeBindingModel {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Элемент не найден");
            }
            typeStorage.Delete(model);
        }
Ejemplo n.º 3
0
        public void Update(TypeBindingModel model)
        {
            using (var context = new ComputingEquipmentDatabase())
            {
                var type = context.Type.FirstOrDefault(rec => rec.Id == model.Id);

                if (type == null)
                {
                    throw new Exception("Тип не найден");
                }
                CreateModel(model, type);
                context.SaveChanges();
            }
        }
Ejemplo n.º 4
0
 public List <TypeViewModel> Read(TypeBindingModel model)
 {
     if (model == null)
     {
         return(typeStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <TypeViewModel> {
             typeStorage.GetElement(model)
         });
     }
     return(typeStorage.GetFilteredList(model));
 }
Ejemplo n.º 5
0
        public void Delete(TypeBindingModel model)
        {
            using (var context = new ComputingEquipmentDatabase())
            {
                Models.Type type = context.Type.FirstOrDefault(rec => rec.Id == model.Id);

                if (type != null)
                {
                    context.Type.Remove(type);
                    context.SaveChanges();
                }
                else
                {
                    throw new Exception("Тип не найден");
                }
            }
        }
Ejemplo n.º 6
0
        public List <TypeViewModel> GetFilteredList(TypeBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new ComputingEquipmentDatabase())
            {
                return(context.Type
                       .Where(rec => rec.Name.Contains(model.Name))
                       .Select(rec => new TypeViewModel
                {
                    Id = rec.Id,
                    Name = rec.Name
                }).ToList());
            }
        }
Ejemplo n.º 7
0
        public TypeViewModel GetElement(TypeBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new ComputingEquipmentDatabase())
            {
                var type = context.Type
                           .FirstOrDefault(rec => rec.Id == model.Id);
                return(type != null ?
                       new TypeViewModel
                {
                    Id = type.Id,
                    Name = type.Name,
                } : null);
            }
        }
Ejemplo n.º 8
0
        public void CreateOrUpdate(TypeBindingModel model)
        {
            var element = typeStorage.GetElement(new TypeBindingModel {
                Name = model.Name
            });

            if (element != null && element.Id != model.Id)
            {
                throw new Exception("Уже есть тип с таким названием");
            }
            if (model.Id.HasValue)
            {
                typeStorage.Update(model);
            }
            else
            {
                typeStorage.Insert(model);
            }
        }
Ejemplo n.º 9
0
        private Models.Type CreateModel(TypeBindingModel model, Models.Type type)
        {
            type.Name = model.Name;

            return(type);
        }