示例#1
0
        public static UserPermissionsModel GetUserPermissionModel(Guid guid, int moduleId)
        {
            var userPermissionList = new UserPermissionsEntities().UserPermissions.
                                     AsQueryable().Where(x => x.user_id == guid).ToList();

            if (moduleId == 0)
            {
                userPermissionList = userPermissionList.Where(x => x.item_id == 0).ToList();
            }
            else
            {
                userPermissionList = userPermissionList.Where(x => x.module_id == moduleId && x.item_id != 0).ToList();
            }
            //
            Dictionary <int, string> dict = new Dictionary <int, string>();

            foreach (ModuleTypes item in Enum.GetValues(typeof(ModuleTypes)))
            {
                var text = string.Format("{0}", Home.TranslateWord.GetWord(item.ToString()));
                dict.Add((int)item, text);
            }

            var userPermissionModel = new UserPermissionsModel
            {
                ModuleList         = dict,
                UserPermissionList = userPermissionList,
                ItemList           = GetItemList(moduleId)
            };

            return(userPermissionModel);
        }
        public ActionResult ManageUserPermission(string UID)
        {
            UID = !string.IsNullOrEmpty(Convert.ToString(UID)) ? EncryptDecrypt.Decrypt(UID) : "0";
            long UserID = Convert.ToInt32(UID);

            using (var objContext = new db_KISDEntities())
            {
                var objModel = new UserPermissionsModel();
                objModel.PermissionList = GetUserPermissions();
                var selectedSections = objContext.UserPermissions.Where(m => m.UserID == UserID).Select(m => m.PageID.Value).ToArray();

                if (selectedSections.Count() == 0)
                {
                    string[] s = { "0" };
                    objModel.SelectedUserPermissions = s;
                }
                else
                {
                    objModel.SelectedUserPermissions = Array.ConvertAll <long, string>(selectedSections,
                                                                                       delegate(long i)
                    {
                        return(i.ToString());
                    });
                }
                objModel.User       = objContext.Users.Where(x => x.UserID == UserID).FirstOrDefault();
                objModel.UserRoleID = (short?)objContext.UserRoles.Where(x => x.UserID == UserID).FirstOrDefault().RoleID;
                objModel.Role       = objContext.Roles.Where(x => x.RoleID == objModel.UserRoleID).FirstOrDefault();

                ViewBag.Title = ViewBag.PageTitle = "Manage User Permissions ";
                return(View("ManageUserPermission", objModel));
            }
        }
        public ActionResult ManageUserPermission(UserPermissionsModel model, string command, FormCollection fm)
        {
            #region Route value directory
            var rvd = new RouteValueDictionary();
            rvd.Add("page", Request.QueryString["page"] ?? "1");
            rvd.Add("pagesize", Request.QueryString["pagesize"] ?? "10");
            rvd.Add("Column", "UserCreateDate");
            rvd.Add("Direction", "Descending");
            rvd.Add("UID", model.UserID);
            #endregion

            using (var objContext = new db_KISDEntities())
            {
                if (string.IsNullOrEmpty(command))
                {
                    if (model.SelectedUserPermissions != null)
                    {
                        #region Save User Permissions
                        long userid  = Convert.ToInt64(Membership.GetUser().ProviderUserKey);
                        User objuser = objContext.Users.Where(x => x.UserID == userid).FirstOrDefault();

                        var objUserPermissions = objContext.UserPermissions.Where(x => x.UserID == model.User.UserID).ToList();
                        if (objUserPermissions != null && objUserPermissions.Count > 0)
                        {
                            foreach (var up in objUserPermissions)
                            {
                                objContext.UserPermissions.Remove(up);
                            }
                            objContext.SaveChanges();
                        }
                        foreach (var item in model.SelectedUserPermissions)
                        {
                            if (item != "0")
                            {
                                var obj = new UserPermission();
                                obj.UserID         = model.User.UserID;
                                obj.PageID         = Convert.ToInt32(item);
                                obj.CreateDate     = DateTime.Now;
                                obj.IsAccessInd    = true;
                                obj.CreateByID     = userid;
                                obj.LastModifyByID = userid;
                                obj.LastModifyDate = DateTime.Now;
                                obj.UserRoleID     = model.UserRoleID;
                                objContext.UserPermissions.Add(obj);
                                objContext.SaveChanges();
                            }
                        }
                        #endregion
                    }
                    TempData["AlertMessage"] = "Manage User Permissions updated successfully.";
                }
                return(RedirectToAction("Index", "UsersManagement", rvd));
            }
        }
        public ActionResult EditPermissions(UserPermissionsModel model)
        {
            try
            {
                _adminBusinessLogic.ChangeUserPermissions(model);
            }
            catch (FormValidationException e)
            {
                return(View("UserError", new UserError(e.Error)));
            }

            return(RedirectToAction("UserPermissions"));
        }
