예제 #1
0
        public async Task <ServiceResponse <GetProductAuditDto> > AddProductAudit(AddProductAuditDto newProductAudit)
        {
            var product = await _dbContext.Products.FirstOrDefaultAsync(x => x.Id == newProductAudit.ProductId);

            if (product == null)
            {
                return(ResponseResult.Failure <GetProductAuditDto>("Product Not Found."));
            }

            var productAudit = new mProductAudit
            {
                Name               = newProductAudit.Name,
                StockCount         = newProductAudit.StockCount,
                AuditAmount        = newProductAudit.AuditAmount,
                AuditTotalAmount   = newProductAudit.AuditTotalAmount,
                Remark             = newProductAudit.Remark,
                CreateBy           = GetUsername(),
                CreateDate         = Now(),
                ProductGroupId     = newProductAudit.ProductGroupId,
                ProductId          = newProductAudit.ProductId,
                ProductAuditTypeId = newProductAudit.ProductAuditTypeId,
            };

            _dbContext.ProductAudits.Add(productAudit);
            await _dbContext.SaveChangesAsync();

            var dto = _mapper.Map <GetProductAuditDto>(productAudit);

            return(ResponseResult.Success(dto));
        }
 public async Task <IActionResult> AddProductAudit(AddProductAuditDto newAudit)
 {
     return(Ok(await _prodService.AddProductAudit(newAudit)));
 }