public ActionResult<Order> Get(String id)//return JSON { if(!ValidateToken()) { var err401 = new Test_Unhar.Models.Error(1105,"Invalid token","This token alredy expired"); return new UnauthorizedObjectResult(err401); } var order = _orderRepository.Find(id); if (order == null) { var err404 = new Test_Unhar.Models.Error(135,"Order not found","Cannot find order with id: "+id); return new NotFoundObjectResult(err404); } return new OkObjectResult(order.response); }
public ActionResult<Order> Get([FromQuery] int start=0, [FromQuery] int quantity=int.MaxValue, [FromQuery] String status="") { IEnumerable<Order.Response> orders; if(!ValidateToken()) { var err401 = new Test_Unhar.Models.Error(1105,"Invalid token","This token alredy expired"); return new UnauthorizedObjectResult(err401); } if(_orderRepository.Quantity==0) {return NoContent();} orders = _orderRepository.FindPageReponse(start, quantity, status); if(orders.Count() == 0) {return NoContent();} return new OkObjectResult(orders); }
public ActionResult<Order.Response> Create([FromBody] Order.Request request) { if(!ValidateToken()) { var err401 = new Test_Unhar.Models.Error(1105,"Invalid token","This token alredy expired"); return new UnauthorizedObjectResult(err401); }; if (request == null) { var err422 = new Test_Unhar.Models.Error(1050,"Invalid data","Invalid location field in incoming object"); return new UnprocessableEntityObjectResult(err422); }; string _id = _orderRepository.Insert(request); return new ObjectResult(_orderRepository.Find(_id).response) {StatusCode = StatusCodes.Status201Created}; /*var baseUrl = Request.Path; return new CreatedResult(baseUrl+"/" + _id.ToString(),_orderRepository.Find(_id).response);*/ }