コード例 #1
0
        public IActionResult UpdateColor(int id, ProductColorDto color)
        {
            if (id != color.Id)
            {
                return(BadRequest());
            }

            try
            {
                _colorService.Modify(new ProductColor {
                    Id = color.Id, Name = color.Name
                });
            }
            catch (DbUpdateConcurrencyException)
            {
                return(NotFound());
            }
            catch (DbUpdateException ex)
            {
                if (ex?.InnerException?.Message != null)
                {
                    return(BadRequest(ex?.InnerException?.Message));
                }
                else
                {
                    return(BadRequest(ex?.Message));
                }
            }

            return(NoContent());
        }
コード例 #2
0
 private static ProductColorCommand ToCommand(this ProductColorDto color)
 {
     return(new ProductColorCommand
     {
         Name = color.Name,
         Code = color.Code,
     });
 }
コード例 #3
0
        private static List <ProductColorDto> CreateProductColors(ProductDto productDto, int[] colorIds)
        {
            var productColors = new List <ProductColorDto>();

            for (int i = 0; i < colorIds.Length; i++)
            {
                var productColor = new ProductColorDto()
                {
                    ProductId = productDto.Id, ColorId = colorIds[i]
                };
                productColors.Add(productColor);
            }
            productDto.ProductColors = productColors;
            return(productColors);
        }
コード例 #4
0
        public string create(ProductColorDto tProductColorDto)
        {
            try
            {
                ProductColor tProductColorNew = mapper.Map <ProductColorDto, ProductColor>(tProductColorDto);
                tProductColorNew.Id         = Guid.NewGuid().ToString();
                tProductColorNew.CreateDate = DateTime.Now;

                _context.ProductColor.Add(tProductColorNew);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
コード例 #5
0
        public ActionResult <ProductColorDto> CreateColor(ProductColorDto color)
        {
            try
            {
                var productColor = _colorService.Create(new ProductColor {
                    Id = color.Id, Name = color.Name
                });
                color.Id = productColor.Id;
            }
            catch (DbUpdateException ex)
            {
                if (ex?.InnerException?.Message != null)
                {
                    return(BadRequest(ex?.InnerException?.Message));
                }
                else
                {
                    return(BadRequest(ex?.Message));
                }
            }

            return(CreatedAtAction(nameof(GetColor), new { id = color.Id }, color));
        }
コード例 #6
0
        //Update
        public string update(ProductColorDto tProductColorDto)
        {
            try
            {
                ProductColor tProductColorUpdate = _context.ProductColor.Find(tProductColorDto.Id);
                if (tProductColorUpdate == null)
                {
                    return("1");
                }
                tProductColorUpdate.Id         = tProductColorDto.Id;
                tProductColorUpdate.Name       = tProductColorDto.Name;
                tProductColorUpdate.Status     = tProductColorDto.Status;
                tProductColorUpdate.CreateDate = tProductColorDto.CreateDate;
                tProductColorUpdate.CreateUser = tProductColorDto.CreateUser;

                _context.ProductColor.Update(tProductColorUpdate);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
コード例 #7
0
        public IActionResult Update([FromBody] ProductColorDto value)
        {
            string result = _productColor.update(value);

            return(new ObjectResult(result));
        }