Exemple #1
0
        public JsonResult Get()
        {
            int    totalRows = 0;
            string exception = "Ok";
            bool   rezult    = true;
            object rows      = new { };

            try
            {
                rows = dbList(ref totalRows);
            }

            catch (Exception ex)
            {
                rezult    = false;
                exception = ex.Message;
                Console.WriteLine(ex.Message);
                rows = new {
                    message = exception
                };
                GIxUtils.Log(ex);
            }

            return(new JsonResult(new
            {
                success = rezult,
                message = exception,
                code = 0,
                total = totalRows,
                data = rows
            })); //, new JsonSerializerOptions { PropertyNamingPolicy = null }
        }
Exemple #2
0
        public JsonResult Delete()
        {
            int    totalRows = 0;
            string exception = "Ok";
            bool   rezult    = true;
            object rows      = new { };

            try
            {
                rows = dbGetList(ref totalRows);
            }
            catch (Exception ex)
            {
                rezult    = false;
                exception = ex.Message;
                Console.WriteLine(ex.Message);
                rows = new
                {
                    message = exception
                };
                GIxUtils.Log(ex);
            }

            return(new JsonResult(new
            {
                success = rezult,
                message = exception,
                code = 0,
                total = totalRows,
                data = rows
            }));
        }
        public JsonResult Get()
        {
            int    totalRows     = 0;
            bool   rezult        = true;
            string rezultMessage = string.Empty;
            object rows          = new { };

            try
            {
                rows = dbList(ref totalRows);
            }
            catch (TokenExpiredException ex)
            {
                rezult        = false;
                rezultMessage = "Token has expired";
                GIxUtils.Log(ex);
            }
            catch (SignatureVerificationException ex)
            {
                rezult        = false;
                rezultMessage = "Token has invalid signature";
                GIxUtils.Log(ex);
            }
            catch (Exception ex)
            {
                rezult        = false;
                rezultMessage = ex.Message;
                GIxUtils.Log(ex);
            }

            return(new JsonResult(new
            {
                success = rezult,
                code = 0,
                message = rezultMessage,
                total = totalRows,
                data = rows
            }));;
            //var rng = new Random();
            //return new JsonResult( new { success = true, status = "success",  Data = Enumerable.Range(1, 5).Select(index => new WeatherForecast
            //{
            //    Date = DateTime.Now.AddDays(index),
            //    TemperatureCC = rng.Next(-20, 55),
            //    Summary = Summaries[rng.Next(Summaries.Length)]
            //}) });

            /*
             * var rng = new Random();
             * return Enumerable.Range(1, 5).Select(index => new WeatherForecast
             * {
             *  Date = DateTime.Now.AddDays(index),
             *  TemperatureCC = rng.Next(-20, 55),
             *  Summary = Summaries[rng.Next(Summaries.Length)]
             * })
             * .ToArray();
             */
        }
        public JsonResult Put(string userId, string activationToken, string newpassword, string repassword)
        {
            int    totalRows = 0;
            string exception = "Ok";
            bool   rezult    = true;
            object rows      = new { };

            try
            {
                var options = new JsonSerializerOptions
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                    WriteIndented        = true
                };
                UserModel user = new UserModel()
                {
                    ActivationToken = Request.Form["ActivationToken"],
                    UserId          = Convert.ToInt32(Request.Form["UserId"]),
                    NewPassword     = Request.Form["NewPassword"],
                    RePassword      = Request.Form["RePassword"]
                };//JsonSerializer.Deserialize<UserModel>(vs, options);
                rows = dbSetUserUser(user, ref totalRows);
            }
            catch (TokenExpiredException ex)
            {
                rezult    = false;
                exception = ex.Message;
                GIxUtils.Log(ex);
            }
            catch (SignatureVerificationException ex)
            {
                rezult    = false;
                exception = ex.Message;
                GIxUtils.Log(ex);
            }
            catch (Exception ex)
            {
                rezult    = false;
                exception = ex.Message;
                Console.WriteLine(ex.Message);
                rows = new
                {
                    message = exception
                };
                GIxUtils.Log(ex);
            }

            return(new JsonResult(new
            {
                success = rezult,
                message = exception,
                code = 0,
                total = 0,
                data = rows
            }));
        }
Exemple #5
0
        private bool dbDelete(ref int totalRecordCount)
        {
            string remoteIP    = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP     = this.HttpContext.Connection.LocalIpAddress.ToString();
            string signatureId = Request.Form["SignatureId"];


            List <dynamic>  rows            = new List <dynamic>();
            GIGridInitModel giGridInitModel = new GIGridInitModel()
            {
                ColumnList = new List <GIGridColumn>()
            };

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_DeleteSignature]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        sqlCommand.Parameters.AddWithValue("@SignatureId", signatureId);

                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        sqlCommand.ExecuteNonQuery();
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            return(true);
        }
        public JsonResult Post([FromBody] object content)
        {
            int    totalRows = 0;
            string exception = "Ok";
            bool   rezult    = true;
            object rows      = new { };

            //UserModel user = new UserModel();

            try
            {
                string vs      = content.ToString();
                var    options = new JsonSerializerOptions
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                    WriteIndented        = true
                };
                TaskModel task = JsonSerializer.Deserialize <TaskModel>(vs, options);
                rows = dbSetTask(task, ref totalRows);
            }
            catch (TokenExpiredException ex)
            {
                rezult    = false;
                exception = ex.Message;
                GIxUtils.Log(ex);
            }
            catch (SignatureVerificationException ex)
            {
                rezult    = false;
                exception = ex.Message;
                GIxUtils.Log(ex);
            }
            catch (Exception ex)
            {
                rezult    = false;
                exception = ex.Message;
                Console.WriteLine(ex.Message);
                rows = new
                {
                    message = exception
                };
                GIxUtils.Log(ex);
            }

            return(new JsonResult(new
            {
                success = rezult,
                message = exception,
                code = 0,
                total = 0,
                data = rows
            }));
        }
