public void DeleteVendor(IntegrationVendor input) { using (var dc = new VendorDataContext(_connectionString)) { var toDelete = dc.IntegrationVendors.Where(x => x.IntegrationVendorId == input.IntegrationVendorId); var toDeleteVendorProducts = dc.IntegrationVendorProducts.Where(x => x.IntegrationVendorId == input.IntegrationVendorId); dc.IntegrationVendorProducts.DeleteAllOnSubmit(toDeleteVendorProducts); dc.IntegrationVendors.DeleteAllOnSubmit(toDelete); dc.SubmitChanges(); } }
public void SaveVendor(IntegrationVendor vendor) { using (var dc = new VendorDataContext(_connectionString)) { var dbVendor = dc.IntegrationVendors.FirstOrDefault(x => x.IntegrationVendorId == vendor.IntegrationVendorId); if (dbVendor != null) { dbVendor.Name = vendor.Name; dbVendor.Descr = vendor.Descr; dbVendor.Code = vendor.Code; dbVendor.SchemaType = vendor.SchemaType; } dc.SubmitChanges(); } }
public int AddVendor(IntegrationVendor input) { using (var dc = new VendorDataContext(_connectionString)) { var vendorSameNameOrCode = dc.IntegrationVendors.FirstOrDefault(x => x.Name == input.Name || x.Code == input.Code); if (vendorSameNameOrCode != null) { input.IntegrationVendorId = vendorSameNameOrCode.IntegrationVendorId; } else { var maxId = dc.IntegrationVendors.Max(x => x.IntegrationVendorId); input.IntegrationVendorId = maxId + 1; dc.IntegrationVendors.InsertOnSubmit(input); dc.SubmitChanges(); } } return(input.IntegrationVendorId); }