private void DataPortal_Fetch(CategoryCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; string commandText = String.Format("SELECT [CategoryId], [Name], [Descn] FROM [dbo].[Category] {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.Category' using the following criteria: {0}.", criteria)); } } } OnFetched(); }
/// <summary> /// Fetch CategoryList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public CategoryList Fetch(CategoryCriteria criteria) { CategoryList item = (CategoryList)Activator.CreateInstance(typeof(CategoryList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return item; // Fetch Child objects. string commandText = String.Format("SELECT [CategoryId], [Name], [Descn] FROM [dbo].[Category] {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 CategoryFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return item; }
/// <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(CategoryCriteria criteria) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) { return; } string commandText = String.Format("DELETE FROM [dbo].[Category] {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(); }
private Category Create(CategoryCriteria criteria) { var item = (Category)Activator.CreateInstance(typeof(Category), 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; } CheckRules(item); MarkNew(item); OnCreated(); return(item); }
GetAllViewModelsFilteredAsync(FilterBindingModel model) { // TODO: Refactor repository architechture efficient data retrieving ICollection <Product> products = Repository.All().ToList <Product>(); // Filter design pattern if (model.CategoryIdFilter != null) { CategoryCriteria categoryCriteria = new CategoryCriteria(model.CategoryIdFilter); products = categoryCriteria.MeetCriteria(products); } if (model.BrandIdFilter != null) { BrandCriteria brandCriteria = new BrandCriteria(model.BrandIdFilter); products = brandCriteria.MeetCriteria(products); } if (model.SearchFilter != null) { SearchCriteria searchCriteria = new SearchCriteria(model.SearchFilter); products = searchCriteria.MeetCriteria(products); } return(this.Mapper.Map <ICollection <ProductViewModel> >(products)); }
private void Child_Fetch(CategoryCriteria 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_Category_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); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) { do { this.Add(PetShop.Tests.Collections.EditableChild.Category.GetCategory(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
private void DataPortal_Fetch(CategoryCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) return; RaiseListChangedEvents = false; // Fetch Child objects. string commandText = String.Format("SELECT [CategoryId], [Name], [Descn] FROM [dbo].[Category] {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.Category.GetCategory(reader)); } while(reader.Read()); } } } } RaiseListChangedEvents = true; OnFetched(); }
/// <summary> /// Fetch CategoryList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public CategoryList Fetch(CategoryCriteria criteria) { CategoryList item = (CategoryList)Activator.CreateInstance(typeof(CategoryList), 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_Category_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); using(var reader = new SafeDataReader(command.ExecuteReader())) { if(reader.Read()) { do { item.Add(new CategoryFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return item; }
private IEnumerable <LogModel> PagingCatCountry(CategoryCriteria criteria, int page, int size, out long rowsCount) { string valueName, valueCode; valueName = valueCode = criteria.Query != null?criteria.Query.ToLower() : ""; Expression <Func <CatCountryLog, bool> > countryEx = x => (x.NewObject.NameEn.ToLower().Contains(valueName) || x.NewObject.Code.ToLower().Contains(valueCode)) && (x.PropertyCommon.DatetimeModified >= criteria.FromDate || criteria.FromDate == null) && (x.PropertyCommon.DatetimeModified <= criteria.ToDate || criteria.ToDate == null); var filterCountry = Builders <CatCountryLog> .Filter.Where(countryEx); var queryCurrencyResult = mongoContext.CatCountries.Find(filterCountry); rowsCount = queryCurrencyResult.CountDocuments(); var data = queryCurrencyResult.Skip(page * size).Limit(size).ToList().Select(x => new LogModel { Id = x.Id, UserUpdated = x.PropertyCommon.UserModified, Action = ConvertAction.ConvertLinqAction(x.PropertyCommon.ActionType), DatetimeUpdated = x.PropertyCommon.DatetimeModified, PropertyChange = x.PropertyCommon.PropertyChange, ObjectId = x.NewObject.Id.ToString(), Name = x.NewObject.Code ?? x.NewObject.NameEn, Code = int.TryParse(x.NewObject?.Id.ToString(), out int n) == true ? null : x.NewObject?.Id.ToString() });
private void DataPortal_Fetch(CategoryCriteria 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_Category_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); 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.Category' using the following criteria: {0}.", criteria)); } } } OnFetched(); MarkOld(); }
private IEnumerable <LogModel> PagingCatStage(CategoryCriteria criteria, int page, int size, out long rowsCount) { Expression <Func <CatStageLog, bool> > stageEx = x => x.NewObject.Code.Contains(criteria.Query ?? "") && x.NewObject.StageNameEn.Contains(criteria.Query ?? "") && (x.PropertyCommon.DatetimeModified >= criteria.FromDate || criteria.FromDate == null) && (x.PropertyCommon.DatetimeModified <= criteria.ToDate || criteria.ToDate == null); var filterStage = Builders <CatStageLog> .Filter.Where(stageEx); var queryCurrencyResult = mongoContext.CatStages.Find(filterStage); rowsCount = queryCurrencyResult.CountDocuments(); var data = queryCurrencyResult.Skip(page * size).Limit(size).ToList().Select(x => new LogModel { Id = x.Id, UserUpdated = x.PropertyCommon.UserModified, Action = ConvertAction.ConvertLinqAction(x.PropertyCommon.ActionType), DatetimeUpdated = x.PropertyCommon.DatetimeModified, PropertyChange = x.PropertyCommon.PropertyChange, ObjectId = x.NewObject.Id.ToString(), Name = x.NewObject.StageNameEn, Code = null }); return(data); }
/// <summary> /// this method shall be used to return the component based on a category /// </summary> /// <param name="category"></param> /// <param name="contentRepositoryId"></param> /// <param name="nbrOfRecords"></param> /// <returns></returns> public static List <XmlDocument> GetComponentsByCategory(string category, int contentRepositoryId, int nbrOfRecords) { List <XmlDocument> results; CategoryCriteria categoryCriteria = new CategoryCriteria(category); ItemTypeCriteria typeCriteria = new ItemTypeCriteria(TRIDION_ITEMTYPE); results = BuildAndExecute(contentRepositoryId, new Criteria[] { categoryCriteria, typeCriteria }, nbrOfRecords); return(results); }
private IEnumerable <LogModel> PagingCatPlace(CategoryCriteria criteria, int page, int size, out long rowsCount) { string type = string.Empty; switch (criteria.TableType) { case CategoryTable.Warehouse: type = CatPlaceConstant.Warehouse; break; case CategoryTable.PortIndex: type = CatPlaceConstant.Port; break; case CategoryTable.Province: type = CatPlaceConstant.Province; break; case CategoryTable.District: type = CatPlaceConstant.District; break; case CategoryTable.Ward: type = CatPlaceConstant.Ward; break; } Expression <Func <CatPlaceLog, bool> > placeEx = x => x.NewObject.Code.Contains(criteria.Query ?? "") && x.NewObject.NameEn.Contains(criteria.Query ?? "") && (x.PropertyCommon.DatetimeModified >= criteria.FromDate || criteria.FromDate == null) && (x.PropertyCommon.DatetimeModified <= criteria.ToDate || criteria.ToDate == null) && (x.NewObject.PlaceTypeId.Contains(type ?? "")); var filterPlace = Builders <CatPlaceLog> .Filter.Where(placeEx); var queryCurrencyResult = mongoContext.CatPlaces.Find(filterPlace); rowsCount = queryCurrencyResult.CountDocuments(); var data = queryCurrencyResult.Skip(page * size).Limit(size).ToList().Select(x => new LogModel { Id = x.Id, UserUpdated = x.PropertyCommon.UserModified, Action = ConvertAction.ConvertLinqAction(x.PropertyCommon.ActionType), DatetimeUpdated = x.PropertyCommon.DatetimeModified, PropertyChange = x.PropertyCommon.PropertyChange, ObjectId = x.NewObject.Id.ToString(), Name = x.NewObject?.NameEn, Code = x.NewObject?.Code }); return(data); }
public IActionResult Paging(CategoryCriteria categoryCriteria, int page, int size) { try { var data = catLogService.Paging(categoryCriteria, page, size, out long rowCount); var result = new { data, totalItems = rowCount, page, size }; return(Ok(result)); } catch (Exception ex) { // log or manage the exception throw ex; } }
private IEnumerable <LogModel> PagingCatCurrencyExchange(CategoryCriteria criteria, int page, int size, out long rowsCount) { var filterCurrencyExchange = Builders <CatCurrencyExchangeLog> .Filter.Where(_ => true); var queryCurrencyResult = mongoContext.CatCurrencyExchanges.Find(filterCurrencyExchange); rowsCount = queryCurrencyResult.CountDocuments(); var data = queryCurrencyResult.Skip(page * size).Limit(size).ToList().Select(x => new LogModel { Id = x.Id, UserUpdated = x.PropertyCommon.UserModified, Action = ConvertAction.ConvertLinqAction(x.PropertyCommon.ActionType), DatetimeUpdated = x.PropertyCommon.DatetimeModified, PropertyChange = x.PropertyCommon.PropertyChange, ObjectId = x.NewObject.Id.ToString(), Name = x.NewObject.CurrencyFromId }); return(data); }
private Category Create(CategoryCriteria criteria) { var item = (Category)Activator.CreateInstance(typeof(Category), 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; } CheckRules(item); MarkNew(item); OnCreated(); return item; }
/// <summary> /// Fetch Category. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Category Fetch(CategoryCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Category item; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Category_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); 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.Category' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); OnFetched(); return(item); }
protected void DoDelete(ref Category 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 CategoryCriteria { CategoryId = item.CategoryId }; DoDelete(criteria); MarkNew(item); }
/// <summary> /// Fetch CategoryList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public CategoryList Fetch(CategoryCriteria criteria) { CategoryList item = (CategoryList)Activator.CreateInstance(typeof(CategoryList), 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_Category_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); using (var reader = new SafeDataReader(command.ExecuteReader())) { if (reader.Read()) { do { item.Add(new CategoryFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return(item); }
/// <summary> /// Fetch CategoryList. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public CategoryList Fetch(CategoryCriteria criteria) { CategoryList item = (CategoryList)Activator.CreateInstance(typeof(CategoryList), true); bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(item); } // Fetch Child objects. string commandText = String.Format("SELECT [CategoryId], [Name], [Descn] FROM [dbo].[Category] {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 CategoryFactory().Map(reader)); } while(reader.Read()); } } } } MarkOld(item); OnFetched(); return(item); }
/// <summary> /// Fetch Category. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public Category Fetch(CategoryCriteria criteria) { bool cancel = false; OnFetching(criteria, ref cancel); if (cancel) { return(null); } Category item; string commandText = String.Format("SELECT [CategoryId], [Name], [Descn] FROM [dbo].[Category] {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.Category' using the following criteria: {0}.", criteria)); } } } } MarkOld(item); OnFetched(); return(item); }
//[Transactional(TransactionalTypes.TransactionScope)] protected void DataPortal_Delete(CategoryCriteria criteria, SqlConnection connection) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) return; string commandText = String.Format("DELETE FROM [dbo].[Category] {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(); }
public List <LogModel> Paging(CategoryCriteria criteria, int page, int size, out long rowsCount) { IEnumerable <LogModel> data = null; rowsCount = 0; switch (criteria.TableType) { case CategoryTable.CatCharge: data = PagingCatCharge(criteria, page, size, out rowsCount); break; case CategoryTable.CatChargeDefaultAccount: data = PagingCatChargeDefaultAccount(criteria, page, size, out rowsCount); break; case CategoryTable.CatCommonityGroup: data = PagingCatCommonityGroup(criteria, page, size, out rowsCount); break; case CategoryTable.CatCommodity: data = PagingCatCommodity(criteria, page, size, out rowsCount); break; case CategoryTable.CatCountry: data = PagingCatCountry(criteria, page, size, out rowsCount); break; case CategoryTable.CatCurrency: data = PagingCatCurrency(criteria, page, size, out rowsCount); break; //case CategoryTable.CatCurrencyExchange: // data = PagingCatCurrencyExchange(query, page, size, out rowsCount); // break; case CategoryTable.CatPartner: data = PagingCatPartner(criteria, page, size, out rowsCount); break; case CategoryTable.CatPlace: data = PagingCatPlace(criteria, page, size, out rowsCount); break; case CategoryTable.CatStage: data = PagingCatStage(criteria, page, size, out rowsCount); break; case CategoryTable.CatUnit: data = PagingCatUnit(criteria, page, size, out rowsCount); break; case CategoryTable.Warehouse: data = PagingCatPlace(criteria, page, size, out rowsCount); break; case CategoryTable.PortIndex: data = PagingCatPlace(criteria, page, size, out rowsCount); break; case CategoryTable.Province: data = PagingCatPlace(criteria, page, size, out rowsCount); break; case CategoryTable.District: data = PagingCatPlace(criteria, page, size, out rowsCount); break; case CategoryTable.Ward: data = PagingCatPlace(criteria, page, size, out rowsCount); break; case CategoryTable.ExchangeRate: data = PagingCatCurrencyExchange(criteria, page, size, out rowsCount); break; } if (data == null) { return(null); } var result = (from s in data join user in ((eFMSDataContext)sysUserContext.DC).SysUser on s.UserUpdated equals user.Id select new LogModel { Id = s.Id, UserUpdated = user.Username, Action = s.Action, DatetimeUpdated = s.DatetimeUpdated, PropertyChange = s.PropertyChange, Name = s.Name, Code = s.Code, ObjectId = s.ObjectId }).ToList(); return(result); }
protected void DataPortal_Delete(CategoryCriteria 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_Category_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(); }
private void DoUpdate(ref Category 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.OriginalCategoryId != item.CategoryId) { // Insert new child. var temp = (Category)Activator.CreateInstance(typeof(Category), true); temp.CategoryId = item.CategoryId; temp.Name = item.Name; temp.Description = item.Description; temp = temp.Save(); // Mark child lists as dirty. This code may need to be updated to one-to-one relationships. foreach(Product itemToUpdate in item.Products) { itemToUpdate.CategoryId = item.CategoryId; } // Update Children Update_Products_Products_FK__Product__Categor__0CBAE877(ref item); // Delete the old. var criteria = new CategoryCriteria {CategoryId = item.OriginalCategoryId}; Delete(criteria); // Mark the original as the new one. item.OriginalCategoryId = item.CategoryId; MarkOld(item); CheckRules(item); OnUpdated(); return; } const string commandText = "UPDATE [dbo].[Category] SET [CategoryId] = @p_CategoryId, [Name] = @p_Name, [Descn] = @p_Descn WHERE [CategoryId] = @p_CategoryId; SELECT [CategoryId] FROM [dbo].[Category] WHERE [CategoryId] = @p_OriginalCategoryId"; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using(var command = new SqlCommand(commandText, connection)) { command.Parameters.AddWithValue("@p_OriginalCategoryId", item.OriginalCategoryId); 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)); //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.OriginalCategoryId = item.CategoryId; MarkOld(item); CheckRules(item); if(!stopProccessingChildren) { // Update Child Items. Update_Products_Products_FK__Product__Categor__0CBAE877(ref item); } OnUpdated(); }
public void Delete(CategoryCriteria criteria) { // Note: this call to delete is for immediate deletion and doesn't keep track of any entity state. DoDelete(criteria); }
protected void DoDelete(ref Category 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 CategoryCriteria{CategoryId = item.CategoryId}; DoDelete(criteria); MarkNew(item); }
/// <summary> /// CodeSmith generated stub method that is called when deleting the <see cref="Category"/> object. /// </summary> /// <param name="criteria"><see cref="CategoryCriteria"/> 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(CategoryCriteria criteria, ref bool cancel);
/// <summary> /// CodeSmith generated stub method that is called when fetching the child <see cref="Category"/> object. /// </summary> /// <param name="criteria"><see cref="CategoryCriteria"/> 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(CategoryCriteria criteria, ref bool cancel);
internal static CategoryInfoList CategoryFetchInfoList(CategoryCriteria criteria) { return(CategoryInfoList.FetchCategoryInfoList(criteria)); }
protected override void DataPortal_Update() { bool cancel = false; OnUpdating(ref cancel); if (cancel) return; if(OriginalCategoryId != CategoryId) { // Insert new child. Category item = new Category {CategoryId = CategoryId, Name = Name, Description = Description}; item = item.Save(); // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships. foreach(Product itemToUpdate in Products) { itemToUpdate.CategoryId = CategoryId; } // Create a new connection. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); FieldManager.UpdateChildren(this, connection); } // Delete the old. var criteria = new CategoryCriteria {CategoryId = OriginalCategoryId}; DataPortal_Delete(criteria); // Mark the original as the new one. OriginalCategoryId = CategoryId; OnUpdated(); return; } const string commandText = "UPDATE [dbo].[Category] SET [CategoryId] = @p_CategoryId, [Name] = @p_Name, [Descn] = @p_Descn WHERE [CategoryId] = @p_OriginalCategoryId; SELECT [CategoryId] FROM [dbo].[Category] WHERE [CategoryId] = @p_OriginalCategoryId"; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using(var command = new SqlCommand(commandText, connection)) { command.Parameters.AddWithValue("@p_OriginalCategoryId", this.OriginalCategoryId); 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)); //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(_originalCategoryIdProperty, this.CategoryId); } FieldManager.UpdateChildren(this, connection); } OnUpdated(); }
private void DoUpdate(ref Category 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.OriginalCategoryId != item.CategoryId) { // Insert new child. var temp = (Category)Activator.CreateInstance(typeof(Category), true); temp.CategoryId = item.CategoryId; temp.Name = item.Name; temp.Description = item.Description; temp = temp.Save(); // Mark child lists as dirty. This code may need to be updated to one-to-one relationships. foreach (Product itemToUpdate in item.Products) { itemToUpdate.CategoryId = item.CategoryId; } // Update Children Update_Products_Products_FK__Product__Categor__0CBAE877(ref item); // Delete the old. var criteria = new CategoryCriteria { CategoryId = item.OriginalCategoryId }; Delete(criteria); // Mark the original as the new one. item.OriginalCategoryId = item.CategoryId; MarkOld(item); CheckRules(item); OnUpdated(); return; } const string commandText = "UPDATE [dbo].[Category] SET [CategoryId] = @p_CategoryId, [Name] = @p_Name, [Descn] = @p_Descn WHERE [CategoryId] = @p_CategoryId; SELECT [CategoryId] FROM [dbo].[Category] WHERE [CategoryId] = @p_OriginalCategoryId"; using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddWithValue("@p_OriginalCategoryId", item.OriginalCategoryId); 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)); //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.OriginalCategoryId = item.CategoryId; MarkOld(item); CheckRules(item); if (!stopProccessingChildren) { // Update Child Items. Update_Products_Products_FK__Product__Categor__0CBAE877(ref item); } OnUpdated(); }