Exemple #7
0
        public JsonResult Get()
        {
            int    totalRows = 0;
            string exception = "Ok";
            bool   rezult    = true;
            object rows      = new { };

            try
            {
                //dynamic car = new Object();
                //car.AddProperty("TopSpeed", 180);


                rows = dbGetUserLeftMenuList(ref totalRows);
                rows = MakePlanTree(rows);
            }
            catch (TokenExpiredException ex)
            {
                rezult    = false;
                exception = ex.Message;
                GIxUtils.Log(ex);
            }
            catch (SignatureVerificationException ex)
            {
                rezult    = false;
                exception = ex.Message;
                GIxUtils.Log(ex);
            }
            catch (Exception ex)
            {
                rezult    = false;
                exception = ex.Message;
                Console.WriteLine(ex.Message);
                rows = new {
                    message = exception
                };
                GIxUtils.Log(ex);
            }

            return(new JsonResult(new { success = rezult, message = exception, records = 1, root = ".", children = rows }));

            //return new JsonResult(new
            //{
            //    success = rezult,
            //    message = exception,
            //    code = 0,
            //    total = totalRows,
            //    data = rows
            //});
        }
        public JsonResult Get()
        {
            int    totalRows = 0;
            string exception = "Ok";
            bool   rezult    = true;
            object rows      = new { };

            try
            {
                rows = dbGetClaimsList(ref totalRows);
            }
            catch (TokenExpiredException ex)
            {
                rezult    = false;
                exception = ex.Message;
                //Console.WriteLine("Token has expired");
                GIxUtils.Log(ex);
            }
            catch (SignatureVerificationException ex)
            {
                rezult    = false;
                exception = ex.Message;
                //Console.WriteLine("Token has invalid signature");
                GIxUtils.Log(ex);
            }
            catch (Exception ex)
            {
                rezult    = false;
                exception = ex.Message;
                //Console.WriteLine(ex.Message);
                rows = new
                {
                    message = exception
                };
                GIxUtils.Log(ex);
            }

            return(new JsonResult(new
            {
                success = rezult,
                message = exception,
                code = 0,
                total = totalRows,
                data = rows
            }));
        }
        public JsonResult Get()
        {
            int    totalRows = 0;
            string exception = "Ok";
            bool   rezult    = true;
            object rows      = new { };

            try
            {
                rows = dbGetUserUser(ref totalRows);
            }
            catch (TokenExpiredException ex)
            {
                rezult    = false;
                exception = ex.Message;
                GIxUtils.Log(ex);
            }
            catch (SignatureVerificationException ex)
            {
                rezult    = false;
                exception = ex.Message;
                GIxUtils.Log(ex);
            }
            catch (Exception ex)
            {
                rezult    = false;
                exception = ex.Message;
                Console.WriteLine(ex.Message);
                rows = new {
                    message = exception
                };
                GIxUtils.Log(ex);
            }

            //return new JsonResult(new { success= rezult, message = exception, records = 1, root = ".", children = rows });
            return(new JsonResult(new
            {
                success = rezult,
                message = exception,
                code = 0,
                total = totalRows,
                data = rows
            }));
        }
Exemple #10
0
        public JsonResult Get()
        {
            int    totalRows     = 0;
            bool   rezult        = true;
            string rezultMessage = string.Empty;
            object rows          = new { };

            try
            {
                rows = dbList(ref totalRows);
            }
            catch (TokenExpiredException ex)
            {
                rezult        = false;
                rezultMessage = "Token has expired";
                GIxUtils.Log(ex);
            }
            catch (SignatureVerificationException ex)
            {
                rezult        = false;
                rezultMessage = "Token has invalid signature";
                GIxUtils.Log(ex);
            }
            catch (Exception ex)
            {
                rezult        = false;
                rezultMessage = ex.Message;
                GIxUtils.Log(ex);
            }

            return(new JsonResult(new
            {
                success = rezult,
                code = 0,
                message = rezultMessage,
                total = totalRows,
                data = rows
            }));;
        }
Exemple #11
0
        private dynamic dbSetUserUser(UserModel user, ref int totalRecordCount)
        {
            bool   initGrid = Request.Query["type"].ToString() == "initGrid" ? true : false;
            string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();

            //*********************************************************
            // If new userd and needs to activate Account
            if (!string.IsNullOrWhiteSpace(user.ActivationToken))
            {
                return(dbActivateAccountToken(user, ref totalRecordCount));
            }

            UserModel model = new UserModel();

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_SetUser]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@InitGrid", initGrid);
                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        sqlCommand.Parameters.AddWithValue("@FirstName", user.FirstName);
                        sqlCommand.Parameters.AddWithValue("@LastName", user.LastName);
                        sqlCommand.Parameters.AddWithValue("@DOB", user.DOB);
                        sqlCommand.Parameters.AddWithValue("@Address", user.Address);
                        sqlCommand.Parameters.AddWithValue("@BirthPlace", user.BirthPlace);
                        sqlCommand.Parameters.AddWithValue("@PIN", user.PIN);
                        sqlCommand.Parameters.AddWithValue("@PassportNom", user.PassportNom);
                        sqlCommand.Parameters.AddWithValue("@CitizenshipId", user.CitizenshipId);
                        sqlCommand.Parameters.AddWithValue("@ContractNom", user.ContractNom);
                        sqlCommand.Parameters.AddWithValue("@DateStart", user.DateStart);
                        sqlCommand.Parameters.AddWithValue("@DateEnd", user.DateEnd);
                        sqlCommand.Parameters.AddWithValue("@StatusId", user.StatusId);
                        sqlCommand.Parameters.AddWithValue("@DepartmentId", user.DepartmentId);
                        sqlCommand.Parameters.AddWithValue("@PositionId", user.PositionId);
                        sqlCommand.Parameters.AddWithValue("@UserId", user.UserId);
                        sqlCommand.Parameters.AddWithValue("@StaffId", user.StaffId);
                        sqlCommand.Parameters.AddWithValue("@IsMed", user.IsMed == null ? false : Convert.ToBoolean(user.IsMed.ToString()));
                        sqlCommand.Parameters.AddWithValue("@IsBlocked", user.IsBlocked == null ? false : Convert.ToBoolean(user.IsBlocked.ToString()));
                        sqlCommand.Parameters.AddWithValue("@IsSales", user.IsSales == null ? false : Convert.ToBoolean(user.IsSales.ToString()));
                        sqlCommand.Parameters.AddWithValue("@Code", user.Code);
                        sqlCommand.Parameters.AddWithValue("@Permissions", user.Permissions);
                        sqlCommand.Parameters.AddWithValue("@Email", user.Email);
                        sqlCommand.Parameters.AddWithValue("@ResetOnly", user.ResetOnly);

                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            if (recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("UserId")]) != System.DBNull.Value)
                                {
                                    model.UserId = (int)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("StaffId")]) != System.DBNull.Value)
                                {
                                    model.StaffId = (int)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("FirstName")]) != System.DBNull.Value)
                                {
                                    model.FirstName = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("LastName")]) != System.DBNull.Value)
                                {
                                    model.LastName = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("DOB")]) != System.DBNull.Value)
                                {
                                    model.DOB = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Address")]) != System.DBNull.Value)
                                {
                                    model.Address = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("PIN")]) != System.DBNull.Value)
                                {
                                    model.PIN = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("PassportNom")]) != System.DBNull.Value)
                                {
                                    model.PassportNom = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("CitizenshipId")]) != System.DBNull.Value)
                                {
                                    model.CitizenshipId = (int)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Citizenship")]) != System.DBNull.Value)
                                {
                                    model.Citizenship = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("ContractNom")]) != System.DBNull.Value)
                                {
                                    model.ContractNom = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("DateStart")]) != System.DBNull.Value)
                                {
                                    model.DateStart = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("DateEnd")]) != System.DBNull.Value)
                                {
                                    model.DateEnd = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("StatusId")]) != System.DBNull.Value)
                                {
                                    model.StatusId = (int)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("StatusDescription")]) != System.DBNull.Value)
                                {
                                    model.StatusDescription = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("DepartmentId")]) != System.DBNull.Value)
                                {
                                    model.DepartmentId = (int)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("DepartmentDescription")]) != System.DBNull.Value)
                                {
                                    model.DepartmentDescription = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("PositionId")]) != System.DBNull.Value)
                                {
                                    model.PositionId = (int)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("PositionDescription")]) != System.DBNull.Value)
                                {
                                    model.PositionDescription = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Code")]) != System.DBNull.Value)
                                {
                                    model.Code = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Username")]) != System.DBNull.Value)
                                {
                                    model.Username = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("IsBlocked")]) != System.DBNull.Value)
                                {
                                    model.IsBlocked = (bool)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("IsMed")]) != System.DBNull.Value)
                                {
                                    model.IsMed = (bool)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("IsSales")]) != System.DBNull.Value)
                                {
                                    model.IsSales = (bool)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("BirthPlace")]) != System.DBNull.Value)
                                {
                                    model.BirthPlace = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Email")]) != System.DBNull.Value)
                                {
                                    model.Email = (string)value;
                                }
                            }
                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                            {
                                totalRecordCount = (int)outputValue.Value;
                            }
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            return(model);
        }
