public void ActionFromOperationResult_ReturnNotFound_WhenSuccessButEmptyData()
        {
            // Arrange
            var operationResult = OperationResult <IEnumerable <object> > .Success(new List <object>());

            // Act
            var result = ApiHelper.ActionFromOperationResult(operationResult);

            // Assert
            Assert.That(result, Is.TypeOf <NotFoundObjectResult>());
        }
        public void ActionFromOperationResult_ReturnBadRequest_WhenSuccessFalse()
        {
            // Arrange
            var operationResult = OperationResult <object> .Failed();

            // Act
            var result = ApiHelper.ActionFromOperationResult(operationResult);

            // Assert
            Assert.That(result, Is.TypeOf <BadRequestObjectResult>());
        }
        public async Task <IActionResult> Get(int id)
        {
            // Get all products
            var operationResult = await _productService.ReadAsync(p => p.Id == id);

            var newOperationResult = new OperationResult <Product>()
            {
                Data      = operationResult.Data.FirstOrDefault(),
                Succeeded = operationResult.Succeeded,
                Errors    = operationResult.Errors
            };

            return(ApiHelper.ActionFromOperationResult(newOperationResult));
        }
        public void ActionFromOperationResult_ReturnOk_WhenSuccess()
        {
            // Arrange
            var operationResult = OperationResult <object> .Success(new
            {
                Property = "Property"
            });

            // Act
            var result = ApiHelper.ActionFromOperationResult(operationResult);

            // Assert
            Assert.That(result, Is.TypeOf <OkObjectResult>());
        }
        public async Task <IActionResult> Post(Product product)
        {
            if (!ModelState.IsValid)
            {
                var error = new OperationError
                {
                    Name        = "Invalid",
                    Description = "Model is not valid"
                };

                return(BadRequest(OperationResult.Failed(error)));
            }

            var productCreateResult = await _productService.CreateAsync(product);

            return(ApiHelper.ActionFromOperationResult(productCreateResult));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Profile([FromBody] ProfileModel model)
        {
            if (!ModelState.IsValid)
            {
                var error = new OperationError
                {
                    Name        = "Invalid",
                    Description = "Model is not valid"
                };

                return(BadRequest(OperationResult.Failed(error)));
            }

            var profileResult = await _accountService.UpdateProfileAsync(User.FindFirst(JwtRegisteredClaimNames.UniqueName).Value, model);

            return(ApiHelper.ActionFromOperationResult(profileResult));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Register([FromBody] RegistrationModel model)
        {
            if (!ModelState.IsValid)
            {
                var error = new OperationError
                {
                    Name        = "Invalid",
                    Description = "Model is not valid"
                };

                return(BadRequest(OperationResult.Failed(error)));
            }

            var registrationResult = await _accountService.RegisterAsync(model);

            return(ApiHelper.ActionFromOperationResult(registrationResult));
        }
        public async Task <IActionResult> Delete(int id)
        {
            var productCreateResult = await _productService.RemoveAsync(id);

            return(ApiHelper.ActionFromOperationResult(productCreateResult));
        }
Ejemplo n.º 9
0
        //[ProducesResponseType(StatusCodes.Status403Forbidden)]
        public async Task <IActionResult> Profile()
        {
            var profile = await _accountService.GetProfileAsync(User.FindFirst(JwtRegisteredClaimNames.UniqueName).Value);

            return(ApiHelper.ActionFromOperationResult(profile));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> UpdateUser(string userId, [FromBody] ProfileModel model)
        {
            var result = await _administratorService.UpdateUserAsync(userId, model);

            return(ApiHelper.ActionFromOperationResult(result));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Users()
        {
            var result = await _administratorService.GetUsersAsync();

            return(ApiHelper.ActionFromOperationResult(result));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> RemoveRole(string roleId)
        {
            var result = await _administratorService.RemoveRoleAsync(roleId);

            return(ApiHelper.ActionFromOperationResult(result));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> AddRole([FromBody] RoleViewModel viewModel)
        {
            var result = await _administratorService.AddRoleAsync(viewModel);

            return(ApiHelper.ActionFromOperationResult(result));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Permissions()
        {
            var permissions = await _administratorService.GetPermissionsAsync();

            return(ApiHelper.ActionFromOperationResult(permissions));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Roles()
        {
            var roles = await _administratorService.GetRolesAsync();

            return(ApiHelper.ActionFromOperationResult(roles));
        }