Ejemplo n.º 1
0
        public async Task <IActionResult> AddPublication([FromForm] PublicationDTO publicationDTO)
        {
            try
            {
                using (var ms = new MemoryStream())
                {
                    await publicationDTO.file.CopyToAsync(ms);

                    publicationDTO.Imagen = ms.ToArray();
                }
                //publicationDTO.FechaCreacion = DateTime.Now;
                //publicationDTO.FechaPublicacion = DateTime.Now;
                var publication = _mapper.Map <Publicacione>(publicationDTO);
                var resp        = await _publicationServices.AddPublication(publication);

                if (resp == null)
                {
                    return(StatusCode(StatusCodes.Status404NotFound, resp));
                }
                //return StatusCode(StatusCodes.Status201Created, user);
                //return CreatedAtAction(nameof(GetUserByID), new { id = user.IdUsuario }, userDTO);
                await _hubContext.Clients.All.SendAsync("NewPublication", publication.Titulo);

                return(StatusCode(StatusCodes.Status201Created, publication));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }