Ejemplo n.º 1
0
        public ActionResult Create(CustomerViewModel customerViewModel)
        {
            if (!string.IsNullOrEmpty(customerViewModel.PersonalNumber))
            {
                MrgreenCustomer mrgreenCustomer = new MrgreenCustomer {
                    FirstName      = customerViewModel.FirstName,
                    LastName       = customerViewModel.LastName,
                    Address        = customerViewModel.Address,
                    PersonalNumber = customerViewModel.PersonalNumber
                };

                return(RedirectToAction("Create", "MrgreenCustomer", mrgreenCustomer));
            }
            else if (!string.IsNullOrEmpty(customerViewModel.FavoriteFootballTeam))
            {
                RedbetCustomer redbetCustomer = new RedbetCustomer
                {
                    FirstName            = customerViewModel.FirstName,
                    LastName             = customerViewModel.LastName,
                    Address              = customerViewModel.Address,
                    FavoriteFootballTeam = customerViewModel.FavoriteFootballTeam
                };

                return(RedirectToAction("Create", "RedbetCustomer", redbetCustomer));
            }

            ModelState.AddModelError("CustomerType", "Personal Number or Favorite Football Team should be informed");

            return(View(customerViewModel));
        }
Ejemplo n.º 2
0
        public void AddCustomer(MrgreenCustomer customer)
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(_mrgreenAdapterSettings.MrgreenUrl);
                var json          = JsonConvert.SerializeObject(customer);
                var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
                var response      = httpClient.PostAsync($"api/customers/", stringContent).Result;

                if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
                {
                    throw new DomainException("Client can not be null.");
                }
            }
        }
 public IActionResult Edit(MrgreenCustomer mrgreenCustomer)
 {
     _mrgreenAdapter.UpdateCustomer(mrgreenCustomer);
     return(RedirectToAction("Index", "Customer"));
 }
 //[HttpPost]
 public IActionResult Create(MrgreenCustomer mrgreenCustomer)
 {
     _mrgreenAdapter.AddCustomer(mrgreenCustomer);
     return(RedirectToAction("Index", "Customer"));
 }