Beispiel #1
0
 public async Task <IActionResult> EditProductGroup(ProductGroupDTO_ToAdd input, int id)
 {
     return(Ok(await service.EditProductGroup(input, id)));
 }
        public async Task <ServiceResponse <ProductGroupDTO_ToReturn> > EditProductGroup(ProductGroupDTO_ToAdd input, int id)
        {
            var productGroup = await GetActiveProductGroupById(id);

            try
            {
                if (productGroup is null)
                {
                    var logMsg = $"ProductGroup id:{id} not found";
                    _logger.LogWarning(logMsg);
                    return(ResponseResult.Failure <ProductGroupDTO_ToReturn>(logMsg));
                }

                productGroup.Name        = input.Name;
                productGroup.IconName    = input.IconName;
                productGroup.UpdatedBy   = GetUsername();
                productGroup.UpdatedDate = Now();

                _context.Update(productGroup);
                await _context.SaveChangesAsync();

                var dto = _mapper.Map <ProductGroupDTO_ToReturn>(productGroup);
                return(ResponseResult.Success <ProductGroupDTO_ToReturn>(dto));
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message);
                return(ResponseResult.Failure <ProductGroupDTO_ToReturn>(ex.Message));
            }
        }
Beispiel #3
0
 public async Task <IActionResult> AddProductGroup(ProductGroupDTO_ToAdd input)
 {
     return(Ok(await service.AddProductGroup(input)));
 }
        public async Task <ServiceResponse <ProductGroupDTO_ToReturn> > AddProductGroup(ProductGroupDTO_ToAdd input)
        {
            try
            {
                var productGroupToAdd = new ProductGroup();
                productGroupToAdd.Name        = input.Name;
                productGroupToAdd.IconName    = input.IconName;
                productGroupToAdd.CreatedBy   = GetUsername();
                productGroupToAdd.CreatedDate = Now();
                productGroupToAdd.UpdatedBy   = GetUsername();
                productGroupToAdd.UpdatedDate = Now();
                productGroupToAdd.IsActive    = true;
                await _context.ProductGroups.AddAsync(productGroupToAdd);

                await _context.SaveChangesAsync();

                var dto = _mapper.Map <ProductGroupDTO_ToReturn>(productGroupToAdd);
                return(ResponseResult.Success <ProductGroupDTO_ToReturn>(dto));
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message);
                return(ResponseResult.Failure <ProductGroupDTO_ToReturn>(ex.Message));
            }
        }