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

                    CreateMerchantModel createMerchantModel = this.ViewModelFactory.ConvertFrom(viewModel);

                    // All good with model, call the client to create the merchant
                    CreateMerchantResponseModel createMerchantResponse =
                        await this.ApiClient.CreateMerchant(accessToken, this.User.Identity as ClaimsIdentity, createMerchantModel, cancellationToken);

                    // TODO: Investigate some kind of spinner...
                    await Task.Delay(TimeSpan.FromSeconds(30));

                    // Merchant Created, redirect to the Merchant List screen
                    return(this.RedirectToAction("GetMerchant",
                                                 "Merchant",
                                                 new
                    {
                        merchantId = createMerchantResponse.MerchantId
                    }));
                }
                catch (Exception e)
                {
                    // Something went wrong creating the contract
                    return(this.View("CreateMerchant").WithWarning("New Merchant", Helpers.BuildUserErrorMessage("Error creating the merchant")));
                }
            }

            // If we got this far, something failed, redisplay form
            return(this.View("CreateMerchant", viewModel));
        }
Esempio n. 2
0
        public IHttpActionResult Post([FromBody] CreateMerchantModel model)
        {
            if (DB.Merchants.Any(x => x.Contact == model.Contact))
            {
                return(BadRequest("The contact of the merchant is already used!"));
            }

            var merchant = new Merchant()
            {
                Contact           = model.Contact,
                DateCreated       = DateTime.UtcNow,
                Location          = model.Location,
                LocationLat       = model.LocationLat,
                LocationLng       = model.LocationLng,
                WorkingHours      = model.WorkingHours,
                Name              = model.Name,
                SupportedNetworks = model.SupportedNetworks,
            };

            DB.Merchants.Add(merchant);
            DB.SaveChanges();

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Created, merchant)));
        }
Esempio n. 3
0
 public static ApiEndpoint <Merchant> Create(CreateMerchantModel merchant) => new ApiEndpoint <Merchant>(BaseUrl, HttpMethod.Post, merchant);