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

                    CreateOperatorModel createOperatorModel = this.ViewModelFactory.ConvertFrom(viewModel);

                    // All good with model, call the client to create the operator
                    CreateOperatorResponseModel createOperatorResponse =
                        await this.ApiClient.CreateOperator(accessToken, this.User.Identity as ClaimsIdentity, createOperatorModel, cancellationToken);

                    // Operator Created, redirect to the Operator List screen
                    return(this.RedirectToAction("GetOperatorList",
                                                 "Operator",
                                                 new
                    {
                        Area = "Estate"
                    }).WithSuccess("Operator Created", $"Operator {createOperatorModel.OperatorName} created successfully"));
                }
                catch (Exception e)
                {
                    return(this.RedirectToAction("CreateOperator", "Operator")
                           .WithWarning("Operator Not Created", Helpers.BuildUserErrorMessage("Operator not created successfully")));
                }
            }

            // If we got this far, something failed, redisplay form
            return(this.View("CreateOperator", viewModel));
        }
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="createOperatorViewModel">The create operator view model.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">createOperatorViewModel</exception>
        public CreateOperatorModel ConvertFrom(CreateOperatorViewModel createOperatorViewModel)
        {
            if (createOperatorViewModel == null)
            {
                throw new ArgumentNullException(nameof(createOperatorViewModel));
            }

            CreateOperatorModel createOperatorModel = new CreateOperatorModel
            {
                RequireCustomMerchantNumber = createOperatorViewModel.RequireCustomMerchantNumber,
                RequireCustomTerminalNumber = createOperatorViewModel.RequireCustomTerminalNumber,
                OperatorName = createOperatorViewModel.OperatorName
            };

            return(createOperatorModel);
        }
Beispiel #3
0
        private async Task <UserDTO> CreateUser(CreateOperatorModel model)
        {
            var user = await userService.GetByNameAsync(model.UNP);

            if (user != null)
            {
                await userService.Delete(user);
            }

            var result = (await operatorController.Create(model)) as RedirectToRouteResult;

            if (result == null)
            {
                return(null);
            }

            user = await userService.GetByNameAsync(model.UNP);

            return(user);
        }
        public async Task <ActionResult> Create(CreateOperatorModel model)
        {
            if (ModelState.IsValid)
            {
                var user        = _mapper.Map <CreateOperatorModel, UserDTO>(model);
                var userProfile = _mapper.Map <CreateOperatorModel, ProfileUserDTO>(model);
                user.ProfileUser = userProfile;

                var result = await _userService.Create(user);

                if (result.Succedeed)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", result.Message);
                }
            }
            return(View(model));
        }