Ejemplo n.º 1
0
        public async Task <ActionResult> Put(int id, [FromForm] LotterySaleDTO lotterySaleCreacionDTO)
        {
            var lotterySaleDB = await context.LotterySales
                                .Include(x => x.LotterySaleItems)
                                .FirstOrDefaultAsync(x => x.Id == id);

            if (lotterySaleDB == null)
            {
                return(NotFound());
            }

            lotterySaleDB = mapper.Map(lotterySaleCreacionDTO, lotterySaleDB);

            //if (lotterySaleCreacionDTO.Poster != null)
            //{
            //    using (var memoryStream = new MemoryStream())
            //    {
            //        await lotterySaleCreacionDTO.Poster.CopyToAsync(memoryStream);
            //        var contenido = memoryStream.ToArray();
            //        var extension = Path.GetExtension(lotterySaleCreacionDTO.Poster.FileName);
            //        lotterySaleDB.Poster = await almacenadorArchivos.EditarArchivo(contenido, extension, contenedor,
            //            lotterySaleDB.Poster,
            //            lotterySaleCreacionDTO.Poster.ContentType);
            //    }
            //}

            // AsignarOrdenLotterySaleItems(lotterySaleDB);

            await context.SaveChangesAsync();

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Post([FromForm] LotterySaleDTO lotterySaleCreacionDTO)
        {
            var lotterySale = mapper.Map <LotterySale>(lotterySaleCreacionDTO);

            //if (lotterySaleCreacionDTO.Poster != null)
            //{
            //    using (var memoryStream = new MemoryStream())
            //    {
            //        await lotterySaleCreacionDTO.Poster.CopyToAsync(memoryStream);
            //        var contenido = memoryStream.ToArray();
            //        var extension = Path.GetExtension(lotterySaleCreacionDTO.Poster.FileName);
            //       // lotterySale.Poster = await almacenadorArchivos.GuardarArchivo(contenido, extension, contenedor,
            //            //lotterySaleCreacionDTO.Poster.ContentType);
            //    }
            //}

            //  AsignarOrdenLotterySaleItems(lotterySale);
            context.Add(lotterySale);
            await context.SaveChangesAsync();

            var lotterySaleDTO = mapper.Map <LotterySaleDTO>(lotterySale);

            return(new CreatedAtRouteResult("obtenerLotterySale", new { id = lotterySale.Id }, lotterySaleDTO));
        }