public string UpdateRoleAccess(TControllerRoleAccess obj)
        {
            TControllerRoleAccessRPO RPO = new TControllerRoleAccessRPO(imap_);
            //RPO.Where(nameof(TControllerRoleAccess.ControllerName)).Equals(obj.ControllerName);
            //RPO.Where(nameof(TControllerRoleAccess.RoleID)).Equals(obj.RoleID);
            Conditions cnd = new Conditions();

            cnd.AddFilter(nameof(TControllerRoleAccess.ControllerName), Operator.Equals(obj.ControllerName));
            cnd.AddFilter(nameof(TControllerRoleAccess.RoleID), Operator.Equals(obj.RoleID));
            RPO.Conditions(cnd);
            RPO.Update(obj, ref exec);
            return(exec.Message);
        }
Exemple #2
0
        public int Delete <T>(List <object> keys, Conditions conditions) where T : class
        {
            if (keys.Count > 0)
            {
                Type obj      = typeof(T);
                int  keyCount = 0;
                foreach (PropertyInfo objprop in obj.GetProperties().Where(x => x.CustomAttributes.Count() > 0))
                {
                    if (objprop.CustomAttributes.Any(x => x.AttributeType.Name == "KeyAttribute"))
                    {
                        conditions.AddFilter(objprop.Name, Operator.Equals(keys[keyCount]));
                        keyCount++;
                    }
                    if (keyCount >= keys.Count)
                    {
                        break;
                    }
                }
            }

            string tableName       = GetTableName(typeof(T));
            string storedProcedure = conditions.SP_DELETE;//GetStoredProcedureOfDelete(typeof(T));

            if (string.IsNullOrEmpty(storedProcedure))
            {
                string query = "DELETE FROM " + tableName + " " + conditions.GetAllFilterParam();
                return(ObjConn.Execute(query, null, ObjTrans, CommandTimeOut, CommandType.Text));
            }
            else
            {
                StoredProcedureParameter.Delete spParams = new StoredProcedureParameter.Delete();
                spParams.filter = conditions.ResultFilter;
                return(ObjConn.Execute(storedProcedure, spParams, ObjTrans, CommandTimeOut, CommandType.StoredProcedure));
            }
        }
Exemple #3
0
        public MUserVM Login(string username, string password, out string message)
        {
            string     encodedPassFromDB;
            bool       matchPass  = false;
            MUser      objRetUser = new MUser();
            MUserVM    objUser    = new MUserVM();
            MUserRPO   muserRPO   = new MUserRPO(imap_);
            Conditions cnd        = new Conditions();

            cnd.AddFilter(nameof(MUser.Username), Operator.Equals(username));
            cnd.AddFilter(nameof(MUser.IsActive), Operator.Equals(1));
            cnd.AddFilter(nameof(MUser.IsLocked), Operator.Equals(0));
            muserRPO.Conditions(cnd);
            //muserRPO.Where(nameof(MUser.IsActive)).Equals(1);
            //muserRPO.Where(nameof(MUser.IsLocked)).Equals(0);
            if (muserRPO.ReadOne(ref exec) && muserRPO.Result.AffectedRow > 0)
            {
                encodedPassFromDB = muserRPO.Result.Row.Password;
                matchPass         = Helpers.Crypto.ValidateKey(password, encodedPassFromDB);
                objRetUser        = matchPass ? muserRPO.Result.Row : null;
                if (matchPass)
                {
                    objUser.objUser  = objRetUser;
                    objUser.ListRole = new List <TuserRole>();
                    TUserRoleRPO objUrole = new TUserRoleRPO(imap_);
                    objUrole.Conditions(nameof(TuserRole.Username), Operator.Equals(objRetUser.Username));
                    //objUrole.Where(nameof(TUserRole.Username)).Equals(objRetUser.Username);
                    if (objUrole.ReadList(ref exec))
                    {
                        objUser.ListRole = objUrole.Result.Collection;
                    }
                    message = exec.Message;
                }
                else
                {
                    message = "Incorrect Username or Password";
                }
            }
            else
            {
                message = exec.Message;
            }

            return(objUser);
        }
        public bool CheckDuplicateRoleAccess(string controllerName, string roleID, ref string message)
        {
            TControllerRoleAccessRPO crRPO = new TControllerRoleAccessRPO(imap_);
            Conditions cnd = new Conditions();

            cnd.AddFilter(nameof(TControllerRoleAccess.ControllerName), Operator.Equals(controllerName));
            cnd.AddFilter(nameof(TControllerRoleAccess.RoleID), Operator.Equals(roleID));
            crRPO.Conditions(cnd);
            //crRPO.Where(nameof(TControllerRoleAccess.ControllerName)).Equals(controllerName);
            //crRPO.Where(nameof(TControllerRoleAccess.RoleID)).Equals(roleID);
            if (crRPO.ReadList(ref exec))
            {
                return(crRPO.Result.AffectedRow > 0);
            }
            else
            {
                message = exec.Message;
            }

            return(true);
        }
        public virtual async Task <FindResult <T> > Get(string filter = "", string sortBy = "", int page = 1, int itemsByPage = 50, bool descending = false)
        {
            try
            {
                var conditions = new Conditions();
                conditions.AddFilter(filter);
                using (var manager = CrudManagerFactory.GetCrudManager <T>())
                {
                    var result = await manager.FindAsync(conditions, page, itemsByPage, sortBy, descending);

                    return(result);
                }
            }
            catch (Exception ex)
            {
                await Logger.ErrorAsync($"Error obteniendo elementos de {typeof(T).Name}", ex);

                throw;
            }
        }
