Пример #1
0
        public override ResponseModel Insert(DbConnect con, DynamicDictionary item)
        {
            UserModel model = new UserModel();

                        //setting the client_id before inserting record if client_id field exists.
                        if(model.GetType().GetProperty("client_id") != null)
            {
                if (item.GetValueAsInt("client_id") == null)
                {
                    item.Add("client_id", SessionData.client_id);
                }
                else
                {
                    item.Add("client_id", item.GetValueAsInt("client_id"));
                }
            }

            string new_file_name = item.GetValueAsString("new_file_name");

            if (new_file_name != "")
            {
                string reltive_path = "temp/";
                item.SetValue("photo_path", reltive_path + new_file_name);
            }
            ResponseModel resp = base.Insert(con, item);

            if (resp.success)
            {
                int user_id = (int)((DynamicDictionary)resp.data).GetValueAsInt("id");
                resp.data = user_id;
                return(resp);
            }
            return(resp);
        }
Пример #2
0
        public override ResponseModel Insert(DbConnect con, DynamicDictionary item)
        {
            AssignedUserRightsModel model = new AssignedUserRightsModel();

            if (model.GetType().GetProperty("client_id") != null)
            {
                object      rights_user = item.GetValue("assigned_right_ids");
                IEnumerable enumerable  = rights_user as IEnumerable;
                if (enumerable != null)
                {
                    foreach (object element in enumerable)
                    {
                        object aa = element;
                        if (item.GetValueAsInt("client_id") == null)
                        {
                            item.Add("client_id", SessionData.client_id);
                        }
                        else
                        {
                            item.Add("client_id", item.GetValueAsInt("client_id"));
                        }
                        item.Add("assigned_right_id", aa);
                        base.Insert(con, item);
                    }
                }
            }
            ResponseModel Assigned_right_user = new ResponseModel();

            Assigned_right_user.success = true;
            Assigned_right_user.message = "Data Successfully Added.";
            return(Assigned_right_user);
        }
