Beispiel #1
0
        public void TestUserAssignAndRemoveRole()
        {
            var userID = new Random().Next(1, 10);

            var assignRole = new UserAssignRole(userID, ManagerType.DepositOfficer, 1);
            var removeManager = new RemoveManager(1, 1, 1);

            Assert.DoesNotThrow(delegate
            {
                this.commandBus.Send(assignRole);
            });

            Assert.DoesNotThrow(delegate
            {
                this.commandBus.Send(removeManager);
            });
        }
Beispiel #2
0
        public ActionResult AssignUserRole(int userID, ManagerType role)
        {
            if (userID <= 0) return Json(new JsonResult(-1));

            bool exist = IoC.Resolve<IManagerQuery>().ExistManager(userID, role);

            if (exist) return Json(new JsonResult(-2));
            else
            {
                try
                {
                    var cmd = new UserAssignRole(userID, role, this.CurrentUser.UserID);
                    this.CommandBus.Send(cmd);
                    return Json(JsonResult.Success);
                }
                catch (CommandExecutionException ex)
                {
                    if (ex.ErrorCode == (int)ErrorCode.NoPermission)
                        return Json(new JsonResult(-3));
                    else return Json(new JsonResult(ex.ErrorCode));
                }
            }
        }