public virtual BangoCommand GetGridFilterItemsCommand(DbConnect con, DynamicDictionary data_param, int page = -1, int pageSize = 20, string sort_by = null, bool count = false) { sort_by = sort_by == null ? string.Empty : sort_by; ComboFieldsAttribute comboAttrib = _model.GetComoFields(); if (sort_by.Trim().Length == 0 && comboAttrib.OrderBy.Length > 0) { sort_by = DbServiceUtility.SetColumnAlias(TableDetail.Alias, comboAttrib.OrderBy); } BangoCommand cmd = GetGridFilterItemsCommandTemplate(comboAttrib.ToString(), count, TableDetail.Alias); cmd = GetSearchCommand(SearchScenario.GridFilter, con, cmd, data_param, comboAttrib.ToString() , sort_by, page, pageSize, count, TableDetail.Alias); //adding the query clause string or_query = string.Empty; Dapper.DynamicParameters param = new Dapper.DynamicParameters(); if (data_param.ContainsKey("q") || data_param.ContainsKey("query")) { string query = data_param.GetValueAsString("q"); if (query.Trim().Length == 0) { query = data_param.GetValueAsString("query"); } AppendQueryAsOr(cmd, query, new string[] { "code", "name_np", "name_en" }); } return(cmd); }
public virtual ResponseAuth Authenticate(DynamicDictionary data_param) { int client_id = (int)data_param.GetValueAsInt("client_id"); string username = data_param.GetValueAsString("username"); string password = data_param.GetValueAsString("password"); return(Authenticate(client_id, username, password)); }
public override ResponseModel Insert(DbConnect con, DynamicDictionary item) { UserModel model = new UserModel(); //setting the client_id before inserting record if client_id field exists. if(model.GetType().GetProperty("client_id") != null) { if (item.GetValueAsInt("client_id") == null) { item.Add("client_id", SessionData.client_id); } else { item.Add("client_id", item.GetValueAsInt("client_id")); } } string new_file_name = item.GetValueAsString("new_file_name"); if (new_file_name != "") { string reltive_path = "temp/"; item.SetValue("photo_path", reltive_path + new_file_name); } ResponseModel resp = base.Insert(con, item); if (resp.success) { int user_id = (int)((DynamicDictionary)resp.data).GetValueAsInt("id"); resp.data = user_id; return(resp); } return(resp); }
public List <string> GetDistinctValues(List <DynamicDictionary> DataSource, string column1, string column2, bool sort = true) { List <string> arr = new List <string>(); List <string> newArr = new List <string>(); for (int i = 0, len = (int)DataSource?.Count; i < len; i++) { DynamicDictionary row = DataSource[i]; string s = row.GetValueAsString(column2) + row.GetValueAsString(column1); if (!arr.Contains(s)) { arr.Add(s); } } arr.Sort(); return(arr); }
public virtual BangoCommand GetSearchCommand(SearchScenario scenario, DbConnect con, BangoCommand cmd, DynamicDictionary data_param, string selectClause, string orderByClause, int page = -1, int pageSize = 20, bool count = false, string tableAlias = null, string scenarioOthers = null) { TableDetailAttribute tableDetail = _model.GetTableDetail(); //clear the params whic are empty or null List <string> keys = new List <string>(data_param.KeyList.Cast <String>()); foreach (string key in keys) { object value = data_param.GetValue(key); if (value == null || data_param.GetValueAsString(key).Length == 0) { data_param.Remove(key); } } //BangoCommand cmd = GetSearchCommandTemplate(selectClause, count, tableAlias); //cmd.Sql.AppendLine("FROM " + model.GetTableName()); IDbExpression dbExp = App.Container.GetInstance <IDbExpression>(); if (data_param.GetCount() == 0) { return(cmd); } string append = DbServiceUtility.GetTableAliasForColumn(tableAlias); if (!(scenario == SearchScenario.TreeNode && count == false)) { //check & adding delete flag check sql DbServiceUtility.BindDeleteParameter(cmd, _model, tableAlias); if (CheckClientID) { DbServiceUtility.BindClientIdParameter(cmd, _model, tableAlias, DisplayMasterDataFromSystem); } //add remaining default search criteria cmd = BeforeBindingParameter(scenario, con, cmd, data_param, count, tableAlias); cmd = DbServiceUtility.BindParameters(cmd, _model, data_param, tableAlias); cmd = AfterBindingParameter(scenario, con, cmd, data_param, count, tableAlias); //check & adding order by clause if (count == false) { cmd = BeforeBindingOrderBy(scenario, con, cmd, data_param, count, tableAlias); cmd = DbServiceUtility.BindOrderBy(cmd, orderByClause); cmd = AfterBindingOrderBy(scenario, con, cmd, data_param, count, tableAlias); cmd = DbServiceUtility.BindPagination(cmd, page, pageSize); } } return(cmd); }
//Func<DbConnect, DynamicDictionary, int> fun = null) public virtual ResponseModel Save(DbConnect con, DynamicDictionary item, TKey id, SaveCallBackDelegate fun = null) { ResponseModel resp = new ResponseModel(); resp.success = false; Errors.Clear(); List <DynamicDictionary> items = Conversion.ToDictionaryListFromJson(item.GetValueAsString(ItemsAddedFieldName)); //get Add Data resp = BatchInsert(con, items, id, fun); if (!resp.success) { resp.message = "Error while adding records/items."; return(resp); } items.Clear(); items = Conversion.ToDictionaryListFromJson(item.GetValueAsString(ItemsModifiedFieldName)); //get Add Data resp = BatchUpdate(con, items, id, fun); if (!resp.success) { resp.message = "Error while updating records/items."; return(resp); } items.Clear(); items = Conversion.ToDictionaryListFromJson(item.GetValueAsString(ItemsDeletedFieldName)); //get Add Data resp = BatchDelete(con, items, fun); if (!resp.success) { resp.message = "Error while deleting records/items."; return(resp); } resp.success = true; resp.message = "Records saved successfully."; return(resp); }
//Client name start public virtual string LoadClientName(DbConnect con, int client_id) { DynamicDictionary list = DbServiceUtility.ExecuteItem(con, GetClientNameQuery(client_id).ToString()); if (list == null) { return(null); } var clientName = list.GetValueAsString("client_name"); if (clientName == null) { return(null); } return(clientName); }
public virtual BangoCommand GetComboItemsCommand(DbConnect con, DynamicDictionary data_param, int page = -1, int pageSize = 20, string sort_by = null, bool count = false) { sort_by = sort_by == null ? string.Empty : sort_by; ComboFieldsAttribute comboAttrib = _model.GetComoFields(); if (sort_by.Trim().Length == 0 && comboAttrib.OrderBy.Length > 0) { sort_by = DbServiceUtility.SetColumnAlias(TableDetail.Alias, comboAttrib.OrderBy); } BangoCommand cmd = GetCombotItemsCommandTemplate(comboAttrib.ToString(), count, TableDetail.Alias); if (comboAttrib.Status != null || comboAttrib.Status.Length > 0) { data_param.Add(comboAttrib.Status, true); //for Combo Status=True mains Active Recors load in ComboBOx } cmd = GetSearchCommand(SearchScenario.Combo, con, cmd, data_param, comboAttrib.ToString() , sort_by, page, pageSize, count, TableDetail.Alias); //adding the query clause string or_query = string.Empty; Dapper.DynamicParameters param = new Dapper.DynamicParameters(); if (data_param.ContainsKey("query")) { string query = data_param.GetValueAsString("query"); if (query != null && query.Trim().Length > 0) { var q = query; string[] arr = q.Split('-'); string searchParams = arr[0].ToString().Trim(); //string name = arr[1].ToString(); AppendQueryAsOr(cmd, searchParams, new string[] { "code", "name_np", "name_en" }); } else { AppendQueryAsOr(cmd, query, new string[] { "code", "name_np", "name_en" }); } //query = data_param.GetValueAsString("query"); } return(cmd); }
public virtual string LoadPhotoURL(DbConnect con, int user_id) { DynamicDictionary list = DbServiceUtility.ExecuteItem(con, GetPhotoPathQuery(user_id).ToString()); if (list == null) { return(null); } var photoPath = list.GetValueAsString("name_photo_url"); if (photoPath == null) { return(null); } string[] formatedPhotoPath = photoPath.Split('\\'); string absolutePhotoPath = string.Join("/", formatedPhotoPath); return(absolutePhotoPath); }
public virtual async Task <IResponseReport> GetListExportPdf(DynamicDictionary data_param, string reportType, string reportName, string sort_by, IReportBase report = null) { ReponseReport resp = new ReponseReport(false, string.Empty); try { IEnumerable <dynamic> items = null; int total = 0; DynamicDictionary copy = (DynamicDictionary)data_param.Clone(); Dictionary <string, object> officeInfo; string JsonData, JsonOfficeInfo; officeInfo = report.GetOfficeInfo(); officeInfo.Add("current_user", SessionData.user_name); foreach (KeyValuePair <string, object> item in data_param) { string k = item.Key; object v = item.Value; officeInfo.Add(k, v); } using (DbConnect con = new DbConnect()) { total = SearchRepo.GetSearchItemsCount(con, copy, -1, 1); if (total > 0) { items = SearchRepo.GetSearchItems(con, data_param, -1, 1, sort_by); IList <dynamic> list = (IList <dynamic>)items; if (list == null) { resp.isData = false; } } } if (Errors.Count > 0) { resp.message = "Grid filter data load failed."; resp.PushErrors(Errors); } else { resp.success = true; if (total > 0 && items != null && items.Count() > 0) { JsonData = Newtonsoft.Json.JsonConvert.SerializeObject(items); if (report == null) { report = GetReportObject(); } JsonOfficeInfo = Newtonsoft.Json.JsonConvert.SerializeObject(officeInfo); string reportTitle = data_param.GetValueAsString("reportTitle"); report.ReportData = "{\"items\":" + JsonData + ",\"info\":" + JsonOfficeInfo + ",\"title\":" + "\"" + reportTitle + "\"" + "}"; bool status = await report.GenerateReport(reportType, reportName); if (status) { resp.success = true; resp.report_url = report.GeneratedFileUrl; resp.report_name = report.GeneratedFileName; } else { resp.message = report.Error; } } else { resp.message = "Grid filter data not found as per search condition"; } } } catch (Exception ex) { } return(resp); }
/// <summary> /// Performs validation of unique-constraints. Detail on the failure are stored in UniqueErrors Property /// It will use the help of TModel for performing the unique-constraint check. /// </summary> /// <param name="item"></param> /// <returns>Returns the status of the validation.</returns> public virtual bool ValidateUniqueValue(DbConnect con, DynamicDictionary item, IModel validatorModel, bool skipFieldsNotProvided = false) { /** * TODO * 1) disable null check or check if unique constraint is not composite constraint * 2) check unique constraint in edit mode, load all data **/ PropertyInfo key = validatorModel.GetKeyPropertyInfo(); TKey id = item.GetValue <TKey>(key.Name); //if (Conversion.ToInt32(id.ToString()) > 0) // skipFieldsNotProvided = false; //if edit mode checke if (validatorModel.GetType().GetProperty("deleted_uq_code") != null) //tod not equal.. { item["deleted_uq_code"] = 1; } BangoCommand cmd = new BangoCommand(commandType: MyroCommandTypes.StringBuilder); string union = string.Empty; //List<PropertyInfo> uniqueFields = new List<PropertyInfo>(); DictionaryFx <string, PropertyInfo> uniqueFields = new DictionaryFx <string, PropertyInfo>(); //preparing sql DynamicDictionary data_param = null; Bango.Models.Attributes.TableDetailAttribute tabelDetail = validatorModel.GetTableDetail(); foreach (KeyValuePair <string, UniqueConstraint> unique in validatorModel.UniqueFields) { if (unique.Value.Fields.Count == 0) { continue; } bool value_not_provided = false; foreach (string fld in unique.Value.Fields) { if (!item.ContainsKey(fld)) { //1) disable null check or check if unique constraint is not composite constraint ///if (unique.Value.Fields.Count <= 1) if (unique.Value.Fields.Count <= 1) //TODO:Shivashwor modify... for client duplicate data insert OFF... { value_not_provided = true; break; } if (!skipFieldsNotProvided) { //If fld name not exists in validatorModel then if (validatorModel.GetValue(fld) == null) { ///item.Add(fld, null); value_not_provided = true; } else { Type t = validatorModel.GetType().GetProperty(fld).PropertyType; if (t.IsValueType) { item.Add(fld, Activator.CreateInstance(t)); } else { item.Add(fld, null); } } } else { //TODO:Shivashwor modify... for client duplicate data insert OFF... value_not_provided = true; } break; } } if (value_not_provided) { continue; } data_param = (DynamicDictionary)item.Clone(); ///TODO:SHIVASHWOR 15 nov 2015 for Unique value is empty or not... object data_val = data_param.GetValue(unique.Key); if (data_val != null) { if (data_val.ToString().Trim().Length == 0) { continue; } } if (union.Length > 0) { cmd.SqlString.AppendLine(union); } string and = string.Empty; cmd.SqlString.AppendLine(String.Format("SELECT distinct '{0}' unique_constraint, '{2}' error_message FROM {1} {3} WHERE 1=1 " , DbServiceUtility.SafeDBString(unique.Value.Name), tabelDetail.Name , DbServiceUtility.SafeDBString(unique.Value.ErrorMessage) , tabelDetail.Alias)); //CHECKING In if client_id exists in the model for adding the client_id in unique contraint check if the developer has forgot to added PropertyInfo prop_client_id = validatorModel.GetType().GetProperty("client_id"); if (prop_client_id != null) { if (!unique.Value.Fields.Contains("client_id")) { unique.Value.Fields.Add("client_id"); } } foreach (string fld in unique.Value.Fields) { if (validatorModel.GetType().GetProperty(fld) != null) { DbServiceUtility.BindParameter(cmd, fld, data_param, validatorModel.GetType().GetProperty(fld).PropertyType, tabelDetail.Alias, SearchTypes.Equal | SearchTypes.CaseSensetive, string.Empty, true, validatorModel.GetType().GetProperty(fld)); } //cmd.SqlString.AppendFormat(" {1} {0} = @{0}", fld, and);//uniqueFields[fld] = validatorModel.GetType().GetProperty(fld); } if (key.Name.Trim().Length > 0)//PRIMARY KEY Check if n { if (id != null) { //var obj_updateBy = data_param.GetValue("updated_by"); //if (obj_updateBy!= null) DbServiceUtility.BindParameter(cmd, key.Name, data_param, System.Data.DbType.Int32, tabelDetail.Alias, SearchTypes.NotEqual, string.Empty, true, key); } } union = " UNION ALL"; } string finalSql = cmd.FinalSql; IEnumerable <dynamic> lst = null; if (finalSql.Length > 0) { try { lst = con.DB.Query <dynamic>(finalSql, cmd.FinalParameters); } catch (NpgsqlException ex) { Errors.Add(ex.ToString()); LogTrace.WriteErrorLog(ex.ToString()); LogTrace.WriteDebugLog(string.Format("sql which gave exception:\r{0}", ex.Routine)); return(false); } catch (Exception ex) { } //checking for the unique constraint if (lst.Count() > 0) { foreach (DapperRow dr in lst) { DynamicDictionary dic = Conversion.ToDynamicDictionary(dr); DynamicDictionary err = new DynamicDictionary(); err.Add(dic.GetValueAsString("unique_constraint"), dic.GetValue("error_message")); ModelService.PushValidationErros(err, ValidationErrors); } return(false); } } else { //TODO:Shivashwor 01 Nov 2015/ //if edit mode nothing changed after save data occurs // throw new NoSqlStringProvidedException(); } return(true); }
public List <DynamicDictionary> PivotTheData(List <DynamicDictionary> sourceData) { DynamicDictionary disc = sourceData[0]; string mov = disc.GetValueAsString("mov").ToUpper().Trim(); try { SummaryOfData.Clear(); //manage or prepare distict of the values double val = 0; string valx = string.Empty, valy = string.Empty; for (int i = 0, len = sourceData.Count; i < len; i++) { valx = sourceData[i].GetValueAsString(ColumnX.Name1); valy = sourceData[i].GetValueAsString(ColumnY.Name2) + sourceData[i].GetValueAsString(ColumnY.Name1); val = sourceData[i].GetValue <Double>(ColumnValue); PivotData pd = GetPivotData(valx, valy); pd.Value = CalculateSummary(pd.Value, val); } List <DynamicDictionary> dt = FinalPivotDictionary; double tot = 0; //now put the data in DataTable foreach (string y in yKeys) { if (y.Trim().Length == 0) { continue; } IEnumerable <PivotData> yRows = SummaryOfData.Where(d => d.ValueY == y); DynamicDictionary dr = new DynamicDictionary(); //prepare the row/record dr[ColumnY.Name1] = y; PivotValue pv_y = SummaryOfY[y]; foreach (PivotData pd in yRows) { val = GetCellData(pd.Value, ColumnY.SummaryGroupFunction); dr[pd.ValueX] = val; //calculate summary of Y pv_y = CalculateSummary(pv_y, val); } foreach (string x in xKeys) { if (!dr.ContainsKey(x)) { dr[x] = string.Empty; } } tot = GetCellData(pv_y, ColumnY.SummaryGroupFunction); dr[ColumnY.SummaryLabel] = tot; // dt.Add(dr); //also calculating the grand total GrandTotal += tot; //Calculate total for arr and dep if (mov == "DEP") { DepTotal = GrandTotal; } else { ArrTotal = GrandTotal - DepTotal; } } DepTotal = GrandTotal; //calculate the summary of X if (ColumnY.CalculateSummary) { DynamicDictionary dr = new DynamicDictionary(); dr[ColumnY.Name1] = ColumnX.SummaryLabel; foreach (string x in xKeys) { IEnumerable <PivotData> xRows = SummaryOfData.Where(d => d.ValueX == x); PivotValue pv_x = SummaryOfX[x]; foreach (PivotData pd in xRows) { pv_x = CalculateSummary(pv_x, GetCellData(pd.Value, ColumnX.SummaryGroupFunction)); } dr[x] = GetCellData(pv_x, ColumnX.SummaryGroupFunction); } if (ColumnX.CalculateSummary) { dr[ColumnX.SummaryLabel] = mov == "ARR" ? ArrTotal : DepTotal; } dt.Add(dr); } return(dt); } catch (Exception ex) { } return(null); }
public async Task <HttpResponseMessage> PostFile() { // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } string temp_root = FileBox.GetWebAppRoot() + "temp\\" + SessionData.client_id + "\\"; string temp_url = "//temp//" + SessionData.client_id + "//"; if (!System.IO.Directory.Exists(temp_root)) { System.IO.Directory.CreateDirectory(temp_root); } MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(temp_root); DynamicDictionary data = new DynamicDictionary(); ResponseModel resp = new ResponseModel(false, data); try { StringBuilder sb = new StringBuilder(); // Holds the response body // Read the form data and return an async task. var bodyparts = await Request.Content.ReadAsMultipartAsync(provider); //rename the file to proper-name // This illustrates how to get the form data. foreach (var key in provider.FormData.AllKeys) { foreach (var val in provider.FormData.GetValues(key)) { data.Add(key, val); } } //for logo upload string logo_name = data.GetValueAsString("logo_name"); string extension = string.Empty; if (logo_name != "") { #region for logo upload string basePath = FileBox.GetWebAppRoot() + "filebox\\CommonInput\\logo\\" + SessionData.client_id + "\\"; if (!System.IO.Directory.Exists(basePath)) { System.IO.Directory.CreateDirectory(basePath); } //check if file already exist and delete if exist string[] Logo_path = Directory.GetFiles(basePath, logo_name + ".*"); string[] filepath = Directory.GetFiles(basePath, "*.*"); if (Logo_path.Length > 0) { System.IO.File.Delete(Logo_path[0]); } //check if file already exist and delete if exist foreach (var file in provider.FileData) { string[] arr = file.Headers.ContentDisposition.FileName.Trim('"').Split('.'); if (arr.Length >= 1) { extension = "." + arr[arr.Length - 1]; } System.IO.File.Move(file.LocalFileName, basePath + logo_name + extension); data.Add("temp_file_url", basePath + logo_name + extension); } #endregion } else { string url = HttpContext.Current.Request.Url.ToString().Substring(0, HttpContext.Current.Request.Url.ToString().IndexOf("/api/")); // This illustrates how to get the file names for uploaded files. string new_file_name = ""; // System.DateTime.Today.ToString("yyyymmddhhmmss") + "_" + getRandomID() + "_" + SessionData.user_id; foreach (var file in provider.FileData) { FileInfo fileInfo = new FileInfo(file.LocalFileName); string[] arr = file.Headers.ContentDisposition.FileName.Trim('"').Split('.'); if (arr.Length >= 1) { extension = "." + arr[arr.Length - 1]; } new_file_name = fileInfo.Name; if (data.ContainsKey("temp_file_path")) { data.SetValue("temp_file_path", temp_root + new_file_name + extension); } else { data.Add("temp_file_path", temp_root + new_file_name + extension); } if (data.ContainsKey("file_name")) { data.SetValue("file_name", new_file_name + extension); } else { data.Add("file_name", new_file_name + extension); } //mime_type_id if (data.ContainsKey("mime_type_id")) { data.SetValue("mime_type_id", extension); } else { data.Add("mime_type_id", extension); } if (data.ContainsKey("file_size_bytes")) { data.SetValue("file_size_bytes", fileInfo.Length); } else { data.Add("file_size_bytes", fileInfo.Length); } data.Add("temp_file_url", url + temp_url + new_file_name + extension); data.Add("temp_file_url", temp_url + new_file_name + extension); System.IO.File.Move(file.LocalFileName, temp_root + new_file_name + extension); } } resp.success = true; resp.message = "File uploaded successfully"; return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(resp)) }); } catch (System.Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } }
public override ResponseModel Update(int?id, DynamicDictionary item) { string message = string.Empty; bool success = false; object data = item; ResponseModel resp = new ResponseModel(); UserModel Model = new UserModel(); LoadItemAfterSave = true; using (DbConnect con = new DbConnect()) { con.DB.BeginTransaction(); try { string new_file_name = item.GetValueAsString("new_file_name"); string user_file_name = item.GetValueAsString("userfilename"); string relative_path = "temp/"; if (user_file_name == null) { if (new_file_name != null) { item.SetValue("photo_path", relative_path + new_file_name); } } else { if (new_file_name != "") { item.SetValue("photo_path", relative_path + new_file_name); } else { item.SetValue("photo_path", ""); string filePath = FileBox.GetWebAppRoot(); if (System.IO.File.Exists(filePath + user_file_name)) //if file exists than delete. { System.IO.File.Delete(filePath + user_file_name); } } } if (SessionData.client_id == 1) { CheckClientID = false; } resp = base.Update(id, item); #region User Profile Window if (resp.success && item.GetValueAsString("userProfile") == "true") { string file_name = item.GetValueAsString("new_file_name"); string filePath = FileBox.GetWebAppRoot() + "temp/"; int? photo_id = item.GetValueAsInt("photo_id"); if (file_name == "") { var photoPath = item.GetValueAsString("user_file_name"); if (photoPath == "") { return(null); } if (System.IO.File.Exists(filePath + new_file_name)) //if file exists than delete. { System.IO.File.Delete(filePath + new_file_name); } int?tax_photo_id = item.GetValueAsInt("photo_id"); item.SetValue("photo_path", ""); resp = base.Update(id, item); } else { if (photo_id == 0) { item.SetValue("photo_path", relative_path + new_file_name); } else { item.SetValue("photo_path", relative_path + new_file_name); } resp = base.Update(id, item); } } #endregion else { } if (resp.success) { con.DB.CommitTransaction(); message = "Data added successfully."; success = true; if (resp.success) { DynamicDictionary respdata = (DynamicDictionary)resp.data; string confirmpassword = respdata.GetValueAsString("confirmpassword"); if (item.GetValueAsString("userProfile") == "" || item.GetValueAsString("userProfile") == null) { if (confirmpassword == "" || confirmpassword == null) { int user_id = (int)((DynamicDictionary)resp.data).GetValueAsInt("id"); resp.data = user_id; return(resp); } } } return(resp); } else { con.DB.RollbackTransaction(); if (resp.validation_errors.GetCount() > 0) { message = string.Join(",", resp.error_code); } else { message = "Data add failed, please try again later."; } } } catch (Exception) { con.DB.RollbackTransaction(); message = "Data add failed, Rollback Transaction."; } } return(new ResponseModel(success, item.GetValue("photo_id"), message)); }
public ResponseAuth AuthenticateUserNamePasword(DbConnect con, int client_id, string username, string password) { ResponseAuth resp = new ResponseAuth(); string template = @" SELECT id, client_id, username, password, name_en, name_np,email, status FROM rbac_user u /**where**/ AND u.status=true AND u.is_deleted=false"; //creating command & preparing command string alias = DbServiceUtility.GetTableAliasForTable("u"); BangoCommand cmd = new BangoCommand(MyroCommandTypes.SqlBuilder); cmd.Template = cmd.SqlBuilder.AddTemplate(template); UserModel mdl = new UserModel(); DbServiceUtility.BindDeleteParameter(cmd, mdl, alias); DynamicDictionary data_param = new DynamicDictionary(); data_param.Add("client_id", client_id); data_param.Add("username", username); DbServiceUtility.BindParameters(cmd, mdl, data_param, alias, SearchTypes.Equal); //executing the command string finalSql = cmd.FinalSql; if (finalSql.Length > 0) { IEnumerable <SqlMapper.DapperRow> items = null; try { items = con.DB.Query <SqlMapper.DapperRow>(finalSql, cmd.FinalParameters, true); } catch (Npgsql.NpgsqlException ex) { LogTrace.WriteErrorLog(ex.ToString()); LogTrace.WriteDebugLog(string.Format("Select SQL which gave exception:\r{0}", ex.Routine)); } Errors = con.DB.GetErros(); if (items != null && items.Count() > 0) { DynamicDictionary data = Conversion.ToDynamicDictionary(items.FirstOrDefault()); if (data.GetValueAsString("password") == EncryptPassword(password)) { resp.success = true; resp.user_id = data.GetValueAsInt("id"); resp.email = data.GetValueAsString("email"); resp.message = "Login successfull"; } else { resp.message = "Username and/or Password is invalid."; } } else { if (Errors.Count > 0) { resp.message = "Technical Problem occurred."; } else { resp.message = "Please provide a valid Username."; } } } return(resp); }