public void AddNewSupplier(Supplier supplier) { if (supplier == null) { throw new ArgumentNullException("supplier"); } if (string.IsNullOrWhiteSpace(supplier.Name)) { throw new Exception("Invalid supplier name!!!"); } supplier.Name = supplier.Name.Trim().Sanitise(); using (var context = new DataManagementContext()) { if (context.Partners.Any(m => m.Name == supplier.Name)) { throw new Exception("A supplier with the supplied name already exists."); } var newSupplier = new Models.Business.Partner { Name = supplier.Name }; var supplierPartnerType = new Models.Business.PartnerType { Partner = newSupplier, PartnerTypeCode = SupplierPartnerType }; context.Partners.Add(newSupplier); context.PartnerTypes.Add(supplierPartnerType); context.SaveChanges(); } }
public void RemoveSupplier(Supplier supplier) { if (supplier == null) { throw new ArgumentNullException("supplier"); } if (string.IsNullOrWhiteSpace(supplier.Name) || string.IsNullOrWhiteSpace(supplier.Name.Sanitise())) { throw new Exception("Invalid Supplier name!!!"); } supplier.Name = supplier.Name.Trim().Sanitise(); using (var context = new DataManagementContext()) { var selectedSupplier = context.Partners.SingleOrDefault(m => m.PartnerID == supplier.SupplierID); if (selectedSupplier == null) { throw new Exception("The Supplier record was not found in the database"); } try { context.Partners.Remove(selectedSupplier); context.SaveChanges(); } catch (Exception) { throw new Exception("Could not remove the selected supplier because it has associated Products."); } } }
public void RenameSupplier(Supplier supplier, string newName) { if (supplier == null) { throw new ArgumentNullException("supplier"); } if (string.IsNullOrWhiteSpace(supplier.Name) || string.IsNullOrWhiteSpace(supplier.Name.Sanitise().Trim())) { throw new Exception("Invalid Supplier name!!!"); } supplier.Name = supplier.Name.Sanitise().Trim(); using (var context = new DataManagementContext()) { var selectedSupplier = context.Partners.SingleOrDefault(m => m.PartnerID == supplier.SupplierID); if (selectedSupplier == null) { throw new Exception("The Supplier record was not found in the database."); } if (selectedSupplier.Name == newName) { return; } selectedSupplier.Name = newName; context.SaveChanges(); } }
public void AddNewManufacturer(Manufacturer manufacturer) { if (manufacturer == null) { throw new ArgumentNullException("manufacturer"); } if (string.IsNullOrWhiteSpace(manufacturer.Name)) { throw new Exception("Invalid Manufacturer name!!!"); } manufacturer.Name = manufacturer.Name.Trim().Sanitise(); using (var context = new DataManagementContext()) { if (context.Manufacturers.Any(m => m.Name == manufacturer.Name)) { throw new Exception("A manufacturer with the supplied name already exists."); } var newManufacturer = new Models.Business.Manufacturer { Name = manufacturer.Name }; context.Manufacturers.Add(newManufacturer); context.SaveChanges(); } }
public void RenameunitMeasure(UnitMeasure unitMeasure, string newName) { if (unitMeasure == null) { throw new ArgumentNullException("unitMeasure"); } if (string.IsNullOrWhiteSpace(unitMeasure.Name) || string.IsNullOrWhiteSpace(unitMeasure.Name.Sanitise().Trim())) { throw new Exception("Invalid UnitMeasure name!!!"); } unitMeasure.Name = unitMeasure.Name.Sanitise().Trim(); using (var context = new DataManagementContext()) { var selectedUnitMeasures = context.UnitMeasures.SingleOrDefault(u => u.UnitMeasureCode == unitMeasure.UnitMeasureCode); if (selectedUnitMeasures == null) { throw new Exception("The UnitMeasure record was not found in the database."); } if (selectedUnitMeasures.Name == newName) { return; } selectedUnitMeasures.Name = newName; context.SaveChanges(); } }
public void RemoveUnitMeasure(UnitMeasure unitMeasure) { if (unitMeasure == null) { throw new ArgumentNullException("unitMeasure"); } if (string.IsNullOrWhiteSpace(unitMeasure.Name) || string.IsNullOrWhiteSpace(unitMeasure.Name.Sanitise())) { throw new Exception("Invalid unitMeasure name!!!"); } unitMeasure.Name = unitMeasure.Name.Trim().Sanitise(); using (var context = new DataManagementContext()) { var selectedUnitMeasure = context.UnitMeasures.SingleOrDefault(u => u.UnitMeasureCode == unitMeasure.UnitMeasureCode); if (selectedUnitMeasure == null) { throw new Exception("The UnitMeasure record was not found in the database"); } try { context.UnitMeasures.Remove(selectedUnitMeasure); context.SaveChanges(); } catch (Exception) { throw new Exception("Could not remove the selected unitMeasure because it has associated Products."); } } }
public void AddUnitMeasure(UnitMeasure unitMeasure) { if (unitMeasure == null) { throw new ArgumentNullException("unitMeasure"); } if (string.IsNullOrWhiteSpace(unitMeasure.Name)) { throw new Exception("Invalid UnitMeasure name!!!"); } unitMeasure.Name = unitMeasure.Name.Trim().Sanitise(); using (var context = new DataManagementContext()) { if (context.UnitMeasures.Any(m => m.Name == unitMeasure.Name)) { throw new Exception("A unitMeasure with the supplied name already exists."); } var newUnitMeasures = new Models.Inventory.UnitMeasure { UnitMeasureCode = unitMeasure.UnitMeasureCode, Name = unitMeasure.Name }; context.UnitMeasures.Add(newUnitMeasures); context.SaveChanges(); } }