Exemple #12
0
        private dynamic dbGetList(ref int totalRecordCount)
        {
            bool   initGrid   = Request.Query["type"].ToString() == "initGrid" ? true : false;
            bool   exportGrid = Request.Query["type"].ToString() == "exportGrid" ? true : false;
            string remoteIP   = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP    = this.HttpContext.Connection.LocalIpAddress.ToString();

            string page  = Request.Query["page"].ToString();
            string start = Request.Query["start"].ToString();
            string limit = Request.Query["limit"].ToString();



            List <dynamic>  rows            = new List <dynamic>();
            GIGridInitModel giGridInitModel = new GIGridInitModel()
            {
                ColumnList = new List <GIGridColumn>()
            };

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_CallCenterGetDocList]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@InitGrid", initGrid);
                        sqlCommand.Parameters.AddWithValue("@ExportGrid", exportGrid);

                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        sqlCommand.Parameters.AddWithValue("@page", page);
                        sqlCommand.Parameters.AddWithValue("@start", start);
                        sqlCommand.Parameters.AddWithValue("@limit", limit);
                        sqlCommand.Parameters.AddWithValue("@sort", Request.Query["sort"].ToString());

                        //sqlCommand.Parameters.AddWithValue("@saxeobaId", Request.Query["saxeobaId"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@docId", Request.Query["docId"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@policyNo", Request.Query["policyNo"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@pin", Request.Query["pin"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@policyHolder", Request.Query["policyHolder"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@policyHolderParent", Request.Query["policyHolderParent"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@organizationName", Request.Query["organizationName"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@contractNom", Request.Query["contractNom"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@docCreateDateStart", Request.Query["docCreateDateStart"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@docCreateDateStart", Request.Query["docCreateDateStart"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@operatorId", Request.Query["operatorId"].ToString());

                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            while (recordSet.Read())
                            {
                                dynamic                model   = null;
                                GIGridColumn           model_c = new GIGridColumn();
                                CallCenterDocListModel model_r = new CallCenterDocListModel();
                                if (initGrid == true)
                                {
                                    model = model_c;
                                }
                                else
                                {
                                    model = model_r;
                                }

                                var properties = model.GetType().GetProperties();
                                foreach (var el in properties)
                                {
                                    string name = el.Name;
                                    value = recordSet[recordSet.GetOrdinal(name)];

                                    if (value != System.DBNull.Value)
                                    {
                                        switch (el.PropertyType.Name)
                                        {
                                        case "Int32":
                                            el.SetValue(model, (int)value);
                                            break;

                                        case "String":
                                            el.SetValue(model, (string)value);
                                            break;

                                        case "Boolean":
                                            el.SetValue(model, (bool)value);
                                            break;
                                        }
                                    }
                                }
                                if (initGrid == true)
                                {
                                    giGridInitModel.ColumnList.Add(model);
                                }
                                else
                                {
                                    rows.Add(model);
                                }
                            }

                            if (initGrid == true && recordSet.NextResult() && recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("Title")]) != System.DBNull.Value)
                                {
                                    giGridInitModel.Title = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Toolbar")]) != System.DBNull.Value)
                                {
                                    giGridInitModel.Toolbar = (string)value;
                                }
                            }

                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                            {
                                totalRecordCount = (int)outputValue.Value;
                            }
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            if (initGrid == false)
            {
                return(rows);
            }
            return(giGridInitModel);
        }
        public async Task <JsonResult> Login()
        {
            LoginRequestJson  reqObj  = new LoginRequestJson();
            LoginResponseJson respObj = new LoginResponseJson()
            {
                success = false,
                message = "",
                code    = 0,
                token   = string.Empty
            };


            try
            {
                //Request.Headers["Authorization"]
                string bearer = Request.Headers["Authorization"];
                if (Request == null || Request.Headers == null || Request.Headers.Count == 0 || string.IsNullOrWhiteSpace(Request.Headers["Authorization"]) == true)
                {
                    Response.StatusCode = StatusCodes.Status401Unauthorized;
                    object respojseObj_MissingBearer = new
                    {
                        success = false,
                        message = "Authorization header is not provided",
                        code    = -401,
                        token   = ""
                    };
                    return(new JsonResult(respojseObj_MissingBearer));
                }
                string[] bearers = bearer.Split("Bearer ");
                if (bearers == null || bearers.Length != 2)
                {
                    Response.StatusCode = StatusCodes.Status401Unauthorized;
                    object respojseObj_MissingBearer = new
                    {
                        success = false,
                        message = "Missing bearer token",
                        code    = -401,
                        token   = ""
                    };
                    return(new JsonResult(respojseObj_MissingBearer));
                }

                using (var reader = new StreamReader(Request.Body))
                {
                    string body = string.Empty;
                    body = await reader.ReadToEndAsync();

                    dynamic jbody = JsonConvert.DeserializeObject(body);

                    if (jbody == null)
                    {
                        object respojseObj_MissingBearer = new
                        {
                            success = false,
                            message = "Missing request body",
                            code    = -401,
                            token   = ""
                        };
                        return(new JsonResult(respojseObj_MissingBearer));
                    }

                    foreach (dynamic item in jbody)
                    {
                        //int rowCount = 0;
                        //foreach (dynamic col in rows)
                        {
                            string name = item.Name;
                            string val  = item.Value.ToString();
                            switch (name)
                            {
                            case  "username":
                                reqObj.username = val;
                                break;

                            case "password":
                                reqObj.password = val;
                                break;
                            }
                        }
                    }
                }

                if (reqObj == null || string.IsNullOrWhiteSpace(reqObj.username) == true || string.IsNullOrWhiteSpace(reqObj.password))
                {
                    Response.StatusCode = StatusCodes.Status401Unauthorized;
                    object respojseObj_MissingBearer = new
                    {
                        success = false,
                        message = "No credentials provided",
                        code    = -401,
                        token   = ""
                    };
                    return(new JsonResult(respojseObj_MissingBearer));
                }

                reqObj.apiKey = bearers[1];
                dbCheckAPIKey(ref reqObj, ref respObj);
                dbIssueSessionToken(ref reqObj, ref respObj);
            }
            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                Response.StatusCode = StatusCodes.Status401Unauthorized;
                object respojseObj_CheckBearer = new
                {
                    success = false,
                    message = $"{ex.Message}",
                    code    = -401,
                    token   = ""
                };
                return(new JsonResult(respojseObj_CheckBearer));
            }


            return(new JsonResult(respObj));
        }
