示例#1
0
        public async Task <IResult> Update(UpdateProposalLogRequest dto)
        {
            var isExists = await _proposalDal.Get(p => p.Id == dto.Id);

            if (isExists == null)
            {
                return(new ErrorResult(Messages.EntityNotFound));
            }
            isExists.SerializedResponse = JsonConvert.SerializeObject(dto.Response);
            await _proposalDal.Update(isExists);

            return(new SuccessResult(Messages.OperationSuccess));
        }
示例#2
0
        public async Task InvokeAsync(HttpContext httpContext, IProposalService proposalService)
        {
            try
            {
                if (httpContext.Request.Path.Value == "/Home/GetProposal")
                {
                    var jsonRequestString = await FormatRequest(httpContext.Request);

                    AddProposalLogRequest addLogRequest = JsonConvert.DeserializeObject <AddProposalLogRequest>(jsonRequestString);
                    var addLogResult = await proposalService.Add(addLogRequest);

                    var originalBodyStream = httpContext.Response.Body;

                    using (var responseBody = new MemoryStream())
                    {
                        httpContext.Response.Body = responseBody;

                        await _next(httpContext);

                        var jsonResponseString = await FormatResponse(httpContext.Response);

                        var response         = JsonConvert.DeserializeObject <GetProposalResponse>(jsonResponseString);
                        var updateLogRequest = new UpdateProposalLogRequest
                        {
                            Id       = addLogResult.Data.Id,
                            Response = JsonConvert.SerializeObject(response)
                        };
                        await proposalService.Update(updateLogRequest);

                        await responseBody.CopyToAsync(originalBodyStream);
                    }
                }
                else
                {
                    await _next(httpContext);
                }
            }
            catch (Exception e)
            {
                //await HandleExceptionAsync(httpContext, e);
            }
        }