/// <summary> /// Insert one register in database. /// </summary> /// <param name="parCategoriesInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void InsertOne(CategoriesInfo parCategoriesInfo, DbTransaction transaction, out string errorMessage) { errorMessage = null; try { motor.CommandText = GetInsertCommand(); ///Warning: performance issues with this automation. See method description for details. List <DbParameter> paramList = ParameterBuilder.GetParametersForInsert(typeof(CategoriesInfo), parCategoriesInfo, motor.Command); motor.ClearCommandParameters(); motor.AddCommandParameters(paramList); motor.AddTransaction(transaction); if (GetIdentity == true) { parCategoriesInfo.CategoryID = motor.ExecuteScalar(); } else { motor.ExecuteNonQuery(); } } catch (Exception ex) { errorMessage = ex.Message; } }
/// <summary> /// Delete registers based on class values informed. MinValues and nulls are skipped. /// </summary> /// <param name="parCategoriesInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void Delete(CategoriesInfo parCategoriesInfo, DbTransaction transaction, out string errorMessage) { errorMessage = null; try { string whereClausule = string.Empty; var pks = GetPrimaryKey(); List <string> primaryKeys = new List <string>(); foreach (var item in pks) { primaryKeys.Add(item.Key); } List <DbParameter> paramList = ParameterBuilder.GetParametersForDelete(primaryKeys, typeof(CategoriesInfo), parCategoriesInfo, motor.Command, out whereClausule); motor.CommandText = GetDeleteCommand() + " " + whereClausule; motor.ClearCommandParameters(); motor.AddCommandParameters(paramList); motor.AddTransaction(transaction); motor.ExecuteNonQuery(); } catch (Exception ex) { errorMessage = ex.Message; } }
/// <summary> /// Get one register using only ID as key. /// </summary> /// <returns></returns> public virtual CategoriesInfo GetValueByID(int CategoryID) { //ToDo: set multiple PK filter motor.ClearCommandParameters(); motor.CommandText = GetSelectCommand() + GetWherePrimaryKey(); List <DbParameter> paramList = new List <DbParameter>(); DbParameter paramCategoryID = motor.Command.CreateParameter(); paramCategoryID.ParameterName = "@param_CategoryID"; paramCategoryID.Value = CategoryID; paramList.Add(paramCategoryID); motor.AddCommandParameters(paramList); CategoriesInfo InfoValue = new CategoriesInfo(); DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(CategoriesInfo), dbReader); using (dbReader) { if (dbReader.Read()) { InfoValue = new CategoriesInfo(); classFiller.Fill(InfoValue); } else { return(null); } } return(InfoValue); }
/// <summary> /// Delete registers based on ID informed. Other values are skipped. /// </summary> /// <param name="parCategoriesInfo">Item to delete</param> /// <param name="errorMessage">Error message</param> public virtual void DeleteByID(CategoriesInfo parCategoriesInfo, out string errorMessage) { CategoriesInfo newParam = new CategoriesInfo(); newParam.CategoryID = parCategoriesInfo.CategoryID; this.Delete(newParam, out errorMessage); }
/// <summary> /// Performs one "select * from MyTable where [InformedProperties]". MinValues and nulls are skipped from filter. /// </summary> /// <param name="filter">CategoriesInfo</param> /// <returns>List of found records.</returns> public virtual List <CategoriesInfo> GetSome(CategoriesInfo filter) { List <CategoriesInfo> AllInfoList = new List <CategoriesInfo>(); string filterWhere = string.Empty; List <DbParameter> paramList = null; GenerateWhere(filter, out filterWhere, out paramList); motor.ClearCommandParameters(); motor.AddCommandParameters(paramList); motor.CommandText = GetSelectCommand() + " " + filterWhere; DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(CategoriesInfo), dbReader); using (dbReader) { while (dbReader.Read()) { CategoriesInfo CategoriesInfo = new CategoriesInfo(); ///Warning: performance issues with this automation. See method description for details. classFiller.Fill(CategoriesInfo); AllInfoList.Add(CategoriesInfo); } } return(AllInfoList); }
/// <summary> /// Delete registers based on class values informed. MinValues and nulls are skipped. /// Must have "MultipleActiveResultSets=True" on connection string. /// </summary> /// <param name="parCategoriesInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void Delete(CategoriesInfo parCategoriesInfo, DbTransaction transaction, out string errorMessage) { errorMessage = string.Empty; CategoriesDAO.Delete(parCategoriesInfo, transaction, out errorMessage); //By default, the caller of this method will do the commit. //motor.Commit(); //motor.CloseConnection(); }
public void DeleteData(ModelNotifiedForCategories modelNotifiedForCategories, out string error) { CategoriesBsn bsn = new CategoriesBsn(wpfConfig); CategoriesInfo dbItem = new CategoriesInfo(); Cloner.CopyAllTo(typeof(ModelNotifiedForCategories), modelNotifiedForCategories, typeof(CategoriesInfo), dbItem); bsn.DeleteByID(dbItem, out error); }
/// <summary> /// Performs one "update" database command. /// Will commit the transaction and close the connection. Use for independent delete. /// </summary> /// <param name="CategoriesInfo">Object to update.</param> /// <param name="errorMessage">Error message if exception is throwed</param> public virtual void UpdateOne(CategoriesInfo parCategoriesInfo, out string errorMessage) { errorMessage = string.Empty; DbTransaction transaction = motor.BeginTransaction(); this.UpdateOne(parCategoriesInfo, transaction, out errorMessage); motor.Commit(); motor.CloseConnection(); }
/// <summary> /// Delete registers based on class ID informed in transactional context. Other values are skipped. /// Must have "MultipleActiveResultSets=True" on connection string. /// </summary> /// <param name="parCategoriesInfo">Item to delete</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void DeleteByID(CategoriesInfo parCategoriesInfo, DbTransaction transaction, out string errorMessage) { CategoriesInfo newParam = new CategoriesInfo(); newParam.CategoryID = parCategoriesInfo.CategoryID; this.Delete(newParam, transaction, out errorMessage); //By default, the caller of this method will do the commit. //motor.Commit(); //motor.CloseConnection(); }
public ModelNotifiedForCategories GetCategoriesByID(int CategoryID, out string error) { error = null; CategoriesBsn bsn = new CategoriesBsn(wpfConfig); CategoriesInfo dbItem = bsn.GetValueByID(CategoryID); ModelNotifiedForCategories item = new ModelNotifiedForCategories(); Cloner.CopyAllTo(typeof(CategoriesInfo), dbItem, typeof(ModelNotifiedForCategories), item); return(item); }
public void AddData(ModelNotifiedForCategories modelNotifiedForCategories, out string error) { CategoriesBsn bsn = new CategoriesBsn(wpfConfig); CategoriesInfo dbItem = new CategoriesInfo(); Cloner.CopyAllTo(typeof(ModelNotifiedForCategories), modelNotifiedForCategories, typeof(CategoriesInfo), dbItem); bsn.InsertOne(dbItem, out error); modelNotifiedForCategories.NewItem = false; Cloner.CopyAllTo(typeof(CategoriesInfo), dbItem, typeof(ModelNotifiedForCategories), modelNotifiedForCategories); }
/// <summary> /// Generate the "where" clausule, used for select data using "GetSome" method. /// </summary> /// <param name="filter">Class used to apply the filter</param> /// <param name="whereClausule">Result whith a string that add filter to the select comand</param> /// <param name="paramList">Result whith the parameters list</param> protected void GenerateWhere(CategoriesInfo filter, out string whereClausule, out List <DbParameter> paramList) { StringBuilder where = new StringBuilder(); paramList = new List <DbParameter>(); where.Append("where 1=1"); // 1) Adding filter for field CategoryID if (filter.CategoryID != Int32.MinValue) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_CategoryID"; param.Value = filter.CategoryID; paramList.Add(param); where.Append(" and Categories.CategoryID=@param_CategoryID"); } // 2) Adding filter for field CategoryName if (filter.CategoryName != null) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_CategoryName"; param.Value = filter.CategoryName; paramList.Add(param); where.Append(" and Categories.CategoryName=@param_CategoryName"); //Hint: use the code below to add a "like" search. Warning: may cause data performance issues. //param.ParameterName = "@param_CategoryName"; //param.Value = "%" + filter.CategoryName "%"; //paramList.Add(param); //where.Append(" and Categories.CategoryName like @param_CategoryName"); } // 3) Adding filter for field Description if (filter.Description != null) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_Description"; param.Value = filter.Description; paramList.Add(param); where.Append(" and Categories.Description=@param_Description"); //Hint: use the code below to add a "like" search. Warning: may cause data performance issues. //param.ParameterName = "@param_Description"; //param.Value = "%" + filter.Description "%"; //paramList.Add(param); //where.Append(" and Categories.Description like @param_Description"); } // 4) Adding filter for field Picture if (filter.Picture != null) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_Picture"; param.Value = filter.Picture; paramList.Add(param); where.Append(" and Categories.Picture=@param_Picture"); } whereClausule = where.ToString(); }
/// <summary> /// Perform one "select" command to database. Filter the data using "filter" class. /// </summary> /// <param name="filter">Class to use as filter</param> /// <returns>List with filtered data</returns> public virtual List <CategoriesInfo> GetSome(CategoriesInfo filter) { motor.OpenConnection(); List <CategoriesInfo> list = CategoriesDAO.GetSome(filter); if (this.closeConnectionWhenFinish) { motor.CloseConnection(); } return(list); }
/// <summary> /// Retrieves the data using only the primary key ID. Ex.: "Select * from MyTable where id=1" /// </summary> /// <returns>The class filled if found.</returns> public virtual CategoriesInfo GetValueByID(int CategoryID) { motor.OpenConnection(); CategoriesInfo value = CategoriesDAO.GetValueByID(CategoryID); if (this.closeConnectionWhenFinish) { motor.CloseConnection(); } return(value); }
/// <summary> /// Performs a "update [FildList] set [FieldList] where id = @id". Must have the ID informed. /// </summary> /// <param name="parCategoriesInfo">Item to update</param> /// <param name="transaction">Transaction context</param> /// <param name="errorMessage">Error message</param> public virtual void UpdateOne(CategoriesInfo parCategoriesInfo, DbTransaction transaction, out string errorMessage) { errorMessage = null; try { motor.CommandText = GetUpdateCommand(); ///Warning: performance issues with this automation. See method description for details. List <DbParameter> paramList = ParameterBuilder.GetParametersForUpdate(typeof(CategoriesInfo), parCategoriesInfo, motor.Command); motor.ClearCommandParameters(); motor.AddCommandParameters(paramList); motor.AddTransaction(transaction); motor.ExecuteNonQuery(); } catch (Exception ex) { errorMessage = ex.Message; } }
/// <summary> /// Use parameters to apply simple filters /// </summary> /// <param name="filterExpression"></param> /// <returns></returns> public virtual List <CategoriesInfo> GetAll(List <DataFilterExpressionDB> filterExpression) { List <CategoriesInfo> AllInfoList = new List <CategoriesInfo>(); motor.ClearCommandParameters(); motor.CommandText = GetSelectCommand() + " where 1=1 "; List <DbParameter> paramList = new List <DbParameter>(); string where = ""; foreach (DataFilterExpressionDB filter in filterExpression) { DbParameter param = motor.Command.CreateParameter(); param.ParameterName = "@param_" + filter.FieldName; param.Value = filter.Filter; param.DbType = HelperDBType.GetDBType(typeof(CategoriesInfo), filter.FieldName); if (filter.FilterType == DataFilterExpressionDB._FilterType.Equal) { param.Value = filter.Filter; where += string.Format(" and Categories.{0} = {1}", filter.FieldName, param.ParameterName); } else { param.Value = "%" + filter.Filter + "%"; where += string.Format(" and Categories.{0} like {1}", filter.FieldName, param.ParameterName); } paramList.Add(param); } motor.CommandText += where; motor.AddCommandParameters(paramList); DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(CategoriesInfo), dbReader); using (dbReader) { while (dbReader.Read()) { CategoriesInfo classInfo = new CategoriesInfo(); classFiller.Fill(classInfo); AllInfoList.Add(classInfo); } } return(AllInfoList); }
/// <summary> /// Performs one "Select * from MyTable". Use wisely. /// </summary> /// <returns>List of found records.</returns> public virtual List <CategoriesInfo> GetAll() { List <CategoriesInfo> AllInfoList = new List <CategoriesInfo>(); motor.CommandText = GetSelectCommand(); DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(CategoriesInfo), dbReader); using (dbReader) { while (dbReader.Read()) { CategoriesInfo classInfo = new CategoriesInfo(); classFiller.Fill(classInfo); AllInfoList.Add(classInfo); } } return(AllInfoList); }
/// <summary> /// Same as get all but filter the result set /// </summary> /// <param name="numberOfRowsToSkip">Skip first X rows</param> /// <param name="numberOfRows">Like "TOP" in sql server</param> /// <returns></returns> public List <CategoriesInfo> GetAll(int numberOfRowsToSkip, int numberOfRows) { List <CategoriesInfo> AllInfoList = new List <CategoriesInfo>(); motor.CommandText = base.GetFilteredRowNumAndSkipQuery("AttributeLists", "id", numberOfRowsToSkip, numberOfRows); DbDataReader dbReader = motor.ExecuteReader(); ClassFiller classFiller = new ClassFiller(typeof(CategoriesInfo), dbReader); using (dbReader) { while (dbReader.Read()) { CategoriesInfo classInfo = new CategoriesInfo(); classFiller.Fill(classInfo); AllInfoList.Add(classInfo); } } return(AllInfoList); }
/// <summary> /// Delete registers based on class values informed. MinValues and nulls are skipped. /// </summary> /// <param name="parCategoriesInfo">Item to delete</param> /// <param name="errorMessage">Error message</param> public virtual void Delete(CategoriesInfo parCategoriesInfo, out string errorMessage) { errorMessage = string.Empty; //1) Start the transaction context. DbTransaction transaction = motor.BeginTransaction(); //2) Call the overload of this method, which call the DAO but does not commit. this.Delete(parCategoriesInfo, transaction, out errorMessage); //3) Commit the transaction. motor.Commit(); //4) Close the conection (if configured to do so). if (this.closeConnectionWhenFinish) { motor.CloseConnection(); } }
/// <summary> /// Perform a search to find the class "CategoriesInfo" using as key the field "Categories". /// </summary> /// <param name="parProductsInfo">Main class that contains the aggregation.</param> /// <returns>Foreing key attched class.</returns> public virtual CategoriesInfo Get_CategoryIDID_FKCategories(ProductsInfo parProductsInfo, DbTransaction transaction) { CategoriesInfo filter = new CategoriesInfo(); filter.CategoryName = parProductsInfo.FK1_CategoryName; CategoriesBsn myClass = new CategoriesBsn(false, this.motor); List <CategoriesInfo> list = myClass.GetSome(filter); if (list.Count == 0) { //This error occurs when try to search for the ID in one table, but it does not find the value. //Ex.: Select id,SomeField from myTable where SomeField='myValue') If no data return, this error will trigger. throw new Exception(string.Format("Can not define ID for parProductsInfo.", parProductsInfo.FK1_CategoryName)); /* [Hint] The code below do one insert in the table "Categories" informing only the "CategoryID" field. * [Warning] The code may crash if other fields are necessary. * [Instructions] Comment the exception above. Uncomment the code below. */ //string errorMsg = string.Empty; //myClass.InsertOne(filter, transaction, out errorMsg); //if (errorMsg != string.Empty) //{ //throw new Exception(errorMsg); //} //else //{ //return filter; //} } if (list.Count > 1) { //This error occurs when try to search for the ID in one table, but it return more then one value. //Ex.: Select id,SomeField from myTable where SomeField='myValue') If more then one line return, this error will trigger. throw new Exception(string.Format("Can not define ID for parProductsInfo. Theres more then one ID value for this field. ", parProductsInfo.FK1_CategoryName)); } else { //Return the only one class found. return(list[0]); } }
public void TryUpdate(UpdateCategoriesView viewToUpdate, out RestExceptionError error) { error = null; CategoriesInfo dbViewToInclude = new CategoriesInfo(); try { Cloner.CopyAllTo(typeof(UpdateCategoriesView), viewToUpdate, typeof(CategoriesInfo), dbViewToInclude); } catch (Exception ex) { error = new RestExceptionError(); error.InternalMessage = "Internal Error parsing data for (Categories.TryUpdate/Parsing)"; error.ExceptionMessage = ex.Message; error.SourceError = RestExceptionError._SourceError.ServerSide; error.StackTrace = ex.StackTrace; } try { CategoriesBsn bsn = new CategoriesBsn(restConfig); string dbError = null; bsn.UpdateOne(dbViewToInclude, out dbError); if (dbError != null) { error = new RestExceptionError(); error.InternalMessage = "Internal Error Save data for [Categories.TryUpdate]"; error.ExceptionMessage = dbError; error.SourceError = RestExceptionError._SourceError.ServerSide; error.StackTrace = ""; } } catch (Exception ex) { error = new RestExceptionError(); error.InternalMessage = "Internal Error Update data for [Categories.TryUpdate]"; error.ExceptionMessage = ex.Message; error.SourceError = RestExceptionError._SourceError.ServerSide; error.StackTrace = ex.StackTrace; } }
/// <summary> /// Performs one "update" database command in a transactional context. /// * The method uses a transaction object already created and does not close the connection. /// * Must have "MultipleActiveResultSets=True" on connection string. /// </summary> /// <param name="ProductsInfo">Object to update.</param> /// <param name="transaction">Inform "DBTransaction".</param> /// <param name="errorMessage">Error message if exception is throwed.</param> public virtual void UpdateOne(ProductsInfo parProductsInfo, DbTransaction transaction, out string errorMessage) { errorMessage = string.Empty; //If is trying to insert FKValue without the ID but has the unique description, //the system will try to get the class with the ID and populate it. if ((parProductsInfo.SupplierID == null) && (parProductsInfo.FK0_CompanyName != null)) { SuppliersInfo fkClass = Get_SupplierIDID_FKSuppliers(parProductsInfo, transaction); parProductsInfo.SupplierID = fkClass.SupplierID; } if ((parProductsInfo.CategoryID == null) && (parProductsInfo.FK1_CategoryName != null)) { CategoriesInfo fkClass = Get_CategoryIDID_FKCategories(parProductsInfo, transaction); parProductsInfo.CategoryID = fkClass.CategoryID; } ProductsDAO.UpdateOne(parProductsInfo, transaction, out errorMessage); //By default, the caller of this method will do the commit. //motor.Commit(); //motor.CloseConnection(); }
public async Task OnNavigatedToAsync(object parameter) { Error = false; Loading = true; var cat = parameter as string; if (cat == null) { cat = "ogolne"; } if (cat != catInfo.Slug || allNewses.Count == 0) { catInfo = CategoriesInfo.GetBySlug(cat); Header = catInfo.Name; await LoadNewsesAsync(); } else if (allNewses.Count > 0) { FilterNewses(selectedProvince); } Loading = false; }
public MeteoViewModel() : base() { catInfo = CategoriesInfo.GetBySlug("meteorologiczne"); }
public StanyWodViewModel() : base() { catInfo = CategoriesInfo.GetBySlug("stany-wod"); }
public OgolneViewModel() : base() { catInfo = CategoriesInfo.GetBySlug("ogolne"); }
public HydroViewModel() : base() { catInfo = CategoriesInfo.GetBySlug("hydrologiczne"); }
public DrogoweViewModel() : base() { catInfo = CategoriesInfo.GetBySlug("informacje-drogowe"); }