Esempio n. 1
0
        public HttpResponseMessage CreateTender([FromBody] PATRequest tenderRequest)
        {
            if (!_clientValidator.Validate(Request.GetClientCertificate(), Request.Headers.Authorization, out string message))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new UnauthorizedAccessException(message)));
            }

            log.DebugEx(tr => tr.Set("POST ~/api/tenders", tenderRequest));

            // Extract the tender from the request
            if (tenderRequest == null || tenderRequest.Tender == null)
            {
                log.ErrorEx(tr => tr.Set("TenderRequest.Tender==NULL in POST ~/api/tenders."));
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "TenderRequest.Tender==NULL"));
            }

            try
            {
                var r = new PATResponse {
                    Tender = _tendersRepository.CreateTender(tenderRequest.Tender)
                };
                log.DebugEx(tr => tr.Set("return", r));
                return(Request.CreateResponse(HttpStatusCode.Created, r));
            }
            catch (InvalidRequestException ex)
            {
                log.ErrorEx(tr => tr.Set("InvalidRequestException in POST ~/api/tenders.", ex));
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
            catch (ResourceNotFoundException ex)
            {
                log.ErrorEx(tr => tr.Set("ResourceNotFoundException in POST ~/api/tenders.", ex));
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }
        }
        public HttpResponseMessage CreateTender([FromBody] PATRequest tenderRequest)
        {
            log.DebugEx(tr => tr.Set("POST ~/api/tenders", tenderRequest));

            // Extract the tender from the request
            if (tenderRequest == null || tenderRequest.Tender == null)
            {
                log.ErrorEx(tr => tr.Set("TenderRequest.Tender==NULL in POST ~/api/tenders."));
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "TenderRequest.Tender==NULL"));
            }

            try
            {
                var r = new PATResponse {
                    Tender = _tendersRepository.CreateTender(tenderRequest.Tender)
                };
                log.DebugEx(tr => tr.Set("return", r));
                return(Request.CreateResponse(HttpStatusCode.OK, r));
            }
            catch (InvalidRequestException ex)
            {
                log.ErrorEx(tr => tr.Set("InvalidRequestException in POST ~/api/tenders.", ex));
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
            catch (ResourceNotFoundException ex)
            {
                log.ErrorEx(tr => tr.Set("ResourceNotFoundException in POST ~/api/tenders.", ex));
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }
        }
Esempio n. 3
0
        async Task HandleCreateTender(POSAPIMsg request)
        {
            var patRequest = JsonConvert.DeserializeObject <PATRequest>(request.Content);

            if (patRequest == null || patRequest.Tender == null)
            {
                _logger.Log($"Invalid Request found in: {request.Header.RequestType} {request.Header.RequestMethod}", LogType.ERROR);
                return;
            }

            await HandleRequest(request, () => new PATResponse { Tender = _tendersRepository.CreateTender(patRequest.Tender) });
        }
        private void HandleCreateTender(POSAPIMsg request)
        {
            var patRequest = JsonConvert.DeserializeObject <PATRequest>(request.Content);

            if (patRequest == null || patRequest.Tender == null)
            {
                Log($"Invalid Request found in: {request.Header.RequestType} {request.Header.RequestMethod}", LogType.ERROR);
                return;
            }

            HandleRequest(request, () => new PATResponse {
                Tender = tendersRepository.CreateTender(patRequest.Tender)
            });
            myApiDataViewModel.CurrentOrder = patRequest.Tender.OrderId;
            myApiDataViewModel.UpdateOrderStatus();
        }