public async Task <ServiceResponse <GetProductStockLogDto> > UpdateStockLog(UpdateStockProduct updateStock) { ServiceResponse <GetProductStockLogDto> res = new ServiceResponse <GetProductStockLogDto>(); ProductStockLog stockLog = await _db.ProductStockLogs .Include(x => x.Product) .FirstOrDefaultAsync(c => c.StockLogId == updateStock.StockLogId); if (stockLog == null) { return(ResponseResult.Failure <GetProductStockLogDto>("data not found")); } try { stockLog.NewEdit = updateStock.NewEdit; stockLog.UpdatedDate = DateTime.Now; stockLog.AmountAfter = updateStock.AmountAfter; stockLog.AmountBefore = updateStock.AmountBefore; stockLog.TextRemark = updateStock.TextRemark; stockLog.IsActice = updateStock.IsActice; _db.ProductStockLogs.Update(stockLog); await _db.SaveChangesAsync(); res.Data = _mapper.Map <GetProductStockLogDto>(stockLog); } catch (Exception ex) { res.IsSuccess = false; res.Message = ex.Message; } return(res); }
public async Task <IActionResult> UpdateProductStockUpdate(UpdateStockProduct update) { try { ServiceResponse <GetProductStockLogDto> res = await _productStockService.UpdateStockLog(update); if (res.Data == null) { return(NotFound(res)); } return(Ok(res)); } catch (Exception) { _logger.LogError("Failed to execute put"); return(BadRequest()); } }