Exemple #14
0
        private IEnumerable <dynamic> dbGetUserLeftMenuList(ref int totalRecordCount)
        {
            bool   initGrid = Request.Query["type"].ToString() == "initGrid" ? true : false;
            string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();

            string page  = Request.Query["page"].ToString();
            string start = Request.Query["start"].ToString();
            string limit = Request.Query["limit"].ToString();



            List <dynamic> rows = new List <dynamic>();

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_GetUserLeftMenuList]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@InitGrid", initGrid);
                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        //sqlCommand.Parameters.AddWithValue("@page", page);
                        //sqlCommand.Parameters.AddWithValue("@start", start);
                        //sqlCommand.Parameters.AddWithValue("@limit", limit);

                        //sqlCommand.Parameters.AddWithValue("@sort", Request.Query["sort"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@userDescription", Request.Query["userDescription"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@userCode", Request.Query["userCode"].ToString());


                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            while (recordSet.Read())
                            {
                                //if (initGrid == true)
                                //{
                                //    GIGridColumn column = new GIGridColumn();
                                //    if ((value = recordSet[recordSet.GetOrdinal("Title")]) != System.DBNull.Value) column.Title = (string)value;
                                //    rows.Add(column);
                                //}
                                //else
                                {
                                    LeftMenu model = new LeftMenu();
                                    if ((value = recordSet[recordSet.GetOrdinal("rootId")]) != System.DBNull.Value)
                                    {
                                        model.rootId = (int)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("id")]) != System.DBNull.Value)
                                    {
                                        model.id = (int)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("pid")]) != System.DBNull.Value)
                                    {
                                        model.pid = (int)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("leaf")]) != System.DBNull.Value)
                                    {
                                        model.leaf = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("expanded")]) != System.DBNull.Value)
                                    {
                                        model.expanded = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("loaded")]) != System.DBNull.Value)
                                    {
                                        model.loaded = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("text")]) != System.DBNull.Value)
                                    {
                                        model.text = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("iconCls")]) != System.DBNull.Value)
                                    {
                                        model.iconCls = (string)value;
                                    }

                                    if ((value = recordSet[recordSet.GetOrdinal("isMenuGroup")]) != System.DBNull.Value)
                                    {
                                        model.isMenuGroup = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("isDashboard")]) != System.DBNull.Value)
                                    {
                                        model.isDashboard = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("reference")]) != System.DBNull.Value)
                                    {
                                        model.reference = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("url")]) != System.DBNull.Value)
                                    {
                                        model.url = (string)value;
                                    }

                                    rows.Add(model);
                                }
                            }
                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                            {
                                totalRecordCount = (int)outputValue.Value;
                            }
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            return(rows);
        }
        private bool dbCheckAPIKey(ref LoginRequestJson req, ref LoginResponseJson resp)
        {
            bool rezult = false;

            try
            {
                string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
                string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();
                //string localHost = HttpContext.Features.Get()?.RemoteIpAddress?.ToString();
                //var a = HttpContext.Features.Get();

                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_ChekAPIKey]";
                        sqlCommand.Parameters.AddWithValue("@APIKey", req.apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@Username", req.username);
                        //sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        //sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            if (recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("IsOk")]) != System.DBNull.Value)
                                {
                                    rezult = (bool)value;
                                }
                            }
                            recordSet.Close();
                            recordSet.Dispose();
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            if (!rezult)
            {
                throw new Exception("ავტორიზაციის შეცდომა! Invalid access token.");
            }
            return(rezult);
        }
