Esempio n. 1
0
 public void Insert(TypeBindingModel model)
 {
     using (var context = new ComputingEquipmentDatabase())
     {
         context.Type.Add(CreateModel(model, new Models.Type()));
         context.SaveChanges();
     }
 }
Esempio 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);
        }
Esempio 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();
            }
        }
Esempio 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));
 }
Esempio 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("Тип не найден");
                }
            }
        }
Esempio 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());
            }
        }
Esempio 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);
            }
        }
Esempio 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);
            }
        }
Esempio n. 9
0
        private Models.Type CreateModel(TypeBindingModel model, Models.Type type)
        {
            type.Name = model.Name;

            return(type);
        }