public async Task <IActionResult> Add(PaymentMethodCreateInputModel paymentMethodCreateInputModel) { if (!this.ModelState.IsValid) { return(this.View(paymentMethodCreateInputModel)); } var paymentMethod = await this.paymentMethodsService.CreateAsync(paymentMethodCreateInputModel); return(this.RedirectToAction(nameof(this.Details), new { id = paymentMethod.Id })); }
public async Task TestCreateAsync_WithDuplicateData_ShouldThrowInvOpEx() { var paymentMethodDuplicateName = "GetThisPm"; var paymentMethodPIA = true; var initialEntry = new PaymentMethodCreateInputModel { Name = paymentMethodDuplicateName, PaymentInAdvance = paymentMethodPIA, }; var duplicateEntry = new PaymentMethodCreateInputModel { Name = paymentMethodDuplicateName, PaymentInAdvance = paymentMethodPIA, }; await this.paymentMethodsService.CreateAsync(initialEntry); await Assert.ThrowsAsync <InvalidOperationException>(async() => await this.paymentMethodsService.CreateAsync(duplicateEntry)); }
public async Task <PaymentMethodDetailsViewModel> CreateAsync(PaymentMethodCreateInputModel paymentMethodCreateInputModel) { var checkPaymentMethodExists = this.paymentMethodsRepository.All() .FirstOrDefault(x => x.Name == paymentMethodCreateInputModel.Name); if (checkPaymentMethodExists != null) { throw new InvalidOperationException(string.Format(ServiceConstants.PaymentMethod.PaymentMethodNameAlreadyExists, paymentMethodCreateInputModel.Name)); } var paymentMethod = new PaymentMethod { Name = paymentMethodCreateInputModel.Name, PaymentInAdvance = paymentMethodCreateInputModel.PaymentInAdvance, }; await this.paymentMethodsRepository.AddAsync(paymentMethod); await this.paymentMethodsRepository.SaveChangesAsync(); var paymentMethodDetailsViewModel = AutoMapper.Mapper.Map <PaymentMethodDetailsViewModel>(paymentMethod); return(paymentMethodDetailsViewModel); }