Exemple #16
0
        private dynamic dbList(ref int totalRecordCount)
        {
            bool   initGrid   = Request.Query["type"].ToString() == "initGrid" ? true : false;
            bool   exportGrid = Request.Query["type"].ToString() == "exportGrid" ? true : false;
            bool   isUtil     = Request.Query["subtype"].ToString() == "isUtil" ? true : false;
            string remoteIP   = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP    = this.HttpContext.Connection.LocalIpAddress.ToString();

            string page  = Request.Query["page"].ToString();
            string start = Request.Query["start"].ToString();
            string limit = Request.Query["limit"].ToString();



            List <dynamic>  rows            = new List <dynamic>();
            GIGridInitModel giGridInitModel = new GIGridInitModel()
            {
                ColumnList = new List <GIGridColumn>()
            };

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_lookup_GetPositionList]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@InitGrid", initGrid);
                        sqlCommand.Parameters.AddWithValue("@ExportGrid", exportGrid);

                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);


                        sqlCommand.Parameters.AddWithValue("@page", page);
                        sqlCommand.Parameters.AddWithValue("@start", start);
                        sqlCommand.Parameters.AddWithValue("@limit", limit);

                        sqlCommand.Parameters.AddWithValue("@utilityFilter", Request.Query["utilityFilter"].ToString()); // when typing in dropdown
                        sqlCommand.Parameters.AddWithValue("@sort", Request.Query["sort"].ToString());

                        //sqlCommand.Parameters.AddWithValue("@userDescription", Request.Query["userDescription"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@userCode", Request.Query["userCode"].ToString());


                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            while (recordSet.Read())
                            {
                                if (initGrid == true)
                                {
                                    GIGridColumn column = new GIGridColumn();
                                    if ((value = recordSet[recordSet.GetOrdinal("Title")]) != System.DBNull.Value)
                                    {
                                        column.Title = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("DataIndex")]) != System.DBNull.Value)
                                    {
                                        column.DataIndex = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("ValueType")]) != System.DBNull.Value)
                                    {
                                        column.ValueType = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Width")]) != System.DBNull.Value)
                                    {
                                        column.Width = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Flex")]) != System.DBNull.Value)
                                    {
                                        column.Flex = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Renderer")]) != System.DBNull.Value)
                                    {
                                        column.Renderer = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsFilter")]) != System.DBNull.Value)
                                    {
                                        column.IsFilter = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsNotColumn")]) != System.DBNull.Value)
                                    {
                                        column.IsNotColumn = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsHidden")]) != System.DBNull.Value)
                                    {
                                        column.IsHidden = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsMenuDisabled")]) != System.DBNull.Value)
                                    {
                                        column.IsMenuDisabled = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsGridSummaryRow")]) != System.DBNull.Value)
                                    {
                                        column.IsGridSummaryRow = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsLocked")]) != System.DBNull.Value)
                                    {
                                        column.IsLocked = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("SummaryRenderer")]) != System.DBNull.Value)
                                    {
                                        column.SummaryRenderer = (string)value;
                                    }

                                    giGridInitModel.ColumnList.Add(column);
                                }
                                else
                                {
                                    GILookupModel model      = new GILookupModel();
                                    var           properties = model.GetType().GetProperties();
                                    foreach (var el in properties)
                                    {
                                        string name = el.Name;
                                        value = recordSet[recordSet.GetOrdinal(name)];

                                        if (value != System.DBNull.Value)
                                        {
                                            switch (el.PropertyType.Name)
                                            {
                                            case "Int32":
                                                el.SetValue(model, (int)value);
                                                break;

                                            case "String":
                                                el.SetValue(model, (string)value);
                                                break;

                                            case "Boolean":
                                                el.SetValue(model, (bool)value);
                                                break;
                                            }
                                        }
                                    }
                                    rows.Add(model);
                                }
                            }
                            if (initGrid == true && recordSet.NextResult() && recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("Title")]) != System.DBNull.Value)
                                {
                                    giGridInitModel.Title = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Toolbar")]) != System.DBNull.Value)
                                {
                                    giGridInitModel.Toolbar = (string)value;
                                }
                            }

                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                            {
                                totalRecordCount = (int)outputValue.Value;
                            }
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            if (initGrid == false)
            {
                return(rows);
            }
            return(giGridInitModel);
        }
        private bool dbIssueSessionToken(ref LoginRequestJson req, ref LoginResponseJson resp)
        {
            try
            {
                string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
                string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();
                //string passwordEncr = GIxUtils.EncryptString(req.password);

                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_IssueSessionToken]";
                        sqlCommand.Parameters.AddWithValue("@APIKey", req.apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@Username", req.username);
                        sqlCommand.Parameters.AddWithValue("@Password", req.password);

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            if (recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("IsOk")]) != System.DBNull.Value)
                                {
                                    resp.success = (bool)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("UniqueID")]) != System.DBNull.Value)
                                {
                                    req.salt = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("UserWho")]) != System.DBNull.Value)
                                {
                                    resp.userWho = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Email")]) != System.DBNull.Value)
                                {
                                    resp.email = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Avatar")]) != System.DBNull.Value)
                                {
                                    resp.avatar = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Version")]) != System.DBNull.Value)
                                {
                                    resp.version = (string)value;
                                }
                                resp.user   = _loginRequest.username;
                                req.version = resp.version;
                            }
                            recordSet.Close();
                            recordSet.Dispose();
                        }
                    }

                    /////
                    /// JWT Base64 user credentials as sessionvarialbelHas + guid from DB

                    var token = new JwtBuilder()
                                .WithAlgorithm(new HMACSHA256Algorithm())                              // symmetric
                                .WithSecret(GIxUtils.DecyptString(_configuration["JWTSecretEncypted"]))
                                .AddClaim("exp", DateTimeOffset.UtcNow.AddDays(1).ToUnixTimeSeconds()) //
                                .AddClaim("LoginRequest", req)
                                .Encode();

                    //Console.WriteLine(token);
                    resp.token = token;

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            if (!resp.success)
            {
                throw new Exception("პაროლი ან მომხმარებლის სახელი არასწორად არის შეყვანილი.");
            }
            return(resp.success);
        }
        private dynamic dbList(ref int totalRecordCount)
        {
            //bool initGrid = Request.Query["type"].ToString() == "initGrid" ? true : false;
            //bool exportGrid = Request.Query["type"].ToString() == "exportGrid" ? true : false;
            //bool isUtil = Request.Query["subtype"].ToString() == "isUtil" ? true : false;
            string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();

            string src   = Request.Query["src"].ToString();
            string page  = Request.Query["page"].ToString();
            string start = Request.Query["start"].ToString();
            string limit = Request.Query["limit"].ToString();

            DashboardModel dashboardModel = new DashboardModel()
            {
                SaxeobaList  = new List <SaxeobaModel>(),
                PieDataList  = new List <PieDataModel>(),
                ActivityList = new List <ActivityModel> (),
                EntityList   = new List <EntityModel>(),
                PieColorList = new List <PieColorModel>()
            };

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_GetDashboard]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@Src", src);
                        //sqlCommand.Parameters.AddWithValue("@InitGrid", initGrid);
                        //sqlCommand.Parameters.AddWithValue("@ExportGrid", exportGrid);

                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);


                        sqlCommand.Parameters.AddWithValue("@page", page);
                        sqlCommand.Parameters.AddWithValue("@start", start);
                        sqlCommand.Parameters.AddWithValue("@limit", limit);

                        //sqlCommand.Parameters.AddWithValue("@utilityFilter", Request.Query["query"].ToString()); // when typing in dropdown
                        //sqlCommand.Parameters.AddWithValue("@sort", Request.Query["sort"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@userDescription", Request.Query["userDescription"].ToString());
                        //sqlCommand.Parameters.AddWithValue("@userCode", Request.Query["userCode"].ToString());


                        //SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        //outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            // 1. SaxeobaList
                            while (recordSet.Read())
                            {
                                dynamic model      = new SaxeobaModel();
                                var     properties = model.GetType().GetProperties();
                                foreach (var el in properties)
                                {
                                    string name = el.Name;
                                    value = recordSet[recordSet.GetOrdinal(name)];
                                    if (value != System.DBNull.Value)
                                    {
                                        switch (el.PropertyType.Name)
                                        {
                                        case "Int32":
                                            el.SetValue(model, (int)value);
                                            break;

                                        case "String":
                                            el.SetValue(model, (string)value);
                                            break;

                                        case "Boolean":
                                            el.SetValue(model, (bool)value);
                                            break;

                                        case "Decimal":
                                            el.SetValue(model, (decimal)value);
                                            break;

                                        case "DateTime":
                                            el.SetValue(model, (DateTime)value);
                                            break;
                                        }
                                    }
                                }

                                dashboardModel.SaxeobaList.Add(model);
                            }

                            // 2. PieChartData
                            recordSet.NextResult();
                            while (recordSet.Read())
                            {
                                dynamic model      = new PieDataModel();
                                var     properties = model.GetType().GetProperties();
                                foreach (var el in properties)
                                {
                                    string name = el.Name;
                                    value = recordSet[recordSet.GetOrdinal(name)];
                                    if (value != System.DBNull.Value)
                                    {
                                        switch (el.PropertyType.Name)
                                        {
                                        case "Int32":
                                            el.SetValue(model, (int)value);
                                            break;

                                        case "String":
                                            el.SetValue(model, (string)value);
                                            break;

                                        case "Boolean":
                                            el.SetValue(model, (bool)value);
                                            break;

                                        case "Decimal":
                                            el.SetValue(model, (decimal)value);
                                            break;

                                        case "DateTime":
                                            el.SetValue(model, (DateTime)value);
                                            break;
                                        }
                                    }
                                }

                                dashboardModel.PieDataList.Add(model);
                            }

                            // 3. ActivityData
                            recordSet.NextResult();
                            while (recordSet.Read())
                            {
                                dynamic model      = new ActivityModel();
                                var     properties = model.GetType().GetProperties();
                                foreach (var el in properties)
                                {
                                    string name = el.Name;
                                    value = recordSet[recordSet.GetOrdinal(name)];
                                    if (value != System.DBNull.Value)
                                    {
                                        switch (el.PropertyType.Name)
                                        {
                                        case "Int32":
                                            el.SetValue(model, (int)value);
                                            break;

                                        case "String":
                                            el.SetValue(model, (string)value);
                                            break;

                                        case "Boolean":
                                            el.SetValue(model, (bool)value);
                                            break;

                                        case "Decimal":
                                            el.SetValue(model, (decimal)value);
                                            break;

                                        case "DateTime":
                                            el.SetValue(model, (DateTime)value);
                                            break;
                                        }
                                    }
                                }
                                dashboardModel.ActivityList.Add(model);
                            }

                            // 4. Entity
                            recordSet.NextResult();
                            while (recordSet.Read())
                            {
                                dynamic model      = new EntityModel();
                                var     properties = model.GetType().GetProperties();
                                foreach (var el in properties)
                                {
                                    string name = el.Name;
                                    value = recordSet[recordSet.GetOrdinal(name)];
                                    if (value != System.DBNull.Value)
                                    {
                                        switch (el.PropertyType.Name)
                                        {
                                        case "Int32":
                                            el.SetValue(model, (int)value);
                                            break;

                                        case "String":
                                            el.SetValue(model, (string)value);
                                            break;

                                        case "Boolean":
                                            el.SetValue(model, (bool)value);
                                            break;

                                        case "Decimal":
                                            el.SetValue(model, (decimal)value);
                                            break;

                                        case "DateTime":
                                            el.SetValue(model, (DateTime)value);
                                            break;
                                        }
                                    }
                                }
                                dashboardModel.EntityList.Add(model);
                            }

                            // 4. Entity
                            recordSet.NextResult();
                            while (recordSet.Read())
                            {
                                dynamic model      = new PieColorModel();
                                var     properties = model.GetType().GetProperties();
                                foreach (var el in properties)
                                {
                                    string name = el.Name;
                                    value = recordSet[recordSet.GetOrdinal(name)];
                                    if (value != System.DBNull.Value)
                                    {
                                        switch (el.PropertyType.Name)
                                        {
                                        case "Int32":
                                            el.SetValue(model, (int)value);
                                            break;

                                        case "String":
                                            el.SetValue(model, (string)value);
                                            break;

                                        case "Boolean":
                                            el.SetValue(model, (bool)value);
                                            break;

                                        case "Decimal":
                                            el.SetValue(model, (decimal)value);
                                            break;

                                        case "DateTime":
                                            el.SetValue(model, (DateTime)value);
                                            break;
                                        }
                                    }
                                }
                                dashboardModel.PieColorList.Add(model);
                            }
                            recordSet.Close();
                            recordSet.Dispose();
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            return(dashboardModel);
        }
        //private IEnumerable<dynamic> dbGetAgentList(ref int totalRecordCount )
        private dynamic dbGetAgentList(ref int totalRecordCount)
        {
            bool   initGrid   = Request.Query["type"].ToString() == "initGrid" ? true : false;
            bool   exportGrid = Request.Query["type"].ToString() == "exportGrid" ? true : false;
            string remoteIP   = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP    = this.HttpContext.Connection.LocalIpAddress.ToString();

            string page  = Request.Query["page"].ToString();
            string start = Request.Query["start"].ToString();
            string limit = Request.Query["limit"].ToString();



            List <dynamic>  rows            = new List <dynamic>();
            GIGridInitModel giGridInitModel = new GIGridInitModel()
            {
                ColumnList = new List <GIGridColumn>()
            };

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_GetAgentBrokerList]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@InitGrid", initGrid);
                        sqlCommand.Parameters.AddWithValue("@ExportGrid", exportGrid);

                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        sqlCommand.Parameters.AddWithValue("@page", page);
                        sqlCommand.Parameters.AddWithValue("@start", start);
                        sqlCommand.Parameters.AddWithValue("@limit", limit);
                        sqlCommand.Parameters.AddWithValue("@sort", Request.Query["sort"].ToString());

                        sqlCommand.Parameters.AddWithValue("@code", Request.Query["ode"].ToString());
                        sqlCommand.Parameters.AddWithValue("@description", Request.Query["description"].ToString());
                        sqlCommand.Parameters.AddWithValue("@pin", Request.Query["pin"].ToString());
                        sqlCommand.Parameters.AddWithValue("@address", Request.Query["address"].ToString());
                        sqlCommand.Parameters.AddWithValue("@phone", Request.Query["phone"].ToString());
                        sqlCommand.Parameters.AddWithValue("@isBroker", Request.Query["isBroker"].ToString());
                        sqlCommand.Parameters.AddWithValue("@isIndMetsarme", Request.Query["isIndMetsarme"].ToString());


                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            while (recordSet.Read())
                            {
                                if (initGrid == true)
                                {
                                    #region helper properties
                                    GIGridColumn column = new GIGridColumn();
                                    if ((value = recordSet[recordSet.GetOrdinal("Title")]) != System.DBNull.Value)
                                    {
                                        column.Title = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("DataIndex")]) != System.DBNull.Value)
                                    {
                                        column.DataIndex = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("DisplayField")]) != System.DBNull.Value)
                                    {
                                        column.DisplayField = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("ValueField")]) != System.DBNull.Value)
                                    {
                                        column.ValueField = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("ValueType")]) != System.DBNull.Value)
                                    {
                                        column.ValueType = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Width")]) != System.DBNull.Value)
                                    {
                                        column.Width = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Flex")]) != System.DBNull.Value)
                                    {
                                        column.Flex = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Renderer")]) != System.DBNull.Value)
                                    {
                                        column.Renderer = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsFilter")]) != System.DBNull.Value)
                                    {
                                        column.IsFilter = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsNotColumn")]) != System.DBNull.Value)
                                    {
                                        column.IsNotColumn = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsHidden")]) != System.DBNull.Value)
                                    {
                                        column.IsHidden = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsMenuDisabled")]) != System.DBNull.Value)
                                    {
                                        column.IsMenuDisabled = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsGridSummaryRow")]) != System.DBNull.Value)
                                    {
                                        column.IsGridSummaryRow = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsLocked")]) != System.DBNull.Value)
                                    {
                                        column.IsLocked = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("SummaryRenderer")]) != System.DBNull.Value)
                                    {
                                        column.SummaryRenderer = (string)value;
                                    }

                                    giGridInitModel.ColumnList.Add(column);
                                    #endregion
                                }
                                else
                                {
                                    AgentBrokerListModel model = new AgentBrokerListModel();
                                    if ((value = recordSet[recordSet.GetOrdinal("RowNum")]) != System.DBNull.Value)
                                    {
                                        model.RowNum = (int)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Id")]) != System.DBNull.Value)
                                    {
                                        model.Id = (int)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Code")]) != System.DBNull.Value)
                                    {
                                        model.Code = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Description")]) != System.DBNull.Value)
                                    {
                                        model.Description = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Pin")]) != System.DBNull.Value)
                                    {
                                        model.Pin = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Address")]) != System.DBNull.Value)
                                    {
                                        model.Address = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("Phone")]) != System.DBNull.Value)
                                    {
                                        model.Phone = (string)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsBroker")]) != System.DBNull.Value)
                                    {
                                        model.IsBroker = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("IsIndMetsarme")]) != System.DBNull.Value)
                                    {
                                        model.IsIndMetsarme = (bool)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("EntityType")]) != System.DBNull.Value)
                                    {
                                        model.EntityType = (int)value;
                                    }
                                    if ((value = recordSet[recordSet.GetOrdinal("clrfg")]) != System.DBNull.Value)
                                    {
                                        model.clrfg = (int)value;
                                    }

                                    rows.Add(model);
                                }
                            }

                            if (initGrid == true && recordSet.NextResult() && recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("Title")]) != System.DBNull.Value)
                                {
                                    giGridInitModel.Title = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Toolbar")]) != System.DBNull.Value)
                                {
                                    giGridInitModel.Toolbar = (string)value;
                                }
                            }

                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                            {
                                totalRecordCount = (int)outputValue.Value;
                            }
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            if (initGrid == false)
            {
                return(rows);
            }
            return(giGridInitModel);
        }
Exemple #20
0
        private IEnumerable<dynamic> dbGetUserTaskPermissionList(ref int totalRecordCount)
        {
            bool initGrid = Request.Query["type"].ToString() == "initGrid" ? true : false;
            string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP = this.HttpContext.Connection.LocalIpAddress.ToString();

            string page = Request.Query["page"].ToString();
            string start = Request.Query["start"].ToString();
            string limit = Request.Query["limit"].ToString();
            string taskId = Request.Query["TaskId"];

            List<dynamic> rows = new List<dynamic>();
            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                    GIxUtils.DecodeConnectionString(
                        _configuration,
                        ref _loginRequest,
                        Request.Headers["X-WebGI-Authentication"],
                        Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_GetTaskPermisionList]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@InitGrid", initGrid);
                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        sqlCommand.Parameters.AddWithValue("@TaskId", taskId);

                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            while (recordSet.Read())
                            {
                                UserPermissionModel model = new UserPermissionModel();
                                //if ((value = recordSet[recordSet.GetOrdinal("rootId")]) != System.DBNull.Value) model.rootId = (int)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("id")]) != System.DBNull.Value) model.id = (int)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("pid")]) != System.DBNull.Value) model.pid = (int)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("leaf")]) != System.DBNull.Value) model.leaf = (bool)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("hasAccess")]) != System.DBNull.Value) model.hasAccess = (bool)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("expanded")]) != System.DBNull.Value) model.expanded = (bool)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("loaded")]) != System.DBNull.Value) model.loaded = (bool)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("text")]) != System.DBNull.Value) model.text = (string)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("cls")]) != System.DBNull.Value) model.cls = (string)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("iconCls")]) != System.DBNull.Value) model.iconCls = (string)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("reference")]) != System.DBNull.Value) model.reference = (string)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("url")]) != System.DBNull.Value) model.url = (string)value;

                                //rows.Add(model);
                                var properties = model.GetType().GetProperties();
                                foreach (var el in properties)
                                {
                                    string name = el.Name;
                                    value = recordSet[recordSet.GetOrdinal(name)];

                                    if (value != System.DBNull.Value)
                                    {
                                        switch (el.PropertyType.Name)
                                        {
                                            case "Int32":
                                                el.SetValue(model, (int)value);
                                                break;
                                            case "String":
                                                el.SetValue(model, (string)value);
                                                break;
                                            case "Boolean":
                                                el.SetValue(model, (bool)value);
                                                break;
                                        }

                                    }
                                }
                                rows.Add(model);
                            }
                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                                totalRecordCount = (int)outputValue.Value;
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            return rows;
        }
Exemple #21
0
        private dynamic dbActivateAccountToken(UserModel user, ref int totalRecordCount)
        {
            bool   initGrid = Request.Query["type"].ToString() == "initGrid" ? true : false;
            string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();

            UserModel model = new UserModel();

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_ActivateAccountToken]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@InitGrid", initGrid);
                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        sqlCommand.Parameters.AddWithValue("@UserId", user.UserId);
                        sqlCommand.Parameters.AddWithValue("@ActivationToken", user.ActivationToken);
                        sqlCommand.Parameters.AddWithValue("@NewPassword", user.NewPassword);
                        sqlCommand.Parameters.AddWithValue("@RePassword", user.RePassword);


                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            //object value;
                            if (recordSet.Read())
                            {
                                //if ((value = recordSet[recordSet.GetOrdinal("UserId")]) != System.DBNull.Value) model.UserId = (int)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("Username")]) != System.DBNull.Value) model.Username = (string)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("FirstName")]) != System.DBNull.Value) model.FirstName = (string)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("LastName")]) != System.DBNull.Value) model.LastName = (string)value;
                                //if ((value = recordSet[recordSet.GetOrdinal("Email")]) != System.DBNull.Value) model.Email = (string)value;
                            }
                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                            {
                                totalRecordCount = (int)outputValue.Value;
                            }
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            return(model);
        }
        public async void Get()
        {
            bool isEncrypted = Convert.ToBoolean(_configuration["ConnectionStrings:Encrypted"]);

            if (isEncrypted)
            {
                /*
                 * In order to decrypt using this certificate, IIS_IUSRS has to have access to private key
                 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                 * WinHttpCertCfg.exe -g -c LOCAL_MACHINE\WebHosting -s "webgi.app" -a "HOMEVM10PRO\IIS_IUSRS"
                 *
                 */


                /*
                 * X509Store store = new X509Store("WebHosting", StoreLocation.LocalMachine);
                 * store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                 * X509Certificate2Collection foundCertificates =
                 *  store.Certificates.Find(
                 *      X509FindType.FindByThumbprint,
                 *      "7970ca8de61cae007db15dfb01cf6f961397ef02",
                 *      true);
                 * store.Close();
                 * if (foundCertificates.Count == 0)
                 *  return;
                 *
                 * X509Certificate2 cert = foundCertificates[0];
                 */

                string encr = GIxUtils.EncryptString("Data Source=172.22.22.12;Initial Catalog=GI_TEST;User ID=WebGi;Password=P@$$w0rd4W3bG1;Persist Security Info=True;TrustServerCertificate=true;");
                string decr = GIxUtils.DecyptString(encr);

                encr = GIxUtils.EncryptString("Barjakuzu010203");

                //X509Certificate2 cert = new X509Certificate2(@"C:\webgi\webgi-app.pfx");

                /*
                 * byte[] data = Encrypt(cert);
                 * byte[] data2 = Decrypt(cert, data);
                 * string decrString = Encoding.ASCII.GetString(data2);
                 *
                 * string base64Encoded = Convert.ToBase64String(data);
                 * byte[] data3 = Convert.FromBase64String(base64Encoded);
                 *
                 * byte[] data4 = Decrypt(cert, data3);
                 * string decrString3 = Encoding.ASCII.GetString(data4);
                 */

                //_configuration["ConnectionStrings:DefaultConnection"] = "OK";
            }


            //"<title>Service Hub</title><br/>**** " + _configuration["ConnectionStrings:DefaultConnection"] + "*****<br/>"+

            await Response.WriteAsync("<!DOCTYPE html>" +
                                      "<html lang=\"en\">" +
                                      "<head>" +
                                      "<meta charset=\"UTF - 8\">" +
                                      "<meta name=\"viewport\" content=\"width = device - width, initial - scale = 1.0\">" +
                                      "<style>body{font-family: Segoe UI,SegoeUI,Segoe WP,Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;font-weight: 400;}</style></head>" +
                                      "<body>" +
                                      "<center><h1>Service Hub - " + _configuration["Environmet"] + "</h1><hr><p>Nothing to see here</p></center>" +
                                      "</body>" +
                                      "</html>");
        }
Exemple #23
0
        //private IEnumerable<dynamic> dbGetProviderList(ref int totalRecordCount )
        private dynamic dbGetClaimsList(ref int totalRecordCount)
        {
            bool   initGrid   = Request.Query["type"].ToString() == "initGrid" ? true : false;
            bool   exportGrid = Request.Query["type"].ToString() == "exportGrid" ? true : false;
            string remoteIP   = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP    = this.HttpContext.Connection.LocalIpAddress.ToString();

            List <dynamic>  rows            = new List <dynamic>();
            GIGridInitModel giGridInitModel = new GIGridInitModel()
            {
                ColumnList = new List <GIGridColumn>()
            };

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_GetAutoPolicyList]";
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);

                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);


                        if (Request != null && Request.Query != null && Request.Query.Keys != null && Request.Query.Keys.Count > 0)
                        {
                            foreach (string key in Request.Query.Keys)
                            {
                                if (!key.StartsWith("_"))
                                {
                                    string param = $"@{key}";
                                    sqlCommand.Parameters.AddWithValue(param, Request.Query[key].ToString());
                                }
                            }
                        }
                        ;

                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            while (recordSet.Read())
                            {
                                dynamic model = null;
                                if (initGrid == true)
                                {
                                    model = new GIGridColumn();
                                }
                                else
                                {
                                    model = new ContractListModel(); ///////////////// !!!!!!!! //////////
                                }
                                var properties = model.GetType().GetProperties();
                                foreach (var el in properties)
                                {
                                    string name = el.Name;
                                    value = recordSet[recordSet.GetOrdinal(name)];
                                    if (value != System.DBNull.Value)
                                    {
                                        switch (el.PropertyType.Name)
                                        {
                                        case "Int32":
                                            el.SetValue(model, (int)value);
                                            break;

                                        case "String":
                                            el.SetValue(model, (string)value);
                                            break;

                                        case "Boolean":
                                            el.SetValue(model, (bool)value);
                                            break;

                                        case "Decimal":
                                            el.SetValue(model, (decimal)value);
                                            break;

                                        case "DateTime":
                                            el.SetValue(model, (DateTime)value);
                                            break;
                                        }
                                    }
                                }

                                if (initGrid == true)
                                {
                                    giGridInitModel.ColumnList.Add(model);
                                }
                                else
                                {
                                    rows.Add(model);
                                }
                            }

                            if (initGrid == true && recordSet.NextResult() && recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("Title")]) != System.DBNull.Value)
                                {
                                    giGridInitModel.Title = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Toolbar")]) != System.DBNull.Value)
                                {
                                    giGridInitModel.Toolbar = (string)value;
                                }
                            }

                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                            {
                                totalRecordCount = (int)outputValue.Value;
                            }
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            if (initGrid == false)
            {
                return(rows);
            }
            return(giGridInitModel);
        }
