Example #1
0
        public async Task <ActionResult> CustomerMove(int key, [SingleParameterBinder(typeof(NewAddress))] NewAddress newAddress)
        {
            if (newAddress == null)
            {
                return(this.Problem(ProblemJsonBuilder.CreateBadParameters()));
            }

            try
            {
                var customer = await customerRepository.GetEnitityByKeyAsync(key);

                var hypermediaCustomer = new HypermediaCustomer(customer);
                hypermediaCustomer.MoveAction.Execute(newAddress);
                return(Ok());
            }
            catch (EntityNotFoundException)
            {
                return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound()));
            }
            catch (CanNotExecuteActionException)
            {
                return(this.CanNotExecute());
            }
            catch (ActionParameterValidationException e)
            {
                var problem = new ProblemJson()
                {
                    Title       = $"Can not use provided object of type '{typeof(NewAddress)}'",
                    Detail      = e.Message,
                    ProblemType = "WebApiHypermediaExtensionsCore.Hypermedia.BadActionParameter",
                    StatusCode  = 422 // Unprocessable Entity
                };
                return(this.UnprocessableEntity(problem));
            }
        }
Example #2
0
        public async Task <ActionResult> GetEntity(int key)
        {
            try
            {
                var customer = await customerRepository.GetEnitityByKeyAsync(key);

                var result = new HypermediaCustomer(customer);
                return(Ok(result));
            }
            catch (EntityNotFoundException)
            {
                return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound()));
            }
        }
Example #3
0
        public async Task <ActionResult> MarkAsFovoriteAction(int key)
        {
            try
            {
                var customer = await customerRepository.GetEnitityByKeyAsync(key);

                var hypermediaCustomer = new HypermediaCustomer(customer);
                hypermediaCustomer.MarkAsFavoriteAction.Execute();
                return(Ok());
            }
            catch (EntityNotFoundException)
            {
                return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound()));
            }
            catch (CanNotExecuteActionException)
            {
                return(this.CanNotExecute());
            }
        }