public async Task <IActionResult> CreateContractProduct([FromQuery] Guid contractId, CancellationToken cancellationToken) { CreateContractProductViewModel viewModel = new CreateContractProductViewModel(); viewModel.ContractId = contractId; return(this.View("CreateContractProduct", viewModel)); }
/// <summary> /// Converts from. /// </summary> /// <param name="createContractProductViewModel">The create contract product view model.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">createContractProductViewModel</exception> public AddProductToContractModel ConvertFrom(CreateContractProductViewModel createContractProductViewModel) { if (createContractProductViewModel == null) { throw new ArgumentNullException(nameof(createContractProductViewModel)); } AddProductToContractModel addProductToContractModel = new AddProductToContractModel(); addProductToContractModel.Value = createContractProductViewModel.Value; addProductToContractModel.DisplayText = createContractProductViewModel.DisplayText; addProductToContractModel.ProductName = createContractProductViewModel.ProductName; return(addProductToContractModel); }
public async Task <IActionResult> CreateContractProduct(CreateContractProductViewModel viewModel, CancellationToken cancellationToken) { // Validate the model if (this.ValidateModel(viewModel)) { try { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); AddProductToContractModel addProductToContractModel = this.ViewModelFactory.ConvertFrom(viewModel); // All good with model, call the client AddProductToContractResponseModel addProductToContractResponse = await this.ApiClient.AddProductToContract(accessToken, this.User.Identity as ClaimsIdentity, viewModel.ContractId, addProductToContractModel, cancellationToken); // Product Created, redirect to the Product List screen return(this.RedirectToAction("GetContractProductsList", "Contract", new { contractId = addProductToContractResponse.ContractId }).WithSuccess("Product Created Successful", $"Contract Product {viewModel.ProductName} successfully created")); } catch (Exception ex) { // Something went wrong creating the Product return(this.View("CreateContractProduct").WithWarning("New Contract Product", Helpers.BuildUserErrorMessage("Error creating the contract product"))); } } // If we got this far, something failed, redisplay form return(this.View("CreateContractProduct", viewModel)); }
/// <summary> /// Validates the model. /// </summary> /// <param name="viewModel">The view model.</param> /// <returns></returns> private Boolean ValidateModel(CreateContractProductViewModel viewModel) { return(this.ModelState.IsValid); }