コード例 #1
0
        public async Task <ActionResult> Put(int id, [FromForm] CreationProductDTO creationProductDTO)
        {
            var entity = mapper.Map <Product>(creationProductDTO);

            entity.Id = id;
            context.Entry(entity).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult> Post([FromForm] CreationProductDTO creationProductDTO)
        {
            var entity = mapper.Map <Product>(creationProductDTO);

            context.Add(entity);
            using (var stream = new MemoryStream())
            {
                await creationProductDTO.Image.CopyToAsync(stream);

                entity.Image = Convert.ToBase64String(stream.ToArray());
            }
            await context.SaveChangesAsync();

            var dto = mapper.Map <ProductDTO>(entity);

            return(new CreatedAtRouteResult("GetProduct", new { id = entity.Id }, dto));
        }