Ejemplo n.º 1
0
        public async Task <dynamic> Upload([FromForm] UploadNoteModel note)
        {
            if (!this.IsTokenValid(_tokenService.GetTemporaryToken(this.GetCurrentUserId())))
            {
                throw new UnauthorizedAccessException();
            }

            if (!ModelState.IsValid)
            {
                return(this.ResultAsync(HttpStatusCode.BadRequest));
            }

            var    command     = _mapper.Map <AddNoteCommand>(note);
            string fileAddress = null;

            if (note.File != null)
            {
                fileAddress = await _mediator.Send(new UploadFileCommand { File = note.File, UploadType = UploadType.Notes });
            }

            command.UserId          = this.GetCurrentUserId();
            command.AttachementPath = Request.GetDisplayUrl() + "?filename=" + fileAddress;
            command.BeneficiaryId   = note.BeneficiaryId;

            var result = await _mediator.Send(command);

            if (result < 0)
            {
                return(this.ResultAsync(HttpStatusCode.NotFound));
            }

            return(await Task.FromResult(new { FileAddress = command.AttachementPath }));
        }
Ejemplo n.º 2
0
        public async Task <dynamic> Upload([FromForm] UploadNoteModel note)
        {
            if (!ModelState.IsValid)
            {
                return(this.ResultAsync(HttpStatusCode.BadRequest));
            }

            // TODO[DH] use a pipeline instead of separate Send commands
            // daca nota este asociata sectiei
            var idSectie = await _mediator.Send(_mapper.Map <PollingStationQuery>(note));

            if (idSectie < 0)
            {
                return(this.ResultAsync(HttpStatusCode.NotFound));
            }

            var command = _mapper.Map <AddNoteCommand>(note);

            command.IdObserver       = int.Parse(User.Claims.First(c => c.Type == ClaimsHelper.ObserverIdProperty).Value);
            command.IdPollingStation = idSectie;

            if (note.File != null)
            {
                var fileAddress = await _mediator.Send(new UploadFileCommand { File = note.File, UploadType = UploadType.Notes });

                command.AttachementPath = fileAddress;
            }

            var result = await _mediator.Send(command);

            if (result < 0)
            {
                return(this.ResultAsync(HttpStatusCode.NotFound));
            }

            return(await Task.FromResult(new { FileAddress = command.AttachementPath, note }));
        }