Exemple #24
0
        public JsonResult Post([FromBody] object content)
        {
            int    totalRows = 0;
            string exception = "Ok";
            bool   rezult    = true;
            object rows      = new { };

            //UserModel user = new UserModel();
            //dynamic ob001 = new ExpandoObject();
            var ob001 = new MyDynObject(new Dictionary <string, object>()
            {
                {
                    "prop1", 12
                },
            });

            //Console.WriteLine(dyn.prop1);
            //ob001.prop1 = 150;

            //dynamic ob002 = new ExpandoObject();
            //ob002 = ob001;


            try
            {
                string vs      = content.ToString();
                var    options = new JsonSerializerOptions
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                    WriteIndented        = true
                };
                UserModel user = JsonSerializer.Deserialize <UserModel>(vs, options);
                rows = dbSetUserUser(user, ref totalRows);
            }
            catch (TokenExpiredException ex)
            {
                rezult    = false;
                exception = ex.Message;
                GIxUtils.Log(ex);
            }
            catch (SignatureVerificationException ex)
            {
                rezult    = false;
                exception = ex.Message;
                GIxUtils.Log(ex);
            }
            catch (Exception ex)
            {
                rezult    = false;
                exception = ex.Message;
                Console.WriteLine(ex.Message);
                rows = new
                {
                    message = exception,
                    set     = ob001
                };
                GIxUtils.Log(ex);
            }

            return(new JsonResult(new
            {
                success = rezult,
                message = exception,
                code = 0,
                total = 0,
                data = rows
            }));
        }