示例#5
0
        public ActionResult SetPermissions()
        {
            UserPermissionsModel userPermissions = new UserPermissionsModel();

            userPermissions.Initialize();

            userPermissions.LoadModulesList();
            List <MenuItemModel> ModulesList;

            ModulesList = userPermissions.ModulesList;

            //Adding Module Functions to the existing Modules List's Module Functions List
            userPermissions.LoadModuleFunctionsList(ref ModulesList);
            userPermissions.ModulesList = ModulesList;

            SessionWrapper.UserPermissionModel = userPermissions;
            return(View(userPermissions));
        }
示例#6
0
        public ActionResult SetPermissions(UserPermissionsModel userPermissions)
        {
            string        sFunctionName = "SetPermissions(post)";
            ResponseModel Result        = new ResponseModel();

            try
            {
                if (string.IsNullOrWhiteSpace(userPermissions.UserTypeID) || string.IsNullOrWhiteSpace(userPermissions.UserLevelID))
                {
                    return(Json(new
                    {
                        ResponseMessage = "Please select User Type and User Level",
                        success = false
                    }));
                }
                Result = userPermissions.SetPermissions();
                if (Result.isSuccessful)
                {
                    return(Json(new
                    {
                        ResponseMessage = "Permissions Successfully set for User Type " + userPermissions.UserTypeID + " and User Level " + userPermissions.UserLevelID,
                        success = true
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        ResponseMessage = "Failed to set Permissions",
                        success = false
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    ResponseMessage = "Failed to set Permissions",
                    success = false
                }));
            }
            //return View(userPermissions);
        }
示例#7
0
        internal void ChangeUserPermissions(UserPermissionsModel model)
        {
            using (var db = new ErasmusDbContext())
            {
                var user = db.Users.SingleOrDefault(x => x.Id == model.UserId);

                if (user != null)
                {
                    var permissions = db.UserPermissions.Where(x => x.UserId == user.Id);
                    if (permissions.Any())
                    {
                        db.UserPermissions.RemoveRange(permissions);
                        db.SaveChanges();
                    }

                    try
                    {
                        if (model.Permissions != null && model.Permissions.Any())
                        {
                            foreach (var perm in model.Permissions)
                            {
                                db.UserPermissions.Add(new UserPermissions()
                                {
                                    UserId       = user.Id,
                                    UniversityId = perm.UniversityId,
                                    FacultyId    = perm.FacultyId.HasValue ? perm.FacultyId : null
                                });
                            }
                            db.SaveChanges();
                        }
                    }
                    catch (Exception e)
                    {
                        return;
                    }
                }
            }
        }
示例#8
0
        public ActionResult EditBaskets(UserPermissionsModel model)
        {
            if (ModelState.IsValid)
            {
                if (Authorized(RoleType.SystemManager))
                {
                    User userFromDB;
                    List <Budgets_UsersToBaskets> existingPermissions;
                    bool noErrors = true;

                    using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId))
                        using (UsersToBasketsRepository userPermissionsRep = new UsersToBasketsRepository())
                        {
                            userFromDB = usersRep.GetEntity(model.UserId);

                            if (userFromDB != null)
                            {
                                if (userFromDB.CompanyId == CurrentUser.CompanyId)
                                {
                                    existingPermissions = userPermissionsRep.GetList().Where(x => x.UserId == userFromDB.Id).ToList();

                                    if (existingPermissions != null)
                                    {
                                        if (model.UserPermissions == null)
                                        {
                                            return(RedirectToAction("Index"));
                                        }

                                        foreach (var permission in model.UserPermissions)
                                        {
                                            if (permission.IsActive)
                                            {
                                                if (!existingPermissions.Any(x => x.BasketId == permission.Permission.Id))
                                                {
                                                    Budgets_UsersToBaskets newPermission = new Budgets_UsersToBaskets()
                                                    {
                                                        UserId    = userFromDB.Id,
                                                        BasketId  = permission.Permission.Id,
                                                        CompanyId = CurrentUser.CompanyId
                                                    };

                                                    if (!userPermissionsRep.Create(newPermission))
                                                    {
                                                        noErrors = false;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                Budgets_UsersToBaskets existingPermission = existingPermissions.SingleOrDefault(x => x.BasketId == permission.Permission.Id);
                                                if (existingPermission != null)
                                                {
                                                    if (!userPermissionsRep.Delete(existingPermission.Id))
                                                    {
                                                        noErrors = false;
                                                    }
                                                }
                                            }
                                        }

                                        if (noErrors)
                                        {
                                            return(RedirectToAction("Index"));
                                        }
                                        else
                                        {
                                            return(Error(Loc.Dic.error_user_edit_permissions_error));
                                        }
                                    }
                                    else
                                    {
                                        return(Error(Loc.Dic.error_database_error));
                                    }
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_no_permission));
                                }
                            }
                            else
                            {
                                return(Error(Loc.Dic.error_database_error));
                            }
                        }
                }
                else
                {
                    return(Error(Loc.Dic.error_no_permission));
                }
            }
            else
            {
                return(Error(ModelState));
            }
        }
