public IActionResult addGroup([FromBody] PermissionObj form)
        {
            try
            {
                var userId = this.help.GetCurrentUser(HttpContext);
                if (userId <= 0)
                {
                    return(StatusCode(401, "الرجاء الـتأكد من أنك قمت بتسجيل الدخول"));
                }
                var perm = this.help.getPermissin("Groups_Add", userId, db);
                if (!perm)
                {
                    return(StatusCode(401, "لا تملك الصلاحية"));
                }


                if (form == null)
                {
                    return(BadRequest("حذث خطأ في ارسال البيانات الرجاء إعادة الادخال"));
                }



                var Groups = (from p in db.Groups where p.Name == form.name select p).SingleOrDefault();

                if (Groups != null)
                {
                    return(StatusCode(401, "الاسم موجود مسبقا"));
                }

                Groups gr = new Groups();
                gr.Name      = form.name;
                gr.State     = 1;
                gr.CreatedBy = userId;
                gr.CreatedOn = DateTime.Now;
                db.Groups.Add(gr);
                foreach (var item in form.id)
                {
                    var             h  = item;
                    PermissionGroup pg = new PermissionGroup();
                    pg.PermissioinId = item;
                    pg.GroupId       = gr.Id;
                    pg.CreatedBy     = userId;
                    pg.CreatedOn     = DateTime.Now;
                    pg.State         = 1;
                    db.PermissionGroup.Add(pg);
                }
                db.SaveChanges();
                return(Ok("تمت عملية الاضافة بنجاح"));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public PermissionObj GetOne(int id)
        {
            object[] sqlParams =
            {
                new SqlParameter("@IDQN", id)
            };
            var obj = context.Database.SqlQuery <ViewPermission>("Sp_GetPermission @IDQN", sqlParams).SingleOrDefault();

            var returnObj = new PermissionObj();

            returnObj.IDQN       = obj.IDQN;
            returnObj.Permission = obj.Permission;
            returnObj.LogStatus  = obj.LogStatus;

            return(returnObj);
        }
示例#3
0
        // create individual list for each type - easy to control on view page
        //private List<PermissionObj> GetPermission_SQ (List<ViewPermission> view)
        //{
        //    // Create an empty list to hold result of the operation

        //    var perList = new List<PermissionObj>();

        //    // For each string in the 'elements' variable, create a new SelectListItem object
        //    // that has both its Value and Text properties set to a particular value.
        //    // This will result in MVC rendering each item as:
        //    foreach (var item in view)
        //    {
        //        if (item.ThanhPhan == "SQ")
        //        {
        //            var permisObj = new PermissionObj();
        //            permisObj.IDQN = item.IDQN;
        //            permisObj.Hoten = item.HoTen;
        //            permisObj.Permission = item.Permission;
        //            permisObj.LogStatus = item.LogStatus;
        //            //permisObj.ThanhPhan = item.ThanhPhan;
        //            perList.Add(permisObj);
        //        }
        //    }

        //    return perList;
        //}
        //private List<PermissionObj> GetPermission_QNCN(List<ViewPermission> view)
        //{
        //    // Create an empty list to hold result of the operation

        //    var perList = new List<PermissionObj>();

        //    // For each string in the 'view' variable, create a new List<PermissionObj> object
        //    // that has properties set to a particular value.
        //    // This will result in MVC rendering each item as:
        //    foreach (var item in view)
        //    {
        //        if (item.ThanhPhan == "QNCN")
        //        {
        //            var permisObj = new PermissionObj();
        //            permisObj.IDQN = item.IDQN;
        //            permisObj.Hoten = item.HoTen;
        //            permisObj.Permission = item.Permission;
        //            permisObj.LogStatus = item.LogStatus;
        //            perList.Add(permisObj);
        //        }
        //    }

        //    return perList;
        //}
        //private List<PermissionObj> GetPermission_HSQ_TS (List<ViewPermission> view)
        //{
        //    // Create an empty list to hold result of the operation

        //    var perList = new List<PermissionObj>();

        //    // For each string in the 'elements' variable, create a new SelectListItem object
        //    // that has both its Value and Text properties set to a particular value.
        //    // This will result in MVC rendering each item as:
        //    foreach (var item in view)
        //    {
        //        if (item.ThanhPhan == "HSQ" && item.DonVi == "cTS")
        //        {
        //            var permisObj = new PermissionObj();
        //            permisObj.IDQN = item.IDQN;
        //            permisObj.Hoten = item.HoTen;
        //            permisObj.Permission = item.Permission;
        //            permisObj.LogStatus = item.LogStatus;
        //            perList.Add(permisObj);
        //        }
        //    }

        //    return perList;
        //}
        //private List<PermissionObj> GetPermission_HSQ_TT (List<ViewPermission> view)
        //{
        //    // Create an empty list to hold result of the operation

        //    var perList = new List<PermissionObj>();

        //    // For each string in the 'elements' variable, create a new SelectListItem object
        //    // that has both its Value and Text properties set to a particular value.
        //    // This will result in MVC rendering each item as:
        //    foreach (var item in view)
        //    {
        //        if (item.ThanhPhan == "HSQ" && item.DonVi == "cTT")
        //        {
        //            var permisObj = new PermissionObj();
        //            permisObj.IDQN = item.IDQN;
        //            permisObj.Hoten = item.HoTen;
        //            permisObj.Permission = item.Permission;
        //            permisObj.LogStatus = item.LogStatus;
        //            perList.Add(permisObj);
        //        }
        //    }

        //    return perList;
        //}
        //private List<PermissionObj> GetPermission_HSQ_dB_BD (List<ViewPermission> view)
        //{
        //    // Create an empty list to hold result of the operation

        //    var perList = new List<PermissionObj>();

        //    // For each string in the 'elements' variable, create a new SelectListItem object
        //    // that has both its Value and Text properties set to a particular value.
        //    // This will result in MVC rendering each item as:
        //    foreach (var item in view)
        //    {
        //        if (item.ThanhPhan == "HSQ" && ( item.DonVi == "dB" || item.DonVi == "bBD"))
        //        {
        //            var permisObj = new PermissionObj();
        //            permisObj.IDQN = item.IDQN;
        //            permisObj.Hoten = item.HoTen;
        //            permisObj.Permission = item.Permission;
        //            permisObj.LogStatus = item.LogStatus;
        //            perList.Add(permisObj);
        //        }
        //    }

        //    return perList;
        //}

        // JSON accept or refresh permission without reload page

        public JsonResult LoadList(int id, string act)
        {
            PermissionObj obj = new PermissionObj();

            if (act == "Accept")
            {
                context.Accept(id);
            }
            else
            {
                context.Refresh(id);
            }
            obj = context.GetOne(id);

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
        public IActionResult addPermissionName([FromBody] PermissionObj form)
        {
            try
            {
                var userId = this.help.GetCurrentUser(HttpContext);
                if (userId <= 0)
                {
                    return(StatusCode(401, "الرجاء الـتأكد من أنك قمت بتسجيل الدخول"));
                }
                var perm = this.help.getPermissin("Permissions_Add", userId, db);
                if (!perm)
                {
                    return(StatusCode(401, "لا تملك الصلاحية"));
                }


                if (form == null)
                {
                    return(BadRequest("حذث خطأ في ارسال البيانات الرجاء إعادة الادخال"));
                }



                var Years = (from p in db.Permissions where p.Name == form.name select p).SingleOrDefault();

                if (Years != null)
                {
                    return(StatusCode(401, "الاسم موجود مسبقا"));
                }

                Permissions pre = new Permissions();
                pre.Name      = form.name;
                pre.State     = 1;
                pre.CreatedBy = userId;
                pre.CreatedOn = DateTime.Now;
                db.Permissions.Add(pre);
                db.SaveChanges();

                return(Ok("تمت عملية الاضافة بنجاح"));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        /// <summary>
        ///     Constructs the PermissionEditViewModel
        /// </summary>
        /// <param name="type"></param>
        /// <param name="permissionObj"></param>
        public PermissionEditViewModel(string type, PermissionObj permissionObj)
        {
            switch (type)
            {
            case "CreateUR":
                this.Field1Title = "User Name";
                this.Field2Title = "Role";
                break;

            case "EditUR":
                this.Field1Title = "User Name";
                this.Field2Title = "Role";
                break;

            case "CreateRP":
                this.Field1Title = "Role";
                this.Field2Title = "Permission";
                break;
            }
            this.Field1 = permissionObj.Field1;
            this.Field2 = permissionObj.Field2;
        }
示例#6
0
        /// <summary>
        ///     Retrieve a list of all the User name / role pairs
        /// </summary>
        /// <returns>List of all the user name / role pairs</returns>
        public ObservableCollection <PermissionObj> RetrieveUserRoleList()
        {
            ObservableCollection <PermissionObj> userRoleList = new ObservableCollection <PermissionObj>();

            try
            {
                using (SqlConnection sqlConnection = new DatabaseConnection(DbServerName, DbName, DbPassword, IsLocalTest).GetConnection(IsLocalTest))
                {
                    SqlCommand sqlCommand = new SqlCommand("Odin_GetUserRoleList", sqlConnection);
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    SqlDataReader reader = sqlCommand.ExecuteReader();
                    while (reader.Read())
                    {
                        PermissionObj permissionObj = new PermissionObj();
                        permissionObj.Field1 = Convert.ToString(reader["UserName"]).Trim();
                        permissionObj.Field2 = Convert.ToString(reader["Role"]).Trim();
                        userRoleList.Add(permissionObj);
                    }
                }
            }
            catch (Exception ex) { ErrorLog.LogError(ex.ToString()); }

            return(userRoleList);
        }