public IActionResult UpdateModel([FromBody] ModelDTO modelDTO) { _logger?.LogInformation($"Inicio del servicio: [PUT] https://localhost:5001/api/models "); try{ ModelMapper modelMapper = MapperFactory.CreateModelMapper(); Entity entity = modelMapper.CreateEntity(modelDTO); _logger?.LogInformation($" Se transformó de DTO a Entity "); UpdateModelCommand command = CommandFactory.CreateUpdateModelCommand((Model)entity); _logger?.LogInformation($" Ejecución del comando "); command.Execute(); if (command.GetResult()) { return(Ok("La modificación fue realizada exitosamente")); } else { return(StatusCode(400)); } } catch (RequiredAttributeException ex) { _logger?.LogWarning("Atributo requerido: " + ex.Message); return(StatusCode(400, ex.Message)); } catch (ModelNotFoundException ex) { _logger?.LogWarning("Modelo con Id : " + ex.ModelId + "no encontrado"); return(StatusCode(404, ex.Message + ex.ModelId)); } catch (BrandNotFoundException ex) { _logger?.LogWarning("La marca con Id : " + ex.BrandId + "no encontrado"); return(StatusCode(404, ex.Message + ex.BrandId)); } catch (InternalServerErrorException ex) { _logger?.LogError("Error: " + ex.Ex.Message); return(StatusCode(500, ex.Message)); } catch (Exception) { _logger?.LogError("Error inesperado"); return(StatusCode(400)); } }
private void UpdateAccountInternal(int creditAccountId, DateTime specifiedDate) { var newCreditAccountState = UpdateFinesAndGetAccountState(creditAccountId, specifiedDate); var account = _creditAccountQueryRepository.Handle(new ModelQuery() { Id = creditAccountId }); if (account.IsClosed) { return; } if (newCreditAccountState != null) { var createModelCommand = new CreateModelCommand <CreditAccountStateDto>() { ModelDto = newCreditAccountState }; _creditAccountStateCommandRepository.Execute(createModelCommand); if (newCreditAccountState.RemainDebt.Value <= 0) { account.IsClosed = true; var updateModelCommand = new UpdateModelCommand <CreditAccountDto>() { ModelDto = account }; _creditAccountCommandRepository.Execute(updateModelCommand); } } }
private CreditAccountStateDto CloseAccount(CreditAccountDto account, CreditAccountStateDto latestCreditAccountState) { var accountCurrency = account.Currency; account.IsClosed = true; var updateCreditAccountCommand = new UpdateModelCommand <CreditAccountDto>() { ModelDto = account }; _creditAccountCommandRepository.Execute(updateCreditAccountCommand); var zeroPrice = new PriceDto() { Currency = accountCurrency, Value = 0m }; var closingCreditAccountState = new CreditAccountStateDto() { CreditAccount = account, FinesForOverdue = zeroPrice, InterestCounted = zeroPrice, MainDebtRemain = zeroPrice, RemainDebt = zeroPrice, Month = latestCreditAccountState.Month + 1, TotalInterestSumNotPaid = zeroPrice }; var newCreditAccountStateCommand = new CreateModelCommand <CreditAccountStateDto>() { ModelDto = closingCreditAccountState }; _creditAccountStateCommandRepository.Execute(newCreditAccountStateCommand); return(closingCreditAccountState); }
public void Handle(UpdateModelCommand <CustomerModel> command) { var customer = this.customerRepository.GetById(command.Id); customer.User.Email = command.Model.Email; command.Model.Map(customer); }
public virtual async Task <CommandResult> UpdateModelAsync(TModelView viewModel) { var command = new UpdateModelCommand <TModelDto> { ModelDto = Mapper.Map <TModelDto>(viewModel) }; var res = await ExecuteCommandAsync(_commandRepository, command); Mapper.Map(command.ModelDto, viewModel); return(res); }
public virtual CommandResult UpdateModel(TModelView viewModel) { var command = new UpdateModelCommand <TModelDto> { ModelDto = Mapper.Map <TModelDto>(viewModel) }; var res = ExecuteCommand(_commandRepository, command); Mapper.Map(command.ModelDto, viewModel); return(res); }
public async Task <ActionResult> Update(int id, UpdateModelCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public override async void OnNavigatingTo(INavigationParameters parameters) { await DialogService.PopAsync(); if (parameters.ContainsKey("category")) { var c = parameters.GetValue <CategoryModel>("category"); Category = c; UpdateModelCommand.Execute(null); } else if (parameters.ContainsKey("IsUpdated")) { UpdateModelCommand.Execute(null); } }
public async Task ExecuteAsync(UpdateModelCommand <TModelDto> command) { var model = await ModelsDao.FindAsync(command.ModelDto.Id); if (model == null) { throw new ArgumentException($"{typeof(TModel).Name} with given Id not found"); } UpdateDbModel(model, command.ModelDto); RestoreFkModels(model, command.ModelDto); Context.Entry(model).State = EntityState.Modified; await SaveAsync(); Mapper.Map(model, command.ModelDto); }
public void Execute(UpdateModelCommand <TModelDto> command) { // if we requested a model with certain then // context already has an attached model with this id // therefore we have to find it or we will get key conflict var model = ModelsDao.Find(command.ModelDto.Id); if (model == null) { throw new ArgumentException($"{typeof(TModel).Name} with given Id not found"); } UpdateDbModel(model, command.ModelDto); RestoreFkModels(model, command.ModelDto); Context.Entry(model).State = EntityState.Modified; Save(); Mapper.Map(model, command.ModelDto); }
private CreditAccountStateDto UpdateFinesAndGetAccountState(int creditAccountId, DateTime specifiedDate) { var query = new ModelQuery() { Id = creditAccountId }; var account = _creditAccountQueryRepository.Handle(query); var latestCreditAccountStateQuery = new ActualCreditAccountStateQuery() { Id = account.Id }; var latestCreditAccountState = _creditAccountQueryRepository.Handle(latestCreditAccountStateQuery); var creditAccountPaymentsQuery = new CreditPaymentsQuery() { CreditAccountId = account.Id }; var latestCreditAccountStateDate = account.AgreementDate.AddMonths(latestCreditAccountState.Month); var accountPayments = _creditAccountQueryRepository.Handle(creditAccountPaymentsQuery); var paymentsForLatestPeriod = accountPayments.Where(p => latestCreditAccountStateDate < p.Timestamp); var accountCurrency = account.Currency; // S var sumPaidForLatestPeriod = paymentsForLatestPeriod.Sum(p => p.PaymentSum.Value); if (latestCreditAccountState.RemainDebt.Value <= sumPaidForLatestPeriod) { return(CloseAccount(account, latestCreditAccountState)); } // Z var totalDebtRemaining = latestCreditAccountState.RemainDebt.Value; // A var debtForMonth = GetDebtForMonth(latestCreditAccountState); if (latestCreditAccountState.MainDebtRemain.Value > sumPaidForLatestPeriod) { var finesForOverdue = latestCreditAccountState.FinesForOverdue; finesForOverdue.Value += account.CreditType.FineInterest * latestCreditAccountState.MainDebtRemain.Value; var updateFinesCommand = new UpdateModelCommand <PriceDto>() { ModelDto = finesForOverdue }; _priceCommandRepository.Execute(updateFinesCommand); var totalDebt = latestCreditAccountState.RemainDebt; totalDebt.Value += finesForOverdue.Value; var updateTotalDebtCommand = new UpdateModelCommand <PriceDto>() { ModelDto = totalDebt }; _priceCommandRepository.Execute(updateTotalDebtCommand); } if (ShouldAccountUpdate(account, specifiedDate)) { var previousFinesForOverdue = latestCreditAccountState.FinesForOverdue; // B var interestForMonth = (decimal)account.CreditType.InterestRate / 12 * totalDebtRemaining; var totalInterestNotPaid = latestCreditAccountState.TotalInterestSumNotPaid.Value; var newTotalDebtRemaining = totalDebtRemaining; var newTotalInterestNotPaid = totalInterestNotPaid; var mainDebtRemain = latestCreditAccountState.MainDebtRemain.Value; if (sumPaidForLatestPeriod < debtForMonth + mainDebtRemain) { newTotalDebtRemaining -= sumPaidForLatestPeriod; newTotalDebtRemaining += debtForMonth; newTotalInterestNotPaid += interestForMonth; mainDebtRemain = debtForMonth + mainDebtRemain - sumPaidForLatestPeriod; } else if (sumPaidForLatestPeriod < debtForMonth + mainDebtRemain + totalInterestNotPaid + interestForMonth) { newTotalDebtRemaining -= debtForMonth + mainDebtRemain; newTotalInterestNotPaid += interestForMonth - (sumPaidForLatestPeriod - debtForMonth - mainDebtRemain); mainDebtRemain = 0m; } else { newTotalInterestNotPaid = 0m; newTotalDebtRemaining -= sumPaidForLatestPeriod - interestForMonth - totalInterestNotPaid; mainDebtRemain = 0m; } var newCreditAccountState = new CreditAccountStateDto() { CreditAccount = account, Month = latestCreditAccountState.Month + 1, FinesForOverdue = new PriceDto() { Currency = accountCurrency, Value = previousFinesForOverdue.Value }, InterestCounted = new PriceDto() { Currency = accountCurrency, Value = interestForMonth }, RemainDebt = new PriceDto() { Currency = accountCurrency, Value = Math.Max(newTotalDebtRemaining + previousFinesForOverdue.Value, 0m) }, TotalInterestSumNotPaid = new PriceDto() { Currency = accountCurrency, Value = newTotalInterestNotPaid }, MainDebtRemain = new PriceDto() { Currency = accountCurrency, Value = mainDebtRemain } }; return(newCreditAccountState); } return(null); }
public void Handle(UpdateModelCommand <HorseModel> command) { var horse = this.horseRepository.GetById(command.Id); horse.Name = command.Model.Name; }