public async Task <IActionResult> Edit(RemittanceEditModel model) { var Result = await RemittanceService.Edit(model, User); return(Ok(Result)); }
public async Task <Response> Edit(RemittanceEditModel model, ClaimsPrincipal User) { using (var uow = UnitOfWorkFactory.Create()) { if (model == null) { return new Response { Status = StatusEnum.Error, Message = "ничего на сервер не отправлено" } } ; if (model.Score2Id == model.ScoreId) { return new Response { Status = StatusEnum.Error, Message = "Перевод осуществляется на один и тот же счет!" } } ; if (!uow.Scores.Check(model.ScoreId)) { return new Response { Status = StatusEnum.Error, Message = $"Нет такого счета!" } } ; if (!uow.Scores.Check(model.Score2Id)) { return new Response { Status = StatusEnum.Error, Message = $"Нет такого счета!" } } ; Score OldScore1 = null; Score OldScore2 = null; Score NewScore1 = await uow.Scores.GetByIdAsync(model.ScoreId); Score NewScore2 = await uow.Scores.GetByIdAsync(model.Score2Id); var Remittance = Mapper.Map <Remittance>(model); Remittance.Discriminator = "Remittance"; var OldScoresId = uow.Remittances.GetRemmiranceScoreId(Remittance.Id); if (OldScoresId.Item1 != Remittance.ScoreId) { OldScore1 = await uow.Scores.GetByIdAsync(OldScoresId.Item1); } if (OldScoresId.Item2 != Remittance.Score2Id) { OldScore2 = await uow.Scores.GetByIdAsync(OldScoresId.Item2); } var OldSum = uow.FinanceActions.GetSumFinanceAction(Remittance.Id); var HelperModel = new RemittanceEditHelperModelBuilder() .SetOldScore1(OldScore1) .SetOldScore2(OldScore2) .SetNewScore1(NewScore1) .SetNewScore2(NewScore2) .SetOldTransactionSum(OldSum) .SetNewTransactionSum(Remittance.Sum) .Build(); var Result = await CheckEditScore(HelperModel); if (!Result.Item1) { return new Response { Status = StatusEnum.Error, Message = Result.Item2 } } ; var _User = await UserManager.FindByNameAsync(User.Identity.Name); Remittance.UserId = _User.Id; Remittance.ProjectId = await uow.Projects.GetNullProjectId(); Remittance.OperationId = await uow.Operations.GetTransferOperationId(); await uow.Remittances.UpdateAsync(Remittance); return(new Response { Status = StatusEnum.Accept, Message = "Редактирование перевода прошло успешно." }); } }