Exemplo n.º 1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            UpdateDocumentResponse response = new UpdateDocumentResponse();


            return(response);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            UpdateDocumentResponse response = new UpdateDocumentResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("DocumentDescription", targetDepth))
                {
                    var unmarshaller = DocumentDescriptionUnmarshaller.Instance;
                    response.DocumentDescription = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UpdateDocument([FromBody] UpdateDocumentRequest request)
        {
            var updateDocumentResponse = new UpdateDocumentResponse();

            if (request.File == null || request.File.Length <= 0)
            {
                return(new BadRequestObjectResult(new { Message = "Requested file can not be empty." }));
            }
            var filePath = Path.GetTempFileName();
            var fileName = Path.GetFileName(filePath);

            if (!FileTypes.IsValidContentType(fileName))
            {
                ModelState.AddModelError(fileName, "File Type Not Supported. Only Word, Pdf, Jpg and Png file types uploadable.");
            }
            if (request.File.Length > 1048576)
            {
                ModelState.AddModelError(fileName, "Maximum File size of 1 Mb exceeded.");
            }
            if (ModelState.Values.Sum(c => c.Errors.Count) > 0)
            {
                updateDocumentResponse.HandleValidation(ModelState);
                return(Ok(updateDocumentResponse));
            }
            var updateModel = new UpdateDocumentModel
            {
                DocumentId     = request.DocumentId,
                ProjectId      = request.ProjectId,
                DocumentTypeId = request.DocumentTypeId,
                TagId          = request.TagId,
                UploadedFile   = new FileModel
                {
                    Content = request.File.OpenReadStream(),
                    Name    = fileName
                }
            };

            var commandHandlerResponse = await _mediator.Send(updateModel);

            updateDocumentResponse.HandleSuccess(commandHandlerResponse);
            return(Ok(updateDocumentResponse));
        }