示例#9
0
        public ActionResult EditBaskets(int id = 0)
        {
            if (!Authorized(RoleType.SystemManager))
            {
                return(Error(Loc.Dic.error_no_permission));
            }

            UserPermissionsModel model = new UserPermissionsModel();
            User user;
            List <Budgets_Baskets> allPermissions;

            using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId))
                using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository())
                {
                    user = usersRep.GetEntity(id);

                    if (user == null)
                    {
                        return(Error(Loc.Dic.error_users_get_error));
                    }

                    model.User            = user;
                    model.UserPermissions = user.Budgets_UsersToBaskets.Select(x => new UserPermission()
                    {
                        Permission = x.Budgets_Baskets, IsActive = true
                    }).Where(x => x.Permission.CompanyId == CurrentUser.CompanyId).ToList();

                    if (model.UserPermissions == null)
                    {
                        return(Error(Loc.Dic.error_permissions_get_error));
                    }

                    allPermissions = permissionsRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).ToList();
                    if (allPermissions == null)
                    {
                        return(Error(Loc.Dic.error_database_error));
                    }

                    List <Budgets_Baskets> allWithoutUserBasket = new List <Budgets_Baskets>();
                    foreach (Budgets_Baskets basket in allPermissions)
                    {
                        allWithoutUserBasket.Add(basket);
                    }

                    foreach (UserPermission UserBasket in model.UserPermissions)
                    {
                        foreach (Budgets_Baskets basket in allPermissions)
                        {
                            if (UserBasket.Permission.Id == basket.Id)
                            {
                                allWithoutUserBasket.Remove(basket);
                            }
                        }
                    }

                    model.UserId = user.Id;
                    model.PermissionsSelectList = new SelectList(allWithoutUserBasket, "Id", "Name");

                    return(View(model));
                }
        }
示例#10
0
        public ActionResult GetUserLevels(string UserTypeID)
        {
            UserPermissionsModel userPermissions = new UserPermissionsModel();
            UserModel            userModel       = new UserModel();

            if (SessionWrapper.UserPermissionModel != null)
            {
                userPermissions = SessionWrapper.UserPermissionModel;
                try
                {
                    userPermissions.GetUserLevels(UserTypeID);
                    return(Json(new
                    {
                        UserLevelList = userPermissions.UserLevelSelectList,
                        success = true
                    }));
                }
                catch (Exception ex)
                {
                    return(Json(new
                    {
                        success = false
                    }));
                }
            }
            if (SessionWrapper.AddUserModel != null)
            {
                userModel = SessionWrapper.AddUserModel;
                try
                {
                    userModel.GetUserLevels(UserTypeID);
                    return(Json(new
                    {
                        UserLevelList = userModel.UserLevelSelectList,
                        success = true
                    }));
                }
                catch (Exception ex)
                {
                    return(Json(new
                    {
                        success = false
                    }));
                }
            }
            if (SessionWrapper.ViewUserModel != null)
            {
                userModel = SessionWrapper.ViewUserModel;
                try
                {
                    userModel.GetUserLevels(UserTypeID);
                    return(Json(new
                    {
                        UserLevelList = userModel.UserLevelSelectList,
                        success = true
                    }));
                }
                catch (Exception ex)
                {
                    return(Json(new
                    {
                        success = false
                    }));
                }
            }
            return(Json(new
            {
                success = false
            }));
        }