Ejemplo n.º 1
0
        public HttpResponseMessage PutInRole(int userId, int roleId)
        {
            //System.Threading.Thread.Sleep(2000); // test api latency

            var command = new GrantRoleToUser(User, roleId, userId);

            try
            {
                _grantRole.Handle(command);
            }
            catch (ValidationException ex)
            {
                var badRequest = Request.CreateResponse(HttpStatusCode.BadRequest,
                    ex.Errors.First().ErrorMessage, "text/plain");
                return badRequest;
            }

            var response = Request.CreateResponse(HttpStatusCode.OK, "Access was granted successfully.");
            return response;
        }
Ejemplo n.º 2
0
        public void Handle(GrantRoleToUser message)
        {
            var role = _roleRepository.Get(new RoleId(message.RoleId));

            ForUser(message.UserId).GrantRole(role);
        }
Ejemplo n.º 3
0
        public HttpResponseMessage ValidateGrant(int userId, int roleId)
        {
            //System.Threading.Thread.Sleep(2000); // test api latency

            var command = new GrantRoleToUser(User, roleId, userId);
            var validationResult = _grantValidator.Validate(command);

            if (validationResult.Errors.Any())
                return Request.CreateResponse(HttpStatusCode.BadRequest,
                    validationResult.Errors.First().ErrorMessage, "text/plain");

            return Request.CreateResponse(HttpStatusCode.OK);
        }