Пример #1
0
        async Task HandleUpdateTender(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.UpdateTender(patRequest.Tender) });
        }
        private void HandleUpdateTender(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.UpdateTender(patRequest.Tender)
            });
            myApiDataViewModel.CurrentOrder = patRequest.Tender.OrderId;
            myApiDataViewModel.UpdateTableData();
        }
Пример #3
0
        public HttpResponseMessage UpdateTender(string id, [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("PUT ~/api/tenders", tenderRequest));

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

            // Validate the tender id
            if (!tenderRequest.Tender.Id.Equals(id))
            {
                log.ErrorEx(tr => tr.Set("tenderRequest.Tender.Id != param id in PUT ~/api/tenders."));
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "tenderRequest.Tender.Id != param id"));
            }

            try
            {
                var r = new PATResponse {
                    Tender = _tendersRepository.UpdateTender(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 PUT ~/api/tenders.", ex));
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
            catch (ResourceNotFoundException ex)
            {
                log.ErrorEx(tr => tr.Set("ResourceNotFoundException in PUT ~/api/tenders.", ex));
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }
        }