Exemple #25
0
        private dynamic dbGetTask(ref int totalRecordCount)
        {
            bool   initGrid = Request.Query["type"].ToString() == "initGrid" ? true : false;
            string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();

            string page   = Request.Query["page"].ToString();
            string start  = Request.Query["start"].ToString();
            string limit  = Request.Query["limit"].ToString();
            string taskId = Request.Query["taskId"];


            TaskModel model = new TaskModel();

            //List<dynamic> rows = new List<dynamic>();
            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_GetTask]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@InitGrid", initGrid);
                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        sqlCommand.Parameters.AddWithValue("@TaskId", taskId);


                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            if (recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("TaskId")]) != System.DBNull.Value)
                                {
                                    model.TaskId = (int)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("TaskName")]) != System.DBNull.Value)
                                {
                                    model.TaskName = (string)value;
                                }
                            }
                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                            {
                                totalRecordCount = (int)outputValue.Value;
                            }
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            return(model);
        }
        private dynamic dbGetSignature(ref int totalRecordCount)
        {
            bool   initGrid = Request.Query["type"].ToString() == "initGrid" ? true : false;
            string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
            string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();

            string page        = Request.Query["page"].ToString();
            string start       = Request.Query["start"].ToString();
            string limit       = Request.Query["limit"].ToString();
            string signatureId = Request.Query["SignatureId"];

            SignatureModel model = new SignatureModel();

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_GetSignature]";
                        //sqlCommand.Parameters.AddWithValue("@APIKey", apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@InitGrid", initGrid);
                        sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        sqlCommand.Parameters.AddWithValue("@SignatureId", signatureId);


                        SqlParameter outputValue = sqlCommand.Parameters.Add("@totalCount", SqlDbType.Int);
                        outputValue.Direction = ParameterDirection.Output;

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            if (recordSet.Read())
                            {
                                var properties = model.GetType().GetProperties();
                                foreach (var el in properties)
                                {
                                    string name = el.Name;
                                    value = recordSet[recordSet.GetOrdinal(name)];

                                    if (value != System.DBNull.Value)
                                    {
                                        switch (el.PropertyType.Name)
                                        {
                                        case "Int32":
                                            el.SetValue(model, (int)value);
                                            break;

                                        case "String":
                                            el.SetValue(model, (string)value);
                                            break;

                                        case "Boolean":
                                            el.SetValue(model, (bool)value);
                                            break;

                                        case "Decimal":
                                            //case "Nullable'1":
                                            el.SetValue(model, (decimal)value);
                                            break;
                                        }
                                    }
                                }
                            }
                            recordSet.Close();
                            recordSet.Dispose();

                            if (outputValue.Value != null)
                            {
                                totalRecordCount = (int)outputValue.Value;
                            }
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                throw new Exception(ex.Message);
            }

            return(model);
        }