public ActionResult GetUserGroupsView()
        {
            UserGroupModel         model  = new UserGroupModel();
            UserGroupServiceClient client = null;

            try
            {
                var UsergroupId = Request.QueryString["usergroupid"];
                client = new UserGroupServiceClient();
                UserGroupDto ugdto = client.GetById(UsergroupId != null ? Convert.ToInt32(UsergroupId) : 0);
                client.Close();
                model.UserGroupId   = ugdto.UserGroupId;
                model.UserGroupName = ugdto.UserGroupName;
                model.Description   = ugdto.Description;
                model.IsActive      = ugdto.IsActive;
                model.AllowEdit     = ugdto.AllowEdit;
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error"));
            }
            finally
            {
                if (client != null && client.State == System.ServiceModel.CommunicationState.Opened)
                {
                    client.Close();
                }
            }
            return(View("UserGroupsView", model));
        }
Beispiel #2
0
        public ActionResult UserGroupRolesIndex()
        {
            UserGroupRolesModel model = new UserGroupRolesModel();

            UserGroupServiceReference.UserGroupServiceClient UGClient = null;
            try
            {
                string usergroupid = "";
                if (!string.IsNullOrEmpty(Request.QueryString["usergroupid"]))
                {
                    UGClient    = new UserGroupServiceClient();
                    usergroupid = Request.QueryString["usergroupid"];
                    UserGroupDto Usergroupdto = UGClient.GetById(Convert.ToInt32(usergroupid));
                    UGClient.Close();
                    model.UserGroupName = Usergroupdto.UserGroupName;
                    model.RoleGroupList = GetRoleGroupList(usergroupid);
                }

                string usertype = "";
                if (!string.IsNullOrEmpty(Request.QueryString["userType"]))
                {
                    usertype = Request.QueryString["userType"];
                }
            }
            catch (Exception ex)
            {
                return(View("ErrorPage"));
            }

            return(View("UserGroupRoles", model));
        }
        public List <UserGroupDto> GetUserGroupsList(Query query)
        {
            UserGroupServiceClient client = new UserGroupServiceClient();
            var result = client.FindByQuery(query);

            client.Close();
            return(result.Entities.ToList());
        }
        public ActionResult CreateUserGroup(UserGroupModel model)
        {
            ViewData["Error"]   = null;
            TempData["Success"] = null;
            try
            {
                UserDto CurrentUser = (UserDto)Session[Constants.SKCURRENTUSER];
                string  usertype    = "";

                if (!string.IsNullOrEmpty(Request.QueryString["userType"]))
                {
                    usertype = Request.QueryString["userType"];
                }

                if (ModelState.IsValid)
                {
                    UserDto currentUser                 = (UserDto)Session[Constants.SKCURRENTUSER];
                    UserGroupServiceClient client       = new UserGroupServiceClient();
                    UserGroupDto           NewUserGroup = new UserGroupDto();
                    if (FormMode == "edit")
                    {
                        NewUserGroup = client.GetById(Id);
                        client.Close();
                    }
                    else
                    {
                        NewUserGroup.IsDeleted   = model.IsDeleted;
                        NewUserGroup.AllowEdit   = model.AllowEdit;
                        NewUserGroup.AllowDelete = model.AllowDelete;
                        NewUserGroup.CreatedBy   = currentUser.UserId;
                    }
                    NewUserGroup.UserGroupName = FirstCharInUpper(model.UserGroupName);
                    NewUserGroup.Description   = model.Description;
                    NewUserGroup.CAId          = model.CAId;
                    NewUserGroup.IsActive      = model.IsActive;

                    NewUserGroup.ModifiedBy = currentUser.UserId;
                    CreateUserGroupService(NewUserGroup, currentUser);
                    if (isGroupSaved)
                    {
                        return(RedirectToAction("UserGroupsIndex", "Account",
                                                new { usertype = usertype, CAId = model.CAId }));
                    }
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("Error"));
            }
            return(View(model));
        }
        public List <UserGroupDto> GetUserGroupList(int?CAId)
        {
            UserGroupServiceClient client = new UserGroupServiceClient();
            List <UserGroupDto>    ugList = null;

            try
            {
                UserDto CurrentUser = (UserDto)Session[Constants.SKCURRENTUSER];
                string  usertype    = "";
                if (!string.IsNullOrEmpty(Request.Params["userType"]))
                {
                    usertype = Request.Params["userType"];
                }
                Query     query = new Query();
                Criterion criteriaCAId;

                if (usertype == "AckUser" && !Helper.IsCAIdNotNull(CurrentUser))
                {
                    criteriaCAId = new Criterion(Constants.CAID, null, CriteriaOperator.IsNullOrZero);
                }
                else if (usertype == "CAUser" && (CAId != null || CAId != 0))
                {
                    criteriaCAId = new Criterion(Constants.CAID, CAId, CriteriaOperator.Equal);
                }
                else
                {
                    criteriaCAId = new Criterion(Constants.CAID, Helper.GetCAIdOfUser(CurrentUser), CriteriaOperator.Equal);
                }

                query.Add(criteriaCAId);
                query.QueryOperator = QueryOperator.And;
                var usergroupdtos = client.FindByQuery(query);
                ugList = usergroupdtos.Entities.ToList();
                ugList.Insert(0, new UserGroupDto
                {
                    UserGroupId   = 0,
                    UserGroupName = "[Select All]"
                });
            }
            catch (Exception ex)
            { }
            finally
            {
                client.Close();
            }
            return(ugList);
        }
        private void CreateUserGroupService(UserGroupDto NewUserGroup, UserDto currentUser)
        {
            UserGroupServiceClient client = new UserGroupServiceClient();

            try
            {
                if (FormMode == "edit")
                {
                    NewUserGroup.UserGroupId = Id;
                    NewUserGroup             = client.Update(NewUserGroup, currentUser.UserName);
                }
                else
                {
                    NewUserGroup.CreatedBy = currentUser.UserId;
                    NewUserGroup           = client.Create(NewUserGroup, currentUser.UserName);
                }
                if (NewUserGroup.Response.HasWarning)
                {
                    foreach (BusinessWarning businessWarning in NewUserGroup.Response.BusinessWarnings)
                    {
                        ViewData["Error"] = ErrorAndValidationMessages.ResourceManager.GetString(businessWarning.Message);
                    }
                }
                else
                {
                    if (FormMode == "edit")
                    {
                        TempData["GroupSaved"] = String.Format(ClientResources.UserGroupUpdated, NewUserGroup.UserGroupName);
                    }
                    else
                    {
                        TempData["GroupSaved"] = String.Format(ClientResources.UserGroupAdded, NewUserGroup.UserGroupName);
                    }
                    isGroupSaved = true;
                }
            }
            catch (Exception)
            {
                client.Close();
            }
        }
