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); }
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); }
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 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 Insert(MebelBindingModel model) { using (var context = new MebelDatabase()) { context.Mebel.Add(CreateModel(model, new Mebel())); context.SaveChanges(); } }
public void Insert(ProviderBindingModel model) { using (var context = new MebelDatabase()) { context.Providers.Add(CreateModel(model, new Provider())); context.SaveChanges(); } }
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 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 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 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(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 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 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; } } } }