Ejemplo n.º 1
0
        public async Task <IActionResult> AddImage(int id, [FromBody] string avatarUrl)
        {
            var    c = new HttpClient();
            Stream i;

            try
            {
                i = await c.GetStreamAsync(avatarUrl);
            }
            catch (Exception e) when(e is HttpRequestException || e is ArgumentException)
            {
                return(BadRequest("Avatar invalido"));
            }


            var command = new AddOrUpdateAvatarCommand()
            {
                UserId      = id,
                ImageStream = i,
                Compression = 100
            };

            await Mediator.Send(command);


            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddImage(int id, IFormFile image)
        {
            if (image == null)
            {
                return(BadRequest("Imagen invalida"));
            }


            var command = new AddOrUpdateAvatarCommand()
            {
                UserId      = id,
                ImageStream = image.OpenReadStream(),
            };

            await Mediator.Send(command);


            return(Ok());
        }