public async Task <IActionResult> CreateContract(CreateContractViewModel viewModel,
                                                         CancellationToken cancellationToken)
        {
            // Validate the model
            if (this.ValidateModel(viewModel))
            {
                try
                {
                    String accessToken = await this.HttpContext.GetTokenAsync("access_token");

                    CreateContractModel createContractModel = this.ViewModelFactory.ConvertFrom(viewModel);

                    // All good with model, call the client to create the golf club
                    CreateContractResponseModel createContractResponseModel =
                        await this.ApiClient.CreateContract(accessToken, this.User.Identity as ClaimsIdentity, createContractModel, cancellationToken);

                    // Merchant Created, redirect to the Merchant List screen
                    return(this.RedirectToAction("GetContractList", "Contract")
                           .WithSuccess("Contract Created Successful", $"Contract {viewModel.ContractDescription} successfully created"));
                }
                catch (Exception ex)
                {
                    // Something went wrong creating the contract
                    return(this.View("CreateContract").WithWarning("New Contract", Helpers.BuildUserErrorMessage("Error creating the contract")));
                }
            }

            // If we got this far, something failed, redisplay form
            return(this.View("CreateContract", viewModel));
        }
        public CreateContractModel GetDataForCreateContract(int subscriberId)
        {
            var tables = NativeSql.ExecMultiple("contracts_getDataForCreating", new { subscriberId, });
            var model  =
                new CreateContractModel()
            {
                Areas      = tables[0].Rows <AreasDictionaryDa>(),
                Subscriber = tables[1].OneRow <CreateContractSubscriberDa>(),
                Tariffs    = tables[2].Rows <CreateContractTariffDa>(),
                Options    = tables[3].Rows <CreateContractTariffOptionDa>(),
                Streets    = tables[4].Rows <StreetWrapper>().Select(sw => sw.Street).ToArray(),
            };

            return(model);
        }
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="createContractViewModel">The create contract view model.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">createContractViewModel</exception>
        public CreateContractModel ConvertFrom(CreateContractViewModel createContractViewModel)
        {
            if (createContractViewModel == null)
            {
                throw new ArgumentNullException(nameof(createContractViewModel));
            }

            CreateContractModel createContractModel = new CreateContractModel
            {
                OperatorId  = createContractViewModel.OperatorId,
                Description = createContractViewModel.ContractDescription
            };

            return(createContractModel);
        }
Пример #4
0
        public ActionResult Create(Guid id)
        {
            if (Session["XenonUserId"] == null)
            {
                return(Redirect("/"));
            }
            ViewBag.Wallet           = id;
            Session["currentWallet"] = id;
            Guid geoid             = (Guid)Session["XenonGeoId"];
            var  s                 = Utils.ToGeographicZoneModel(DataAccessAction.geographicZone.GetAllAvailableGeographicZones());
            CreateContractModel cs = new CreateContractModel
            {
                GeographicZoneModel = s,
                WalletId            = id,
                WalletName          = DataAccessAction.wallet.GetWalletById(id).Service,
                UserId = geoid
            };

            return(View(cs));
        }
Пример #5
0
        public String CreateApi(Guid id)
        {
            if (Session["XenonUserId"] == null)
            {
                return(JsonConvert.SerializeObject(new CreateContractModel()));
            }
            ViewBag.Wallet           = id;
            Session["currentWallet"] = id;
            Guid geoid             = (Guid)Session["XenonGeoId"];
            var  s                 = Utils.ToGeographicZoneModel(DataAccessAction.geographicZone.GetAllAvailableGeographicZones());
            CreateContractModel cs = new CreateContractModel
            {
                GeographicZoneModel = s,
                WalletId            = id,
                WalletName          = DataAccessAction.wallet.GetWalletById(id).Service,
                UserId = geoid
            };

            return(JsonConvert.SerializeObject(cs));
        }