private void DataPortal_Fetch(ProductCriteria 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_Product_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_DescnHasValue", criteria.DescriptionHasValue); command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue); 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.Product' using the following criteria: {0}.", criteria)); } } } OnFetched(); }
/// <summary> /// Fetch ProductList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public ProductList Fetch(ProductCriteria criteria) { ProductList item = (ProductList)Activator.CreateInstance(typeof(ProductList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return item; // Fetch Child objects. string commandText = String.Format("SELECT [ProductId], [CategoryId], [Name], [Descn], [Image] FROM [dbo].[Product] {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 ProductFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return item; }
private void DataPortal_Fetch(ProductCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; RaiseListChangedEvents = false; // Fetch Child objects. string commandText = String.Format("SELECT [ProductId], [CategoryId], [Name], [Descn], [Image] FROM [dbo].[Product] {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.Product.GetProduct(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
private void DataPortal_Fetch(ProductCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; string commandText = String.Format("SELECT [ProductId], [CategoryId], [Name], [Descn], [Image] FROM [dbo].[Product] {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.Product' using the following criteria: {0}.", criteria)); } } } OnFetched(); }
public List <Product> GeyByCriteria(ProductCriteria productCriteria) { var items = new List <Product>(); for (int i = 0; i < 10; i++) { items.Add(new Product { Name = "Producto " + i.ToString() }); } return(items); }
static void Main(string[] args) { ProductCriteria productCriteria = new ProductCriteria(); var items = ProductAgent.Instance().GeyByCriteria(productCriteria); foreach (var item in items) { System.Console.WriteLine(item.Name); } System.Console.ReadLine(); }
internal List <TDto> RetrieveProductsByCategory <TDto>(object categoryId, IDataConverter <ProductInfoData, TDto> converter) where TDto : class { ArgumentValidator.IsNotNull("converter", converter); ProductCriteria criteria = new ProductCriteria(); criteria.CategoryId = categoryId; IProductService service = UnitOfWork.GetService <IProductService>(); var query = service.Search(criteria); if (query.HasResult) { return(query.DataToDtoList(converter).ToList()); } return(null); }
/// <summary> /// Requests product data. /// </summary> /// <param name="request">Product request message.</param> /// <returns>Product response message.</returns> public ProductResponse GetProducts(ProductRequest request) { ProductResponse response = new ProductResponse(); response.CorrelationId = request.RequestId; // Validate client tag and access token if (!ValidRequest(request, response, Validate.ClientTag | Validate.AccessToken)) { return(response); } ProductCriteria criteria = request.Criteria as ProductCriteria; if (request.LoadOptions.Contains("Categories")) { IEnumerable <Category> categories = productDao.GetCategories(); response.Categories = Mapper.ToDataTransferObjects(categories); } if (request.LoadOptions.Contains("Products")) { IEnumerable <Product> products = productDao.GetProductsByCategory(criteria.CategoryId, criteria.SortExpression); response.Products = Mapper.ToDataTransferObjects(products); } if (request.LoadOptions.Contains("Product")) { Product product = productDao.GetProduct(criteria.ProductId); product.Category = productDao.GetCategoryByProduct(criteria.ProductId); response.Product = Mapper.ToDataTransferObject(product); } if (request.LoadOptions.Contains("Search")) { IList <Product> products = productDao.SearchProducts(criteria.ProductName, criteria.PriceFrom, criteria.PriceThru, criteria.SortExpression); response.Products = Mapper.ToDataTransferObjects(products); } return(response); }
/// <summary> /// Fetch ProductList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public ProductList Fetch(ProductCriteria criteria) { ProductList item = (ProductList)Activator.CreateInstance(typeof(ProductList), 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_Product_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_DescnHasValue", criteria.DescriptionHasValue); command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { item.Add(new ProductFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return(item); }
/// <summary> /// Fetch Product. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Product Fetch(ProductCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Product item; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Product_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_DescnHasValue", criteria.DescriptionHasValue); command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue); 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.Product' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); OnFetched(); return(item); }
protected void DoDelete(ref Product 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 ProductCriteria { ProductId = item.ProductId }; DoDelete(criteria); MarkNew(item); }
/// <summary> /// Fetch ProductList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public ProductList Fetch(ProductCriteria criteria) { ProductList item = (ProductList)Activator.CreateInstance(typeof(ProductList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(item); } // Fetch Child objects. string commandText = String.Format("SELECT [ProductId], [CategoryId], [Name], [Descn], [Image] FROM [dbo].[Product] {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 ProductFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return(item); }
private Product Create(ProductCriteria criteria) { var item = (Product)Activator.CreateInstance(typeof(Product), true); bool cancel = false; OnCreating(ref cancel); if (cancel) return item; var resource = Fetch(criteria); using (BypassPropertyChecks(item)) { item.Name = resource.Name; item.Description = resource.Description; item.Image = resource.Image; } CheckRules(item); MarkNew(item); OnCreated(); return item; }
/// <summary> /// Fetch Product. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Product Fetch(ProductCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Product item; string commandText = String.Format("SELECT [ProductId], [CategoryId], [Name], [Descn], [Image] FROM [dbo].[Product] {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.Product' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); OnFetched(); return(item); }
/// <summary> /// Fetch ProductList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public ProductList Fetch(ProductCriteria criteria) { ProductList item = (ProductList)Activator.CreateInstance(typeof(ProductList), 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_Product_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_DescnHasValue", criteria.DescriptionHasValue); command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) { do { item.Add(new ProductFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return item; }
private void Child_Fetch(ProductCriteria 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_Product_Select]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag)); command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue); command.Parameters.AddWithValue("@p_DescnHasValue", criteria.DescriptionHasValue); command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) { do { this.Add(PetShop.Tests.StoredProcedures.Product.GetProduct(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
/// <summary> /// CodeSmith generated stub method that is called when fetching the <see cref="Product"/> object. /// </summary> /// <param name="criteria"><see cref="ProductCriteria"/> 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(ProductCriteria criteria, ref bool cancel);
/// <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(ProductCriteria 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_Product_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(); }
protected void DoDelete(ref Product 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 ProductCriteria{ProductId = item.ProductId}; DoDelete(criteria); MarkNew(item); }
public void Delete(ProductCriteria 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 Product 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.OriginalProductId != item.ProductId) { // Insert new child. var temp = (Product)Activator.CreateInstance(typeof(Product), true); temp.ProductId = item.ProductId; temp.CategoryId = item.CategoryId; temp.Name = item.Name; temp.Description = item.Description; temp.Image = item.Image; 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.ProductId = item.ProductId; } // Update Children Update_Category_Category_FK__Product__Categor__0CBAE877(ref item); Update_Items_Items_FK__Item__ProductId__117F9D94(ref item); // Delete the old. var criteria = new ProductCriteria {ProductId = item.OriginalProductId}; Delete(criteria); // Mark the original as the new one. item.OriginalProductId = item.ProductId; MarkOld(item); CheckRules(item); OnUpdated(); return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using(var command = new SqlCommand("[dbo].[CSLA_Product_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OriginalProductId", item.OriginalProductId); command.Parameters.AddWithValue("@p_ProductId", item.ProductId); command.Parameters.AddWithValue("@p_CategoryId", item.CategoryId); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(item.Name)); command.Parameters.AddWithValue("@p_Descn", ADOHelper.NullCheck(item.Description)); command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(item.Image)); //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.OriginalProductId = item.ProductId; MarkOld(item); CheckRules(item); if(!stopProccessingChildren) { // Update Child Items. Update_Category_Category_FK__Product__Categor__0CBAE877(ref item); Update_Items_Items_FK__Item__ProductId__117F9D94(ref item); } OnUpdated(); }
protected override void DataPortal_Update() { bool cancel = false; OnUpdating(ref cancel); if (cancel) return; if(OriginalProductId != ProductId) { // Insert new child. Product item = new Product {ProductId = ProductId, CategoryId = CategoryId, Name = Name, Description = Description, Image = Image}; 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.ProductId = ProductId; } // Create a new connection. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); FieldManager.UpdateChildren(this, connection); } // Delete the old. var criteria = new ProductCriteria {ProductId = OriginalProductId}; DataPortal_Delete(criteria); // Mark the original as the new one. OriginalProductId = ProductId; OnUpdated(); return; } const string commandText = "UPDATE [dbo].[Product] SET [ProductId] = @p_ProductId, [CategoryId] = @p_CategoryId, [Name] = @p_Name, [Descn] = @p_Descn, [Image] = @p_Image WHERE [ProductId] = @p_OriginalProductId; SELECT [ProductId] FROM [dbo].[Product] WHERE [ProductId] = @p_OriginalProductId"; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using(var command = new SqlCommand(commandText, connection)) { command.Parameters.AddWithValue("@p_OriginalProductId", this.OriginalProductId); command.Parameters.AddWithValue("@p_ProductId", this.ProductId); command.Parameters.AddWithValue("@p_CategoryId", this.CategoryId); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); command.Parameters.AddWithValue("@p_Descn", ADOHelper.NullCheck(this.Description)); command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(this.Image)); //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(_originalProductIdProperty, this.ProductId); } FieldManager.UpdateChildren(this, connection); } OnUpdated(); }
//[Transactional(TransactionalTypes.TransactionScope)] protected void DataPortal_Delete(ProductCriteria criteria, SqlConnection connection) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) return; string commandText = String.Format("DELETE FROM [dbo].[Product] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag)); 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(); }
/// <summary> /// CodeSmith generated stub method that is called when deleting the <see cref="Product"/> object. /// </summary> /// <param name="criteria"><see cref="ProductCriteria"/> 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(ProductCriteria criteria, ref bool cancel);
public IServiceQueryResultList <ProductInfoData> Search(ProductCriteria criteria) { IEnumerable <ProductInfoData> result = Repository.Search(criteria); return(ServiceResultFactory.BuildServiceQueryResult <ProductInfoData>(result)); }
public List <Product> GeyByCriteria(ProductCriteria productCriteria) { ProductBusiness productBusiness = new ProductBusiness(); return(productBusiness.GeyByCriteria(productCriteria)); }
private void DoUpdate(ref Product 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.OriginalProductId != item.ProductId) { // Insert new child. var temp = (Product)Activator.CreateInstance(typeof(Product), true); temp.ProductId = item.ProductId; temp.CategoryId = item.CategoryId; temp.Name = item.Name; temp.Description = item.Description; temp.Image = item.Image; 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.ProductId = item.ProductId; } // Update Children Update_Category_Category_FK__Product__Categor__0CBAE877(ref item); Update_Items_Items_FK__Item__ProductId__117F9D94(ref item); // Delete the old. var criteria = new ProductCriteria { ProductId = item.OriginalProductId }; Delete(criteria); // Mark the original as the new one. item.OriginalProductId = item.ProductId; MarkOld(item); CheckRules(item); OnUpdated(); return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Product_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OriginalProductId", item.OriginalProductId); command.Parameters.AddWithValue("@p_ProductId", item.ProductId); command.Parameters.AddWithValue("@p_CategoryId", item.CategoryId); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(item.Name)); command.Parameters.AddWithValue("@p_Descn", ADOHelper.NullCheck(item.Description)); command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(item.Image)); //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.OriginalProductId = item.ProductId; MarkOld(item); CheckRules(item); if (!stopProccessingChildren) { // Update Child Items. Update_Category_Category_FK__Product__Categor__0CBAE877(ref item); Update_Items_Items_FK__Item__ProductId__117F9D94(ref item); } OnUpdated(); }
public List <Product> GeyByCriteria(ProductCriteria productCriteria) { ProductData productData = new ProductData(); return(productData.GeyByCriteria(productCriteria)); }