Пример #3
0
        public override BangoCommand GetSearchCommand(SearchScenario scenario, DbConnect con, BangoCommand cmd,
                                                      DynamicDictionary data_param, string selectClause, string orderByClause, int page = -1, int pageSize = 20,
                                                      bool count = false, string tableAlias = null, string scenarioOthers = null)
        {
            if (SessionData.client_id == 1)
            {
                CheckClientID = false;
            }
            var cmd1 = base.GetSearchCommand(scenario, con, cmd, data_param, selectClause, orderByClause, page, pageSize,
                                             count, tableAlias, scenarioOthers);

            //assigned_roles_id1
            if (data_param.ContainsKey("assigned_roles_id1"))
            {
                var SQLl = string.Format(@"
                    SELECT  distinct  r.user_id FROM RBAC_USER_ROLES r
                    left join rbac_role_roles rr on r.assigned_role_id = rr.role_id
                    LEFT JOIN RBAC_USER_ROLES rs on rs.id = rr.assigned_role_id
                    where r.assigned_role_id={0} ", data_param.GetValueAsInt("assigned_roles_id1"));

                cmd1.SqlBuilder.Where(string.Format("  c.ID NOT IN ({0}) ", SQLl));
            }
            else if (data_param.ContainsKey("assigned_roles_id"))
            {
                var SQLl = string.Format(@"
                    SELECT  distinct  r.user_id FROM RBAC_USER_ROLES r
                    left join rbac_role_roles rr on r.assigned_role_id = rr.role_id
                    LEFT JOIN RBAC_USER_ROLES rs on rs.id = rr.assigned_role_id
                    where r.assigned_role_id={0} ", data_param.GetValueAsInt("assigned_roles_id"));

                cmd1.SqlBuilder.Where(string.Format("  c.ID IN ({0}) ", SQLl));
            }
            //assigned_rights_id1
            if (data_param.ContainsKey("assigned_rights_id1"))
            {
                var SQLl = string.Format(@"
            SELECT distinct  ur.user_id
            FROM RBAC_USER_RIGHTS ur 
	            INNER JOIN RBAC_RIGHTS_MASTER rm ON ur.ASSIGNED_RIGHT_ID = rm.id
            WHERE  ur.is_deleted = false 
            AND ur.status = true and ur.ASSIGNED_RIGHT_ID = {0} ", data_param.GetValueAsInt("assigned_rights_id1"));

                cmd1.SqlBuilder.Where(string.Format("  c.ID NOT IN ({0}) ", SQLl));
            }
            else if (data_param.ContainsKey("assigned_right_id"))
            {
                var SQLl = string.Format(@"
            SELECT distinct  ur.user_id
            FROM RBAC_USER_RIGHTS ur 
	            INNER JOIN RBAC_RIGHTS_MASTER rm ON ur.ASSIGNED_RIGHT_ID = rm.id
            WHERE  ur.is_deleted = false 
            AND ur.status = true and ur.ASSIGNED_RIGHT_ID = {0} ", data_param.GetValueAsInt("assigned_right_id"));

                cmd1.SqlBuilder.Where(string.Format("  c.ID IN ({0}) ", SQLl));
            }

            return(cmd1);
        }
Пример #4
0
        public virtual ResponseCollection Get(int page = 1, int page_size = 20, string sort_by = null)
        {
            DynamicDictionary paraList = GetQueryAsDictionary();

            //TODO:Shivashwsr 08 jan 2016
            if (paraList.GetValueAsInt("limit") != null)
            {
                int?limit_page = paraList.GetValueAsInt("limit");
                page_size = (int)limit_page;
            }

            return((new TService()).GetSearchItems(paraList, page, page_size, sort_by));
        }
Пример #5
0
        public virtual ResponseCollection GridFilterItems(string gridfilter, int?page = 0, int?page_size = 0, string sort_by = null)
        {
            DynamicDictionary paraList = GetQueryAsDictionary();

            //TODO:Shivashwsr 08 jan 2016
            if (paraList.GetValueAsInt("limit") != null)
            {
                int?limit_page = paraList.GetValueAsInt("limit");
                page_size = (int)limit_page;
            }

            return((new TService()).GetGridFilterItems(paraList, Convert.ToInt32(page), Convert.ToInt32(page_size), sort_by));
        }
Пример #6
0
        public bool IsValidSession(DbConnect con, string token, int user_id)
        {
            if (!App.CheckToken)
            {
                return(true);
            }
            DynamicDictionary tokenDetail = GetTokenDetail(token, user_id);

            if (tokenDetail == null || tokenDetail.GetCount() == 0)
            {
                return(false);
            }
            if (tokenDetail.ContainsKey("expire_datetime"))
            {
                if (!String.IsNullOrEmpty(tokenDetail["expire_datetime"].ToString()))
                {
                    DateTime expiryDate   = Convert.ToDateTime(tokenDetail["expire_datetime"]);
                    DateTime current_date = DateTime.Now;
                    TimeSpan difference   = expiryDate - current_date;
                    if (difference.TotalMinutes < 0)
                    {
                        Status = AuthorizationStatus.SessionExpired;
                        return(false);
                    }
                    else
                    {
                        SessionData.client_id = tokenDetail.GetValueAsInt("client_id");
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #7
0
        public void Logout()
        {
            DynamicDictionary authDetail = null;

            if (SessionData.token != null)
            {
                if (SessionData.user_id != null)
                {
                    authDetail = GetTokenDetail(SessionData.token, (int)SessionData.user_id);
                }
            }
            if (authDetail != null)
            {
                int?session_id = authDetail.GetValueAsInt("id");
                //Delete(session_id);
                SessionLogService srvc = new SessionLogService();
                srvc.Delete(session_id);
            }
            if (HttpContext.Current.Response.Cookies.AllKeys.Contains("token"))
            {
                HttpContext.Current.Response.Cookies.Remove("token");
            }
            if (HttpContext.Current.Response.Cookies.AllKeys.Contains("user_id"))
            {
                HttpContext.Current.Response.Cookies.Remove("user_id");
            }
            SessionData.Session.Clear();
        }
Пример #8
0
        public virtual ResponseAuth Authenticate(DynamicDictionary data_param)
        {
            int    client_id = (int)data_param.GetValueAsInt("client_id");
            string username  = data_param.GetValueAsString("username");
            string password  = data_param.GetValueAsString("password");

            return(Authenticate(client_id, username, password));
        }
        protected bool AuthenticationFromDB(HttpActionContext actionContext, string token, int user_id)
        {
            if (!App.CheckToken)
            {
                return(true);
            }
            IAuthService      authSrvc    = App.Container.GetInstance <Rbac.IAuthService>();
            DynamicDictionary tokenDetail = authSrvc.GetTokenDetail(token, user_id);

            if (tokenDetail == null || tokenDetail.GetCount() == 0)
            {
                Status = AuthorizationStatus.NotLoggedIn;
                return(false);
            }
            if (tokenDetail.ContainsKey("expire_datetime"))
            {
                if (!String.IsNullOrEmpty(tokenDetail["expire_datetime"].ToString()))
                {
                    DateTime expiryDate   = Convert.ToDateTime(tokenDetail["expire_datetime"]);
                    DateTime current_date = DateTime.Now;
                    TimeSpan difference   = expiryDate - current_date;
                    if (difference.TotalMinutes < 0)
                    {
                        Status = AuthorizationStatus.SessionExpired;
                        return(false);
                    }
                    else
                    {
                        int?session_id = tokenDetail.GetValueAsInt("id");
                        _client_id            = (int)tokenDetail.GetValueAsInt("client_id");
                        SessionData.client_id = _client_id;
                        DynamicDictionary data_param = new DynamicDictionary();
                        data_param.Add("expire_datetime", AuthService.GetExpirtyDateTime(DateTime.Now));
                        data_param.Add("id", session_id);
                        SessionLogService logSrvc = new SessionLogService();
                        logSrvc.Update(session_id, data_param);
                        Status = AuthorizationStatus.Authorized;
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #10
0
        public override ResponseModel Update(int?id, DynamicDictionary item)
        {
            string        message = string.Empty;
            bool          success = false;
            object        data    = item;
            ResponseModel resp    = new ResponseModel();
            UserModel     Model   = new UserModel();

            LoadItemAfterSave = true;
            using (DbConnect con = new DbConnect())
            {
                con.DB.BeginTransaction();
                try
                {
                    string new_file_name  = item.GetValueAsString("new_file_name");
                    string user_file_name = item.GetValueAsString("userfilename");
                    string relative_path  = "temp/";
                    if (user_file_name == null)
                    {
                        if (new_file_name != null)
                        {
                            item.SetValue("photo_path", relative_path + new_file_name);
                        }
                    }
                    else
                    {
                        if (new_file_name != "")
                        {
                            item.SetValue("photo_path", relative_path + new_file_name);
                        }
                        else
                        {
                            item.SetValue("photo_path", "");
                            string filePath = FileBox.GetWebAppRoot();
                            if (System.IO.File.Exists(filePath + user_file_name)) //if file exists than delete.
                            {
                                System.IO.File.Delete(filePath + user_file_name);
                            }
                        }
                    }
                    if (SessionData.client_id == 1)
                    {
                        CheckClientID = false;
                    }

                    resp = base.Update(id, item);

                    #region User Profile Window
                    if (resp.success && item.GetValueAsString("userProfile") == "true")
                    {
                        string file_name = item.GetValueAsString("new_file_name");
                        string filePath  = FileBox.GetWebAppRoot() + "temp/";
                        int?   photo_id  = item.GetValueAsInt("photo_id");
                        if (file_name == "")
                        {
                            var photoPath = item.GetValueAsString("user_file_name");
                            if (photoPath == "")
                            {
                                return(null);
                            }
                            if (System.IO.File.Exists(filePath + new_file_name)) //if file exists than delete.
                            {
                                System.IO.File.Delete(filePath + new_file_name);
                            }

                            int?tax_photo_id = item.GetValueAsInt("photo_id");
                            item.SetValue("photo_path", "");
                            resp = base.Update(id, item);
                        }
                        else
                        {
                            if (photo_id == 0)
                            {
                                item.SetValue("photo_path", relative_path + new_file_name);
                            }
                            else
                            {
                                item.SetValue("photo_path", relative_path + new_file_name);
                            }
                            resp = base.Update(id, item);
                        }
                    }
                    #endregion
                    else
                    {
                    }
                    if (resp.success)
                    {
                        con.DB.CommitTransaction();
                        message = "Data added successfully.";
                        success = true;
                        if (resp.success)
                        {
                            DynamicDictionary respdata        = (DynamicDictionary)resp.data;
                            string            confirmpassword = respdata.GetValueAsString("confirmpassword");
                            if (item.GetValueAsString("userProfile") == "" || item.GetValueAsString("userProfile") == null)
                            {
                                if (confirmpassword == "" || confirmpassword == null)
                                {
                                    int user_id = (int)((DynamicDictionary)resp.data).GetValueAsInt("id");
                                    resp.data = user_id;
                                    return(resp);
                                }
                            }
                        }
                        return(resp);
                    }
                    else
                    {
                        con.DB.RollbackTransaction();

                        if (resp.validation_errors.GetCount() > 0)
                        {
                            message = string.Join(",", resp.error_code);
                        }
                        else
                        {
                            message = "Data add failed, please try again later.";
                        }
                    }
                }
                catch (Exception)
                {
                    con.DB.RollbackTransaction();
                    message = "Data add failed, Rollback Transaction.";
                }
            }
            return(new ResponseModel(success, item.GetValue("photo_id"), message));
        }
Пример #11
0
        public ResponseAuth AuthenticateUserNamePasword(DbConnect con, int client_id, string username, string password)
        {
            ResponseAuth resp     = new ResponseAuth();
            string       template = @"
                SELECT id, client_id, username, password, name_en, name_np,email, status
                FROM rbac_user u
                /**where**/
                AND u.status=true AND u.is_deleted=false";
            //creating command & preparing command
            string       alias = DbServiceUtility.GetTableAliasForTable("u");
            BangoCommand cmd   = new BangoCommand(MyroCommandTypes.SqlBuilder);

            cmd.Template = cmd.SqlBuilder.AddTemplate(template);
            UserModel mdl = new UserModel();

            DbServiceUtility.BindDeleteParameter(cmd, mdl, alias);
            DynamicDictionary data_param = new DynamicDictionary();

            data_param.Add("client_id", client_id);
            data_param.Add("username", username);
            DbServiceUtility.BindParameters(cmd, mdl, data_param, alias, SearchTypes.Equal);

            //executing the command
            string finalSql = cmd.FinalSql;

            if (finalSql.Length > 0)
            {
                IEnumerable <SqlMapper.DapperRow> items = null;
                try
                {
                    items = con.DB.Query <SqlMapper.DapperRow>(finalSql, cmd.FinalParameters, true);
                }
                catch (Npgsql.NpgsqlException ex)
                {
                    LogTrace.WriteErrorLog(ex.ToString());
                    LogTrace.WriteDebugLog(string.Format("Select SQL which gave exception:\r{0}", ex.Routine));
                }

                Errors = con.DB.GetErros();
                if (items != null && items.Count() > 0)
                {
                    DynamicDictionary data = Conversion.ToDynamicDictionary(items.FirstOrDefault());
                    if (data.GetValueAsString("password") == EncryptPassword(password))
                    {
                        resp.success = true;
                        resp.user_id = data.GetValueAsInt("id");
                        resp.email   = data.GetValueAsString("email");
                        resp.message = "Login successfull";
                    }
                    else
                    {
                        resp.message = "Username and/or Password is invalid.";
                    }
                }
                else
                {
                    if (Errors.Count > 0)
                    {
                        resp.message = "Technical Problem occurred.";
                    }
                    else
                    {
                        resp.message = "Please provide a valid Username.";
                    }
                }
            }

            return(resp);
        }