private Supply CreateModel(SupplyBindingModel model, Supply supply, MebelDatabase context) { supply.Date = model.Date; supply.Name = model.Name; supply.Price = model.Price; if (supply.Id == 0) { context.Supplys.Add(supply); context.SaveChanges(); } if (model.Id.HasValue) { var supplyMaterials = context.SupplyMaterials .Where(rec => rec.SupplyId == model.Id.Value) .ToList(); context.SupplyMaterials.RemoveRange(supplyMaterials.ToList()); context.SaveChanges(); } foreach (var supplyMaterial in model.SupplyMaterials) { context.SupplyMaterials.Add(new SupplyMaterial { SupplyId = supply.Id, MaterialId = supplyMaterial.Key, Count = supplyMaterial.Value.Item2 }); context.SaveChanges(); } return(supply); }
private Shipment CreateModel(ShipmentBindingModel model, Shipment shipment, MebelDatabase context) { shipment.Date = model.Date; shipment.Name = model.Name; shipment.Price = model.Price; if (shipment.Id == 0) { context.Shipments.Add(shipment); context.SaveChanges(); } if (model.Id.HasValue) { var shipmentGarnitures = context.ShipmentGarnitures .Where(rec => rec.ShipmentId == model.Id.Value) .ToList(); context.ShipmentGarnitures.RemoveRange(shipmentGarnitures.ToList()); context.SaveChanges(); } foreach (var shipmentGarniture in model.ShipmentGarnitures) { context.ShipmentGarnitures.Add(new ShipmentGarniture { ShipmentId = shipment.Id, GarnitureId = shipmentGarniture.Key, Count = shipmentGarniture.Value.Item2 }); context.SaveChanges(); } return(shipment); }
public void Update(SupplyBindingModel model) { using (var context = new MebelDatabase()) { using (var transaction = context.Database.BeginTransaction()) { try { var supply = context.Supplys.FirstOrDefault(rec => rec.Id == model.Id); if (supply == null) { throw new Exception("Поставка не найдена"); } CreateModel(model, supply, context); context.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
public void Update(ModuleBindingModel model) { using (var context = new MebelDatabase()) { using (var transaction = context.Database.BeginTransaction()) { try { var module = context.Modules.FirstOrDefault(rec => rec.Id == model.Id); if (module == null) { throw new Exception("Модуль не найден"); } CreateModel(model, module, context); context.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
public void Insert(MebelBindingModel model) { using (var context = new MebelDatabase()) { context.Mebel.Add(CreateModel(model, new Mebel())); context.SaveChanges(); } }
public List <ProviderViewModel> GetFullList() { using (var context = new MebelDatabase()) { return(context.Providers .Select(CreateModel).ToList()); } }
public void Insert(ProviderBindingModel model) { using (var context = new MebelDatabase()) { context.Providers.Add(CreateModel(model, new Provider())); context.SaveChanges(); } }
public List <ShipmentViewModel> GetFullList() { using (var context = new MebelDatabase()) { return(context.Shipments .Include(rec => rec.ShipmentGarnitures) .ThenInclude(rec => rec.Garniture) .Select(CreateModel) .ToList()); } }
public List <ModuleViewModel> GetFullList() { using (var context = new MebelDatabase()) { return(context.Modules .Include(rec => rec.ModuleMaterial) .Include(rec => rec.ModuleMebel) .Select(CreateModel) .ToList()); } }
public List <SupplyViewModel> GetFullList() { using (var context = new MebelDatabase()) { return(context.Supplys .Include(rec => rec.SupplyMaterials) .ThenInclude(rec => rec.Material) .Select(CreateModel) .ToList()); } }
public List <ProviderViewModel> GetFilteredList(ProviderBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { return(context.Providers .Where(rec => rec.FullName.Contains(model.FullName)) .Select(CreateModel).ToList()); } }
public void Update(MebelBindingModel model) { using (var context = new MebelDatabase()) { var element = context.Mebel.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Мебель не найдена"); } CreateModel(model, element); context.SaveChanges(); } }
public List <GarnitureViewModel> GetFullList() { using (var context = new MebelDatabase()) { return(context.Garniture .Include(rec => rec.GarnitureMaterial) .ThenInclude(rec => rec.Material) .Include(rec => rec.GarnitureMebel) .ThenInclude(rec => rec.Mebel) .Select(CreateModel) .ToList()); } }
public List <MebelViewModel> GetFullList() { using (var context = new MebelDatabase()) { return(context.Mebel .Select(rec => new MebelViewModel { Id = rec.Id, Name = rec.Name, Price = rec.Price }) .ToList()); } }
public ProviderViewModel GetElement(ProviderBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { var provider = context.Providers .FirstOrDefault(rec => rec.Id == model.Id || rec.FullName == model.FullName); return(provider != null? CreateModel(provider) : null); } }
public void Delete(ModuleBindingModel model) { using (var context = new MebelDatabase()) { var module = context.Modules.FirstOrDefault(rec => rec.Id == model.Id); if (module == null) { throw new Exception("Модуль не найден"); } context.Modules.Remove(module); context.SaveChanges(); } }
public List <SupplyViewModel> GetFilteredList(SupplyBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { return(context.Supplys .Include(rec => rec.SupplyMaterials) .ThenInclude(rec => rec.Material) .Where(rec => rec.Date >= model.DateFrom && rec.Date <= model.DateTo) .Select(CreateModel).ToList()); } }
public List <ShipmentViewModel> GetFilteredList(ShipmentBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { return(context.Shipments .Include(rec => rec.ShipmentGarnitures) .ThenInclude(rec => rec.Garniture) .Where(rec => rec.Date >= model.DateFrom && rec.Date <= model.DateTo) .Select(CreateModel).ToList()); } }
public SupplyViewModel GetElement(SupplyBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { var supply = context.Supplys .Include(rec => rec.SupplyMaterials) .ThenInclude(rec => rec.Material) .FirstOrDefault(rec => rec.Id == model.Id); return(supply != null? CreateModel(supply) : null); } }
public void Delete(ProviderBindingModel model) { using (var context = new MebelDatabase()) { Provider element = context.Providers.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Providers.Remove(element); context.SaveChanges(); } else { throw new Exception("Поставщик не найден"); } } }
public ShipmentViewModel GetElement(ShipmentBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { var shipment = context.Shipments .Include(rec => rec.ShipmentGarnitures) .ThenInclude(rec => rec.Garniture) .FirstOrDefault(rec => rec.Id == model.Id); return(shipment != null? CreateModel(shipment) : null); } }
public void Delete(MebelBindingModel model) { using (var context = new MebelDatabase()) { Mebel element = context.Mebel.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Mebel.Remove(element); context.SaveChanges(); } else { throw new Exception("Мебель не найдена"); } } }
public void Delete(ShipmentBindingModel model) { using (var context = new MebelDatabase()) { Shipment element = context.Shipments.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Shipments.Remove(element); context.SaveChanges(); } else { throw new Exception("Отгрузка не найдено"); } } }
public void Delete(SupplyBindingModel model) { using (var context = new MebelDatabase()) { Supply element = context.Supplys.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Supplys.Remove(element); context.SaveChanges(); } else { throw new Exception("Поступление не найдено"); } } }
public List <ModuleViewModel> GetFilteredList(ModuleBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { return(context.Modules .Include(rec => rec.ModuleMaterial) .Include(rec => rec.ModuleMebel) .Where(rec => rec.Id == model.Id) .Select(CreateModel) .ToList()); } }
public List <MebelViewModel> GetFilteredList(MebelBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { return(context.Mebel .Where(rec => rec.Name.Contains(model.Name)) .Select(rec => new MebelViewModel { Id = rec.Id, Name = rec.Name, Price = rec.Price }) .ToList()); } }
public void Insert(ModuleBindingModel model) { using (var context = new MebelDatabase()) { using (var transaction = context.Database.BeginTransaction()) { try { CreateModel(model, new Module(), context); context.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
public MebelViewModel GetElement(MebelBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { var component = context.Mebel .FirstOrDefault(rec => rec.Name == model.Name || rec.Id == model.Id); return(component != null ? new MebelViewModel { Id = component.Id, Name = component.Name, Price = component.Price } : null); } }
public ModuleViewModel GetElement(ModuleBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { var module = context.Modules .Include(rec => rec.ModuleMaterial) .ThenInclude(rec => rec.Material) .Include(rec => rec.ModuleMebel) .ThenInclude(rec => rec.Mebel) .FirstOrDefault(rec => rec.Id == model.Id); return(module != null? CreateModel(module) : null); } }