예제 #1
0
        public async Task <ServiceResponse <GetProductGroupDto> > EditProductGroup(EditProductGroup productGroup)
        {
            try
            {
                //Find ProductGroup
                var prodGrp = await _dBContext.ProductGroups.Include(x => x.Product).Include(x => x.CreateBy).FirstOrDefaultAsync(x => x.Id == productGroup.Id);

                if (prodGrp == null)
                {
                    return(ResponseResult.Failure <GetProductGroupDto>("ProductGroup Id not found"));
                }

                //Update data
                prodGrp.Name     = productGroup.Name;
                prodGrp.IsActive = productGroup.IsActive;
                _dBContext.Update(prodGrp);
                await _dBContext.SaveChangesAsync();

                //Mapping
                GetProductGroupDto prodGrpDto = _mapper.Map <GetProductGroupDto>(prodGrp);
                return(ResponseResult.Success(prodGrpDto));
            }
            catch (System.Exception ex)
            {
                //Write log
                _log.LogError($"Update product is error detail: {ex.Message}");
                //Return
                return(ResponseResult.Failure <GetProductGroupDto>($"Update ProductGroup error detail: {ex.Message}"));
            }
        }
 public async Task <IActionResult> EditProductGroup(EditProductGroup editProductGroup)
 {
     return(Ok(await _productGroupService.EditProductGroup(editProductGroup)));
 }