Exemple #1
0
        private IList <UserRoleListItemModel> GetUserRoleListItems(UserRoleSearchModel model)
        {
            var userEmail = model.UserEmail?.Split('|')[1];

            var userRoles         = UserRoleServices.Search(model.ApplicationIds, userEmail, model.RoleIds, model.RegionIds, model.CountryIds, model.IndustryIds);
            var userRoleListItems = Mapper.Map <IList <UserRoleEntity>, IList <UserRoleListItemModel> >(userRoles);

            return(userRoleListItems);
        }
Exemple #2
0
        public ActionResult _Add(UserRoleEditModel model)
        {
            switch (model.RoleId)
            {
            case 4:     // Industry Director
            case 12:
                model.RegionId  = null;
                model.CountryId = null;
                break;

            case 5:     // Region Director
            case 13:
                model.IndustryId = null;
                model.CountryId  = null;
                break;

            case 6:     // Country Director
            case 14:
                model.IndustryId = null;
                model.RegionId   = null;
                break;

            default:
                model.IndustryId = null;
                model.RegionId   = null;
                model.CountryId  = null;
                break;
            }

            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ModelState.GetErrors() }));
            }

            var userRole = Mapper.Map <UserRoleEditModel, UserRoleEntity>(model);

            var userId    = model.UserEmail.Split('|')[0];
            var userEmail = model.UserEmail.Split('|')[1];

            userRole.UserId    = Convert.ToInt32(userId);
            userRole.UserEmail = userEmail;

            var added = UserRoleServices.CreateUserRole(userRole);

            switch (added)
            {
            case -1:
                return(Json(new { success = false, title = "Error!", message = "User role could not added!" }));

            case 0:
                return(Json(new { success = false, title = "Already exists!", message = "User role could not added. It already exists." }));

            default:     // 1:
                return(Json(new { success = true, message = "User role added!" }));
            }
        }
Exemple #3
0
        public ActionResult _Delete(int id)
        {
            var userRole = UserRoleServices.Get(id);

            if (userRole == null)
            {
                return(Json(new { success = false, message = "User role could not found!" }, JsonRequestBehavior.AllowGet));
            }

            var deleted = UserRoleServices.DeleteUserRole(id);

            if (!deleted)
            {
                return(Json(new { success = false, message = "User role could not deleted!" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { success = true, message = "Deleted!" }, JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AssignRolesForUsers(object sender, DirectEventArgs e)
        {
            try
            {
                // delete role for each selected user
                foreach (var row in RowSelectionModel1.SelectedRows)
                {
                    // check user id
                    if (!string.IsNullOrEmpty(row.RecordID))
                    {
                        // delete roles for user
                        UserRoleServices.Delete(null, Convert.ToInt32(row.RecordID));
                    }
                }

                // get new role list
                var roleIds = hdfSelectedRoleIds.Text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                // add each user to selected role
                foreach (var row in RowSelectionModel1.SelectedRows)
                {
                    // check user id
                    if (!string.IsNullOrEmpty(row.RecordID))
                    {
                        foreach (var roleId in roleIds)
                        {
                            UserRoleServices.Create(new UserRole
                            {
                                UserId = Convert.ToInt32(row.RecordID),
                                RoleId = Convert.ToInt32(roleId)
                            });
                        }
                    }
                }

                // hide window
                wdAssignRole.Hide();
                // show dialog
                Dialog.ShowNotification("Thiết lập quyền thành công !");
            }
            catch (Exception ex)
            {
                // exception
                ExtNet.MessageBox.Alert("Có lỗi xảy ra", ex.Message).Show();
            }
        }
Exemple #5
0
 public UserRoleController(ILogger <UserRoleController> logger, UserRoleServices userRoleServices)
 {
     _logger           = logger;
     _userRoleServices = userRoleServices;
 }
 public UserRolesController()
 {
     UserRoleServices = new UserRoleServices();
 }