Beispiel #7
0
        public ActionResult SaveUserGroupRolePermissions(UserGroupRolesModel model)
        {
            UserGroupServiceReference.UserGroupServiceClient UGClient = null;
            UserGroupDto userGroupDto = new UserGroupDto();

            string[] RoleGroupNames = { string.Empty };
            int      usergroupid    = 0;

            if (!string.IsNullOrEmpty(Request.QueryString["usergroupid"]))
            {
                usergroupid = Convert.ToInt32(Request.QueryString["usergroupid"]);
            }

            try
            {
                UGClient       = new UserGroupServiceClient();
                userGroupDto   = UGClient.GetById(usergroupid);
                RoleGroupNames = (string[])Session["RoleGroupNames" + Request.QueryString["usergroupid"]];

                //if (userGroupDto.RolePermissionsInUserGroup == null || userGroupDto.RolePermissionsInUserGroup.Count == 0)
                userGroupDto.RolePermissionsInUserGroup = new List <UserGroupRolePermissionDto>();
                userGroupDto.RolePermissionsInUserGroup.Clear();
                for (int i = 0; i < RoleGroupNames.Count(); i++)
                {
                    List <RoleModel> Roles = (List <RoleModel>)Session[RoleGroupNames[i]];
                    if (Roles != null)
                    {
                        foreach (RoleModel rolemodel in Roles)
                        {
                            if (rolemodel.AllowAdd || rolemodel.AllowEdit || rolemodel.AllowPrint || rolemodel.AllowView || rolemodel.AllowDelete)
                            {
                                var userGroupRolePermissionDto = new UserGroupRolePermissionDto
                                {
                                    PermissionForUserGroup = new List <UserGroupDto>
                                    {
                                        new UserGroupDto
                                        {
                                            UserGroupId = userGroupDto.UserGroupId
                                        }
                                    },
                                    PermissionForRole = rolemodel.PermissionForRole,
                                    AllowAdd          = rolemodel.AllowAdd,
                                    AllowEdit         = rolemodel.AllowEdit,
                                    AllowView         = rolemodel.AllowView,
                                    AllowDelete       = rolemodel.AllowDelete,
                                    AllowPrint        = rolemodel.AllowPrint
                                };
                                userGroupDto.RolePermissionsInUserGroup.Add(userGroupRolePermissionDto);
                            }
                        }
                    }
                }
                UGClient.Update(userGroupDto, ((UserDto)Session[Constants.SKCURRENTUSER]).UserName);
                UGClient.Close();
            }
            catch (Exception ex)
            {
                return(View("ErrorPage"));
            }
            finally
            {
                if (RoleGroupNames != null && RoleGroupNames.Count() > 0)
                {
                    for (int i = 0; i < RoleGroupNames.Count(); i++)
                    {
                        Session.Remove(RoleGroupNames[i]);
                    }
                }
                if (Session["RoleGroupNames" + usergroupid] != null)
                {
                    Session.Remove("RoleGroupNames" + usergroupid);
                }
            }
            return(RedirectToAction("UserGroupsIndex", new { usertype = Request.QueryString["usertype"] }));
        }
        public ActionResult UserGroup()
        {
            UserGroupModel         model  = new UserGroupModel();
            UserGroupServiceClient client = null;

            try
            {
                UserDto CurrentUser = (UserDto)Session[Constants.SKCURRENTUSER];
                string  mode        = Request.QueryString["mode"] != null ? Request.QueryString["mode"].ToString() : string.Empty;
                int     usergroupid = 0;
                if (Request.QueryString["usergroupid"] != null)
                {
                    usergroupid = Convert.ToInt32(Request.QueryString["usergroupid"]);
                }

                Nullable <int> caID = null;
                if (!string.IsNullOrEmpty(Request.QueryString["CAId"]))
                {
                    caID         = Convert.ToInt32(Request.QueryString["CAId"]);
                    model.Client = GetClient(Convert.ToInt32(caID));
                }

                string usertype = "";
                if (!string.IsNullOrEmpty(Request.QueryString["userType"]))
                {
                    usertype = Request.QueryString["userType"];
                }

                if (usertype == "AckUser" && !Helper.IsCAIdNotNull(CurrentUser))
                {
                    model.CAId = null;
                }
                else if (usertype == "CAUser" && (caID != null || caID != 0))
                {
                    model.CAId = caID;
                }
                else
                {
                    model.CAId = Helper.GetCAIdOfUser(CurrentUser);
                }

                if (mode == "edit")
                {
                    FormMode = mode;
                    client   = new UserGroupServiceClient();
                    UserGroupDto ugdto = client.GetById(usergroupid);
                    Id = ugdto.UserGroupId;
                    model.UserGroupName = ugdto.UserGroupName;
                    model.Description   = ugdto.Description;
                    model.IsActive      = ugdto.IsActive;
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error"));
            }
            finally
            {
                if (client != null && client.State == System.ServiceModel.CommunicationState.Opened)
                {
                    client.Close();
                }
            }
            return(View("CreateUserGroup", model));
        }