public async Task <IActionResult> EditPiDetail([FromBody] PiDetailDto piDetailDto) { if (User.Identity.IsAuthenticated) { var result = await _piDetailService.EditPiInfo(piDetailDto); switch (result) { case PiDetailResult.CanNotUpdate: return(JsonResponseStatus.Error(new { info = "PI ویرایش نشد " })); } } return(JsonResponseStatus.Success()); }
public async Task <PiDetailResult> EditPiInfo(PiDetailDto piDetailDto) { var piDetail = await piDetailRepository.GetEntityById(piDetailDto.Id); if (piDetail == null) { return(PiDetailResult.CanNotUpdate); } #region Update Broker Balance if (piDetail.DepositPrice > piDetailDto.DepositPrice) { var updateBrokerAmount = await _brokerRepository.UpdateBrokerAmount(piDetail.BrokerId, piDetail.DepositPrice - piDetailDto.DepositPrice, false); if (!updateBrokerAmount) { return(PiDetailResult.CannotUpdateBrokerAmountBalance); } } else { var updateBrokerAmount = await _brokerRepository.UpdateBrokerAmount(piDetail.BrokerId, piDetailDto.DepositPrice - piDetail.DepositPrice, true); if (!updateBrokerAmount) { return(PiDetailResult.CannotUpdateBrokerAmountBalance); } } #endregion piDetail.DepositPrice = piDetailDto.DepositPrice; piDetail.DepositDate = piDetailDto.DepositDate; piDetail.BrokerId = piDetailDto.BrokerId; piDetail.PeroformaInvoiceId = piDetailDto.PiId; piDetail.IsSold = false; piDetailRepository.UpdateEntity(piDetail); await piDetailRepository.SaveChanges(); return(PiDetailResult.Success); }