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 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 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 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(); } }
public ProductService(IUnitOfWork unitOfWork) { if (unitOfWork == null) { throw new ArgumentNullException("unitOfWork"); } _context = unitOfWork as DataManagementContext; _productRepository = new ProductRepository(_context); }
public ICollection <Supplier> GetSuppliers() { using (var context = new DataManagementContext()) { var supplier = from s in context.Partners select new Supplier() { SupplierID = s.PartnerID, Name = s.Name }; return(supplier.ToList()); } }
public ICollection <Manufacturer> GetManufacturers() { using (var context = new DataManagementContext()) { var manufacturers = from m in context.Manufacturers select new Manufacturer { ManufacturerID = m.ManufacturerID, Name = m.Name }; return(manufacturers.ToList()); } }
public ICollection <Customer> GetCustomers() { using (var context = new DataManagementContext()) { var customer = from s in context.Partners select new Customer() { CustomerID = s.PartnerID, Name = s.Name }; return(customer.ToList()); } }
ICollection <UnitMeasure> IUnitMeasureService.GetAllUnitMeasures() { using (var context = new DataManagementContext()) { var unitMeasure = from u in context.UnitMeasures select new UnitMeasure { UnitMeasureCode = u.UnitMeasureCode, Name = u.Name }; return(unitMeasure.ToList()); } }
public ICollection <Manufacturer> SearchManufacturers(string query) { if (string.IsNullOrWhiteSpace(query)) { return(GetManufacturers()); } var searchQuery = string.Format("%{0}%", query.Sanitise().Trim().ToLower()); using (var context = new DataManagementContext()) { var searchResults = from m in context.Manufacturers where SqlFunctions.PatIndex(searchQuery, m.Name) > 0 select new Manufacturer { ManufacturerID = m.ManufacturerID, Name = m.Name }; return(searchResults.ToList()); } }
public ProductService() { _context = new DataManagementContext(); }