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

            return(type);
        }