public async Task <IActionResult> RegisterCarrier(CarrierViewModel carrierViewModel)
        {
            var vm = new CarrierListViewModel(await _carrierRepository.GetCarriersAsync(null));

            if (ViewData.ModelState.IsValid)
            {
                var carrier = new Carrier();
                carrierViewModel.CopyTo(carrier);
                var userManager = serviceProvider.GetService <UserManager <ApplicationUser> >();
                var user        = await userManager.FindByNameAsync(carrier.Name);

                if (user == null)
                {
                    var carrierId = await _carrierRepository.AddAsync(carrier);

                    user = new ApplicationUser {
                        UserName = carrier.Name, CarrierId = carrierId
                    };
                    await userManager.CreateAsync(user, _securityContext.DefaultPassword);

                    return(new RedirectToActionResult(urlHelper, "Login", "Carrier", null));
                }
                else
                {
                    ViewData.ModelState.AddModelError("UserNameNotAvailable", "The User Name is not available");
                }
            }
            else
            {
                vm.LoadCarrierFrom(carrierViewModel);
            }

            ViewData.Model = vm;
            return(new ViewResult()
            {
                ViewData = ViewData, ViewName = "Index"
            });
        }
 public async Task <int> Post([FromBody] Carrier carrier)
 {
     return(await _carrierRepository.AddAsync(carrier));
 }