public void Insert(TypeBindingModel model) { using (var context = new ComputingEquipmentDatabase()) { context.Type.Add(CreateModel(model, new Models.Type())); context.SaveChanges(); } }
public void Delete(TypeBindingModel model) { var element = typeStorage.GetElement(new TypeBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Элемент не найден"); } typeStorage.Delete(model); }
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(); } }
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)); }
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("Тип не найден"); } } }
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()); } }
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); } }
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); } }
private Models.Type CreateModel(TypeBindingModel model, Models.Type type) { type.Name = model.Name; return(type); }