Ejemplo n.º 1
0
        public async Task <ActionResult> BuyCar(int key, BuyCarParameters parameter)
        {
            if (parameter == null)
            {
                var problem = new ProblemJson
                {
                    Title       = $"Can not use provided object of type '{typeof(BuyCarParameters)}'",
                    Detail      = "Json or contained links might be invalid",
                    ProblemType = "WebApi.HypermediaExtensions.Hypermedia.BadActionParameter",
                    StatusCode  = 422 // Unprocessable Entity
                };
                return(this.UnprocessableEntity(problem));
            }

            try
            {
                //shortcut for get car from repository
                var car      = new HypermediaCarHto(parameter.Brand, parameter.CarId);
                var customer = await customerRepository.GetEnitityByKeyAsync(key).ConfigureAwait(false);

                //do what has to be done
                return(Ok());
            }
            catch (EntityNotFoundException)
            {
                return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound()));
            }
            catch (CanNotExecuteActionException)
            {
                return(this.CanNotExecute());
            }
        }
Ejemplo n.º 2
0
 public ActionResult GetEntity(string brand, int id)
 {
     try
     {
         // short cut for example, we should actually call the Car repo and get a Car domain object
         var result = new HypermediaCarHto(brand, id);
         return(Ok(result));
     }
     catch (EntityNotFoundException)
     {
         return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound()));
     }
 }