/// <summary> /// This call to delete is for immediate deletion and doesn't keep track of any entity state. /// </summary> /// <param name="criteria">The Criteria.</param> private void DoDelete(SupplierCriteria criteria) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) { return; } string commandText = String.Format("DELETE FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) { throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); } } } OnDeleted(); }
protected void DataPortal_Fetch(SupplierCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_Addr1HasValue", criteria.Addr1HasValue); command.Parameters.AddWithValue("@p_Addr2HasValue", criteria.Addr2HasValue); command.Parameters.AddWithValue("@p_CityHasValue", criteria.CityHasValue); command.Parameters.AddWithValue("@p_StateHasValue", criteria.StateHasValue); command.Parameters.AddWithValue("@p_ZipHasValue", criteria.ZipHasValue); command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) Map(reader); else throw new Exception(String.Format("The record was not found in 'dbo.Supplier' using the following criteria: {0}.", criteria)); } } } OnFetched(); }
private Supplier Create(SupplierCriteria criteria) { var item = (Supplier)Activator.CreateInstance(typeof(Supplier), true); bool cancel = false; OnCreating(ref cancel); if (cancel) { return(item); } var resource = Fetch(criteria); using (BypassPropertyChecks(item)) { item.Name = resource.Name; item.Status = resource.Status; item.Addr1 = resource.Addr1; item.Addr2 = resource.Addr2; item.City = resource.City; item.State = resource.State; item.Zip = resource.Zip; item.Phone = resource.Phone; } CheckRules(item); MarkNew(item); OnCreated(); return(item); }
protected void DataPortal_Fetch(SupplierCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; string commandText = String.Format("SELECT [SuppId], [Name], [Status], [Addr1], [Addr2], [City], [State], [Zip], [Phone] FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using(var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) Map(reader); else throw new Exception(String.Format("The record was not found in 'dbo.Supplier' using the following criteria: {0}.", criteria)); } } } OnFetched(); }
private void Child_Fetch(SupplierCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; RaiseListChangedEvents = false; // Fetch Child objects. string commandText = String.Format("SELECT [SuppId], [Name], [Status], [Addr1], [Addr2], [City], [State], [Zip], [Phone] FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) { do { this.Add(PetShop.Business.Supplier.GetSupplier(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
public List <TDto> RetrieveAllSupplier <TDto>(IDataConverter <SupplierInfoData, TDto> converter) where TDto : class { SupplierCriteria criteria = new SupplierCriteria(); return(RetrieveSuppliersBySearch(criteria, converter)); }
/// <summary> /// Fetch SupplierList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public SupplierList Fetch(SupplierCriteria criteria) { SupplierList item = (SupplierList)Activator.CreateInstance(typeof(SupplierList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return item; // Fetch Child objects. string commandText = String.Format("SELECT [SuppId], [Name], [Status], [Addr1], [Addr2], [City], [State], [Zip], [Phone] FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using(var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { item.Add(new SupplierFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return item; }
private Supplier Create(SupplierCriteria criteria) { var item = (Supplier)Activator.CreateInstance(typeof(Supplier), true); bool cancel = false; OnCreating(ref cancel); if (cancel) return item; var resource = Fetch(criteria); using (BypassPropertyChecks(item)) { item.Name = resource.Name; item.Status = resource.Status; item.Addr1 = resource.Addr1; item.Addr2 = resource.Addr2; item.City = resource.City; item.State = resource.State; item.Zip = resource.Zip; item.Phone = resource.Phone; } CheckRules(item); MarkNew(item); OnCreated(); return item; }
public IEnumerable <SupplierInfoData> Search(SupplierCriteria criteria) { ArgumentValidator.IsNotNull("critetia", criteria); IEnumerable <SupplierInfoData> result = null; RepositoryExceptionWrapper.Wrap(GetType(), () => { ICriteria query = CurrentSession.CreateCriteria <SupplierInfoData>(); if (criteria.CategoryId != null) { query.AddExpressionEq <SupplierInfoData, object>(o => o.CategoryId, criteria.CategoryId); } if (!string.IsNullOrEmpty(criteria.SupplierName)) { query.AddExpressionInsensitiveLike <SupplierInfoData, string>(o => o.Name, criteria.SupplierName, MatchMode.Anywhere); } if (!string.IsNullOrEmpty(criteria.ZipCode)) { query.AddExpressionInsensitiveLike <SupplierInfoData, string>(o => o.ZipCode, criteria.ZipCode, MatchMode.Anywhere); } if (!string.IsNullOrEmpty(criteria.Address)) { query.AddExpressionInsensitiveLike <SupplierInfoData, string>(o => o.Address, criteria.Address, MatchMode.Anywhere); } result = query.List <SupplierInfoData>(); }); return(result); }
private void RetrieveSuppliersByCriteria(SupplierCriteria criteria) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { SupplierFacade facade = new SupplierFacade(uow); CurrentInstances = facade.RetrieveSuppliersBySearch(criteria, new SupplierInfoConverter(CurrentUserContext.CurrentLanguage.Id)); } }
public async Task <IReadOnlyCollection <Supplier> > GetMultipleAsync(SupplierCriteria criteria = null) { try { var suppliers = new List <Supplier>(); var reader = await SqlMapper.ExecuteReaderAsync( cnn : this._connection, sql : this.GetSelectAllSQL() + " " + this.GetSortingSQL(), // $"select * from [{nameof(Supplier)}];", transaction : this.GetTransactionIfAvailable()); await using (reader) { while (await reader.ReadAsync()) { var address = Address.Create( country: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.Country))), province: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.Province))), city: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.City))), zip: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.Zip))), street: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.Street))), number: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.Number)))); var agent = Agent.Create( name: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Agent), nameof(Agent.Name))), surname: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Agent), nameof(Agent.Surname))), phone: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Agent), nameof(Agent.Phone)))); suppliers.Add( new Supplier( id: await reader.GetSafeAsync <int>(nameof(Supplier.Id)), name: await reader.GetSafeAsync <string>(nameof(Supplier.Name)), eMail: await reader.GetSafeAsync <string>(nameof(Supplier.Email)), webSite: await reader.GetSafeAsync <string>(nameof(Supplier.Website)), phone: await reader.GetSafeAsync <string>(nameof(Supplier.Phone)), fax: await reader.GetSafeAsync <string>(nameof(Supplier.Fax)), notes: await reader.GetSafeAsync <string>(nameof(Supplier.Notes)), address: address, agent: agent)); } } //await Task.Delay(1000 * 3); return(suppliers); } catch (InvalidCastException ex) { Debug.WriteLine(ex); return(Array.Empty <Supplier>()); } catch (Exception ex) { Debug.WriteLine(ex); return(Array.Empty <Supplier>()); } }
public List <TDto> RetrieveSuppliersBySearch <TDto>(SupplierCriteria criteria, IDataConverter <SupplierInfoData, TDto> converter) where TDto : class { UnitOfWork.BeginTransaction(); List <TDto> instances = SupplierSystem.RetrieveSuppliersBySearch(criteria, converter); UnitOfWork.CommitTransaction(); if (instances == null) { instances = new List <TDto>(); } return(instances); }
public async Task Can_Handle_IValidatableObject_On_Command_Property() { // Arrange var supplierCriteria = new SupplierCriteria(name: "Louis"); var insertCustomerCommand = new InsertSupplier(supplierCriteria: supplierCriteria); // Act var dispatcher = this.GetDispatcher(); var commandResult = (await dispatcher.Command(command: insertCustomerCommand)).As<CommandResult>(); // Assert Assert.False(condition: commandResult.Success); Assert.Equal(expected: "Name Cannot Be Louis", actual: commandResult.Errors[0]); }
public async Task Can_Receive_ValidationResult() { // Arrange var supplierCriteria = new SupplierCriteria(name: "CoolName"); var insertSupplierCommand = new InsertSupplier(supplierCriteria: supplierCriteria); // Act var dispatcher = this.GetDispatcher(); var commandResult = (await dispatcher.Command(command: insertSupplierCommand)).As <SampleValidationResult>(); // Assert Assert.False(condition: commandResult.Success); Assert.Equal(expected: "Another Test Error Message", actual: commandResult.Errors[0].ErrorMessage); }
internal List <TDto> RetrieveSuppliersBySearch <TDto>(SupplierCriteria criteria, IDataConverter <SupplierInfoData, TDto> converter) where TDto : class { ArgumentValidator.IsNotNull("criteria", criteria); ArgumentValidator.IsNotNull("converter", converter); ISupplierService service = UnitOfWork.GetService <ISupplierService>(); var query = service.Search(criteria); if (query.HasResult) { return(query.DataToDtoList(converter).ToList()); } return(null); }
/// <summary> /// Fetch SupplierList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public SupplierList Fetch(SupplierCriteria criteria) { SupplierList item = (SupplierList)Activator.CreateInstance(typeof(SupplierList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(item); } // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_Addr1HasValue", criteria.Addr1HasValue); command.Parameters.AddWithValue("@p_Addr2HasValue", criteria.Addr2HasValue); command.Parameters.AddWithValue("@p_CityHasValue", criteria.CityHasValue); command.Parameters.AddWithValue("@p_StateHasValue", criteria.StateHasValue); command.Parameters.AddWithValue("@p_ZipHasValue", criteria.ZipHasValue); command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { item.Add(new SupplierFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return(item); }
/// <summary> /// Fetch Supplier. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Supplier Fetch(SupplierCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Supplier item; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_Addr1HasValue", criteria.Addr1HasValue); command.Parameters.AddWithValue("@p_Addr2HasValue", criteria.Addr2HasValue); command.Parameters.AddWithValue("@p_CityHasValue", criteria.CityHasValue); command.Parameters.AddWithValue("@p_StateHasValue", criteria.StateHasValue); command.Parameters.AddWithValue("@p_ZipHasValue", criteria.ZipHasValue); command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { item = Map(reader); } else { throw new Exception(String.Format("The record was not found in 'dbo.Supplier' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); OnFetched(); return(item); }
/// <summary> /// Fetch SupplierList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public SupplierList Fetch(SupplierCriteria criteria) { SupplierList item = (SupplierList)Activator.CreateInstance(typeof(SupplierList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return item; // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_Addr1HasValue", criteria.Addr1HasValue); command.Parameters.AddWithValue("@p_Addr2HasValue", criteria.Addr2HasValue); command.Parameters.AddWithValue("@p_CityHasValue", criteria.CityHasValue); command.Parameters.AddWithValue("@p_StateHasValue", criteria.StateHasValue); command.Parameters.AddWithValue("@p_ZipHasValue", criteria.ZipHasValue); command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) { do { item.Add(new SupplierFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return item; }
private void Child_Fetch(SupplierCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; RaiseListChangedEvents = false; // Fetch Child objects. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_Addr1HasValue", criteria.Addr1HasValue); command.Parameters.AddWithValue("@p_Addr2HasValue", criteria.Addr2HasValue); command.Parameters.AddWithValue("@p_CityHasValue", criteria.CityHasValue); command.Parameters.AddWithValue("@p_StateHasValue", criteria.StateHasValue); command.Parameters.AddWithValue("@p_ZipHasValue", criteria.ZipHasValue); command.Parameters.AddWithValue("@p_PhoneHasValue", criteria.PhoneHasValue); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) { do { this.Add(PetShop.Tests.StoredProcedures.Supplier.GetSupplier(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
/// <summary> /// Fetch SupplierList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public SupplierList Fetch(SupplierCriteria criteria) { SupplierList item = (SupplierList)Activator.CreateInstance(typeof(SupplierList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(item); } // Fetch Child objects. string commandText = String.Format("SELECT [SuppId], [Name], [Status], [Addr1], [Addr2], [City], [State], [Zip], [Phone] FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { item.Add(new SupplierFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); MarkAsChild(item); OnFetched(); return(item); }
protected void DoDelete(ref Supplier item) { // If we're not dirty then don't update the database. if (!item.IsDirty) { return; } // If we're new then don't call delete. if (item.IsNew) { return; } var criteria = new SupplierCriteria { SuppId = item.SuppId }; DoDelete(criteria); MarkNew(item); }
/// <summary> /// Fetch Supplier. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Supplier Fetch(SupplierCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Supplier item; string commandText = String.Format("SELECT [SuppId], [Name], [Status], [Addr1], [Addr2], [City], [State], [Zip], [Phone] FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { item = Map(reader); } else { throw new Exception(String.Format("The record was not found in 'dbo.Supplier' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); OnFetched(); return(item); }
public Task <IReadOnlyCollection <SupplierSummaryDto> > GetSupplierSummariesAsync(SupplierCriteria criteria = null) { throw new NotImplementedException(); }
public Task <SupplierHeaderDto> GetSupplierHeadersAsync(SupplierCriteria criteria = null) { throw new NotImplementedException(); }
private void DoUpdate(ref Supplier item, bool stopProccessingChildren) { bool cancel = false; OnUpdating(ref cancel); if (cancel) return; // Don't update if the item isn't dirty. if (item.IsDirty) { if(item.OriginalSuppId != item.SuppId) { // Insert new child. var temp = (Supplier)Activator.CreateInstance(typeof(Supplier), true); temp.SuppId = item.SuppId; temp.Name = item.Name; temp.Status = item.Status; temp.Addr1 = item.Addr1; temp.Addr2 = item.Addr2; temp.City = item.City; temp.State = item.State; temp.Zip = item.Zip; temp.Phone = item.Phone; temp = temp.Save(); // Mark child lists as dirty. This code may need to be updated to one-to-one relationships. foreach(Item itemToUpdate in item.Items) { itemToUpdate.Supplier = item.SuppId; } // Update Children Update_Items_Items_FK__Item__Supplier__1273C1CD(ref item); // Delete the old. var criteria = new SupplierCriteria {SuppId = item.OriginalSuppId}; Delete(criteria); // Mark the original as the new one. item.OriginalSuppId = item.SuppId; MarkOld(item); CheckRules(item); OnUpdated(); return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using(var command = new SqlCommand("[dbo].[CSLA_Supplier_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OriginalSuppId", item.OriginalSuppId); command.Parameters.AddWithValue("@p_SuppId", item.SuppId); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(item.Name)); command.Parameters.AddWithValue("@p_Status", item.Status); command.Parameters.AddWithValue("@p_Addr1", ADOHelper.NullCheck(item.Addr1)); command.Parameters.AddWithValue("@p_Addr2", ADOHelper.NullCheck(item.Addr2)); command.Parameters.AddWithValue("@p_City", ADOHelper.NullCheck(item.City)); command.Parameters.AddWithValue("@p_State", ADOHelper.NullCheck(item.State)); command.Parameters.AddWithValue("@p_Zip", ADOHelper.NullCheck(item.Zip)); command.Parameters.AddWithValue("@p_Phone", ADOHelper.NullCheck(item.Phone)); //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); } } } item.OriginalSuppId = item.SuppId; MarkOld(item); CheckRules(item); if(!stopProccessingChildren) { // Update Child Items. Update_Items_Items_FK__Item__Supplier__1273C1CD(ref item); } OnUpdated(); }
/// <summary> /// CodeSmith generated stub method that is called when fetching the child <see cref="Supplier"/> object. /// </summary> /// <param name="criteria"><see cref="SupplierCriteria"/> object containing the criteria of the object to fetch.</param> /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param> partial void OnFetching(SupplierCriteria criteria, ref bool cancel);
protected override void DataPortal_Update() { bool cancel = false; OnUpdating(ref cancel); if (cancel) return; if(OriginalSuppId != SuppId) { // Insert new child. Supplier item = new Supplier {SuppId = SuppId, Name = Name, Status = Status, Addr1 = Addr1, Addr2 = Addr2, City = City, State = State, Zip = Zip, Phone = Phone}; item = item.Save(); // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships. foreach(Item itemToUpdate in Items) { itemToUpdate.Supplier = SuppId; } // Create a new connection. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); FieldManager.UpdateChildren(this, connection); } // Delete the old. var criteria = new SupplierCriteria {SuppId = OriginalSuppId}; DataPortal_Delete(criteria); // Mark the original as the new one. OriginalSuppId = SuppId; OnUpdated(); return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using(var command = new SqlCommand("[dbo].[CSLA_Supplier_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OriginalSuppId", this.OriginalSuppId); command.Parameters.AddWithValue("@p_SuppId", this.SuppId); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); command.Parameters.AddWithValue("@p_Status", this.Status); command.Parameters.AddWithValue("@p_Addr1", ADOHelper.NullCheck(this.Addr1)); command.Parameters.AddWithValue("@p_Addr2", ADOHelper.NullCheck(this.Addr2)); command.Parameters.AddWithValue("@p_City", ADOHelper.NullCheck(this.City)); command.Parameters.AddWithValue("@p_State", ADOHelper.NullCheck(this.State)); command.Parameters.AddWithValue("@p_Zip", ADOHelper.NullCheck(this.Zip)); command.Parameters.AddWithValue("@p_Phone", ADOHelper.NullCheck(this.Phone)); //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); LoadProperty(_originalSuppIdProperty, this.SuppId); } FieldManager.UpdateChildren(this, connection); } OnUpdated(); }
public IServiceQueryResultList <SupplierInfoData> Search(SupplierCriteria criteria) { IEnumerable <SupplierInfoData> result = Repository.Search(criteria); return(ServiceResultFactory.BuildServiceQueryResult <SupplierInfoData>(result)); }
public abstract Task <IReadOnlyCollection <Supplier> > GetMultipleAsync(SupplierCriteria criteria = null);
protected void DoDelete(ref Supplier item) { // If we're not dirty then don't update the database. if (!item.IsDirty) return; // If we're new then don't call delete. if (item.IsNew) return; var criteria = new SupplierCriteria{SuppId = item.SuppId}; DoDelete(criteria); MarkNew(item); }
/// <summary> /// CodeSmith generated stub method that is called when deleting the <see cref="Supplier"/> object. /// </summary> /// <param name="criteria"><see cref="SupplierCriteria"/> object containing the criteria of the object to delete.</param> /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param> partial void OnDeleting(SupplierCriteria criteria, ref bool cancel);
/// <summary> /// CodeSmith generated stub method that is called when fetching the <see cref="Supplier"/> object. /// </summary> /// <param name="criteria"><see cref="SupplierCriteria"/> object containing the criteria of the object to fetch.</param> /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param> partial void OnFetching(SupplierCriteria criteria, ref bool cancel);
public void Delete(SupplierCriteria criteria) { // Note: this call to delete is for immediate deletion and doesn't keep track of any entity state. DoDelete(criteria); }
private void DoUpdate(ref Supplier item, bool stopProccessingChildren) { bool cancel = false; OnUpdating(ref cancel); if (cancel) { return; } // Don't update if the item isn't dirty. if (item.IsDirty) { if (item.OriginalSuppId != item.SuppId) { // Insert new child. var temp = (Supplier)Activator.CreateInstance(typeof(Supplier), true); temp.SuppId = item.SuppId; temp.Name = item.Name; temp.Status = item.Status; temp.Addr1 = item.Addr1; temp.Addr2 = item.Addr2; temp.City = item.City; temp.State = item.State; temp.Zip = item.Zip; temp.Phone = item.Phone; temp = temp.Save(); // Mark child lists as dirty. This code may need to be updated to one-to-one relationships. foreach (Item itemToUpdate in item.Items) { itemToUpdate.Supplier = item.SuppId; } // Update Children Update_Items_Items_FK__Item__Supplier__1273C1CD(ref item); // Delete the old. var criteria = new SupplierCriteria { SuppId = item.OriginalSuppId }; Delete(criteria); // Mark the original as the new one. item.OriginalSuppId = item.SuppId; MarkOld(item); CheckRules(item); OnUpdated(); return; } const string commandText = "UPDATE [dbo].[Supplier] SET [SuppId] = @p_SuppId, [Name] = @p_Name, [Status] = @p_Status, [Addr1] = @p_Addr1, [Addr2] = @p_Addr2, [City] = @p_City, [State] = @p_State, [Zip] = @p_Zip, [Phone] = @p_Phone WHERE [SuppId] = @p_SuppId; SELECT [SuppId] FROM [dbo].[Supplier] WHERE [SuppId] = @p_OriginalSuppId"; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddWithValue("@p_OriginalSuppId", item.OriginalSuppId); command.Parameters.AddWithValue("@p_SuppId", item.SuppId); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(item.Name)); command.Parameters.AddWithValue("@p_Status", item.Status); command.Parameters.AddWithValue("@p_Addr1", ADOHelper.NullCheck(item.Addr1)); command.Parameters.AddWithValue("@p_Addr2", ADOHelper.NullCheck(item.Addr2)); command.Parameters.AddWithValue("@p_City", ADOHelper.NullCheck(item.City)); command.Parameters.AddWithValue("@p_State", ADOHelper.NullCheck(item.State)); command.Parameters.AddWithValue("@p_Zip", ADOHelper.NullCheck(item.Zip)); command.Parameters.AddWithValue("@p_Phone", ADOHelper.NullCheck(item.Phone)); //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) { throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); } } } } item.OriginalSuppId = item.SuppId; MarkOld(item); CheckRules(item); if (!stopProccessingChildren) { // Update Child Items. Update_Items_Items_FK__Item__Supplier__1273C1CD(ref item); } OnUpdated(); }
public InsertSupplier(SupplierCriteria supplierCriteria) { this.Criteria = supplierCriteria; }
public abstract Task <Supplier> GetSingleAsync(SupplierCriteria criteria = null);
public override async Task <IReadOnlyCollection <Supplier> > GetMultipleAsync(SupplierCriteria criteria = null) { try { var suppliers = new List <Supplier>(); var cmd = new CommandDefinition( commandText: $"select * from [{nameof(Supplier)}] order by { nameof(Supplier.Name) } asc", transaction: this.GetTransactionIfAvailable()); //var resultsGrid = SqlMapper.QueryMultipleAsync(this._connection, cmd); //var x = await resultsGrid.Result.ReadAsync(); await using (var reader = await SqlMapper.ExecuteReaderAsync(cnn: this._connection, cmd).ConfigureAwait(false)) { while (await reader.ReadAsync()) { // TODO: cache column names composition var address = Address.Create( country: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.Country))).ConfigureAwait(false), province: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.Province))).ConfigureAwait(false), city: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.City))).ConfigureAwait(false), zip: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.Zip))).ConfigureAwait(false), street: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.Street))).ConfigureAwait(false), number: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Address), nameof(Address.Number))).ConfigureAwait(false)); var agent = Agent.Create( name: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Agent), nameof(Agent.Name))).ConfigureAwait(false), surname: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Agent), nameof(Agent.Surname))).ConfigureAwait(false), phone: await reader.GetSafeAsync <string>(DbSchemaHelper.ComposeColumnName(nameof(Supplier.Agent), nameof(Agent.Phone))).ConfigureAwait(false)); suppliers.Add( new Supplier( id: await reader.GetSafeAsync <long>(nameof(Supplier.Id)).ConfigureAwait(false), name: await reader.GetSafeAsync <string>(nameof(Supplier.Name)).ConfigureAwait(false), eMail: await reader.GetSafeAsync <string>(nameof(Supplier.Email)).ConfigureAwait(false), webSite: await reader.GetSafeAsync <string>(nameof(Supplier.Website)).ConfigureAwait(false), phone: await reader.GetSafeAsync <string>(nameof(Supplier.Phone)).ConfigureAwait(false), fax: await reader.GetSafeAsync <string>(nameof(Supplier.Fax)).ConfigureAwait(false), notes: await reader.GetSafeAsync <string>(nameof(Supplier.Notes)).ConfigureAwait(false), address: address, agent: agent)); } } return(suppliers); } catch (InvalidCastException ex) { Debug.WriteLine(ex); return(Array.Empty <Supplier>()); } catch (Exception ex) { Debug.WriteLine(ex); return(Array.Empty <Supplier>()); } }
/// <summary> /// This call to delete is for immediate deletion and doesn't keep track of any entity state. /// </summary> /// <param name="criteria">The Criteria.</param> private void DoDelete(SupplierCriteria criteria) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) return; string commandText = String.Format("DELETE FROM [dbo].[Supplier] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); } } OnDeleted(); }
public Task <Supplier> GetSingleAsync(SupplierCriteria criteria = null) { throw new NotImplementedException(); }
public void Delete(SupplierCriteria criteria) { //Note: this call to delete is for immediate deletion and doesn't keep track of any entity state. DoDelete(criteria); }
protected void DataPortal_Delete(SupplierCriteria criteria) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) return; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Delete]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); } } OnDeleted(); }