Exemple #6
0
        public T ReadOne <T>(List <object> keys, Conditions conditions)
        {
            if (keys.Count > 0)
            {
                Type obj      = typeof(T);
                int  keyCount = 0;
                foreach (PropertyInfo objprop in obj.GetProperties().Where(x => x.CustomAttributes.Count() > 0))
                {
                    if (objprop.CustomAttributes.Any(x => x.AttributeType.Name == "KeyAttribute"))
                    {
                        conditions.AddFilter(objprop.Name, Operator.Equals(keys[keyCount]));
                        keyCount++;
                    }
                    if (keyCount >= keys.Count)
                    {
                        break;
                    }
                }
            }

            string storedProcedureName = conditions.SP_SELECT;//GetStoredProcedureOfSelect(typeof(T));
            string tableName           = GetTableName(typeof(T));

            if (storedProcedureName != "")
            {
                StoredProcedureParameter.Select spParam = new StoredProcedureParameter.Select()
                {
                    filter        = conditions.GetFilterParam(),
                    selectedField = conditions.GetTop1SelectParam(),
                    groupBy       = conditions.GetGroupByParam(),
                    orderBy       = conditions.GetOrderByParam()
                };
                var retn = ObjConn.Query <T>(storedProcedureName, spParam, ObjTrans, true, CommandTimeOut, CommandType.StoredProcedure);
                if (retn.Count() > 0)
                {
                    return(retn.ToList()[0]);
                }
                else
                {
                    return(default);
        public virtual async Task <FindResult <object> > Get(string select, string filter = "", string sortBy = "", int page = 1, int itemsByPage = 50, bool descending = false)
        {
            if (select == null)
            {
                throw new LogicException("El parámetro select es requerido.");
            }
            try
            {
                var conditions = new Conditions();
                conditions.AddFilter(filter);
                using (var manager = CrudManagerFactory.GetCrudManager <T>())
                {
                    var result = await manager.FindSelectAsync(conditions, select, page, itemsByPage, sortBy, descending);

                    return(result);
                }
            }
            catch (Exception ex)
            {
                await Logger.ErrorAsync($"Error obteniendo elementos de {typeof(T).Name}", ex);

                throw;
            }
        }
Exemple #8
0
        public int Update <T>(T model, bool isDirect, Conditions conditions) where T : class
        {
            //TODO DATETIME PROBLEM IF NULL

            //Create Set Value
            string SetValue = "";
            string prefix   = "";
            var    asdsadf  = model.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite && !x.CustomAttributes.Any(y => y.AttributeType.Name == "RequiredAttribute" || y.AttributeType.Name == "ReadOnlyAttribute"));

            foreach (PropertyInfo objprop in model.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite && !x.CustomAttributes
                                                                                                                              .Any(y => y.AttributeType.Name == "RequiredAttribute" || y.AttributeType.Name == "ReadOnlyAttribute")))
            {
                prefix = SetValue.Length == 0 ? "" : ", ";
                var VAL = objprop.GetValue(model, null);

                if (VAL != null)
                {
                    if (objprop.PropertyType.Name == "DateTime")
                    {
                        if (VAL.ToString() != "1/1/0001 12:00:00 AM")
                        {
                            SetValue = SetValue + prefix + objprop.Name + "='" + VAL.ToString() + "'";
                        }
                    }
                    else
                    {
                        SetValue = SetValue + prefix + objprop.Name + "='" + VAL.ToString() + "'";
                    }
                }
            }

            //Add Filter Based on Key Models: Auto Add Default Primary Key as Filter
            if (isDirect)
            {
                object keyVal;
                foreach (PropertyInfo objprop in model.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
                         .Where(x => x.CustomAttributes.Any(y => y.AttributeType.Name == "KeyAttribute")))
                {
                    keyVal = objprop.GetValue(model, null);
                    if (keyVal == null)
                    {
                        break;
                    }
                    conditions.AddFilter(objprop.Name, Operator.Equals(keyVal.ToString()));
                }
            }

            //Execute
            string tableName       = GetTableName(typeof(T));
            string storedProcedure = conditions.SP_UPDATE;  //GetStoredProcedureOfUpdate(typeof(T));

            if (string.IsNullOrEmpty(storedProcedure))
            {
                string query = "UPDATE " + tableName + " SET " + SetValue + " " + conditions.GetAllFilterParam();
                return(ObjConn.Execute(query, null, ObjTrans, CommandTimeOut, CommandType.Text));
            }
            else
            {
                StoredProcedureParameter.Update spParams = new StoredProcedureParameter.Update();
                spParams.filter   = conditions.ResultFilter;
                spParams.setvalue = SetValue;
                spParams.isDebug  = true;
                if (spParams.isDebug)
                {
                    object execQuery = ObjConn.ExecuteScalar(storedProcedure, spParams, ObjTrans, CommandTimeOut, CommandType.StoredProcedure);
                    return(0);
                }
                else
                {
                    return(ObjConn.Execute(storedProcedure, spParams, ObjTrans, CommandTimeOut, CommandType.StoredProcedure));
                }
            }
        }
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            Ilog    _logger     = context.HttpContext.RequestServices.GetService(typeof(Ilog)) as Ilog;
            IMapper _imapper    = context.HttpContext.RequestServices.GetService(typeof(IMapper)) as IMapper;
            string  username    = "******";
            string  objIdentity = context.HttpContext.Session.GetString(Helpers.SessionKeyUser.Key);

            if (!string.IsNullOrEmpty(objIdentity))
            {
                username = JsonConvert.DeserializeObject <Models.UserSessionModel>(objIdentity).username;
            }

            _logger.SetLogInfo(username, context.HttpContext.Request.Path.Value);
            _imapper.user = username;
            _imapper.host = context.HttpContext.Connection.RemoteIpAddress.ToString();

            //when controller not allowanonymous
            if (!context.Filters.Any(item => item is IAllowAnonymousFilter))
            {
                bool isValiduser = false;
                if (!string.IsNullOrEmpty(objIdentity))
                {
                    ExecResult      exec         = new ExecResult();
                    CheckisAdminRPO userRoleRPOs = new CheckisAdminRPO(_imapper);
                    userRoleRPOs.Conditions(nameof(TuserRole.Username), Operator.Equals(username));
                    userRoleRPOs.ReadList(ref exec);
                    //if not success check administrator
                    if (!exec.Success)
                    {
                        isValiduser = false;
                    }
                    //if not admin then check allowed actionController
                    else if (userRoleRPOs.Result.AffectedRow == 0)
                    {
                        ActPermissionVMRPO actiPermissionRPO = new ActPermissionVMRPO(_imapper);
                        string             controllerName    = (string)context.RouteData.Values["controller"] + "Controller";
                        string             actionName        = (string)context.RouteData.Values["action"];
                        Conditions         cnd = new Conditions();
                        cnd.AddFilter(nameof(ActPermissionVM.Username), Operator.Equals(username));
                        cnd.AddFilter(nameof(ActPermissionVM.ControllerName), Operator.Equals(controllerName));
                        cnd.AddFilter(nameof(ActPermissionVM.ActionName), Operator.Equals(actionName));
                        cnd.AddFilter(nameof(ActPermissionVM.IsAllowed), Operator.Equals("1"));
                        actiPermissionRPO.Conditions(cnd);
                        if (actiPermissionRPO.ReadList(ref exec))
                        {
                            List <ActPermissionVM> tym = actiPermissionRPO.Result.Collection;
                            isValiduser = actiPermissionRPO.Result.AffectedRow > 0;
                        }
                    }
                    else
                    {
                        isValiduser = true; //is admin
                    }
                }

                if (!isValiduser)
                {
                    _logger.WARNING("Not Authorized");
                    context.Result = new ViewResult
                    {
                        ViewName = "../Account/NotAuthorized"
                    };
                }
            }
        }