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 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("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" };
        }
Esempio n. 2
0
 public async Task<IActionResult> Index(SearchViewModel searchVM)
 {
     string searchString = searchVM == null ? null : searchVM.SearchString;
     var carriers = await _carrierRepository.GetCarriersAsync(searchString);
     var model = new CarrierListViewModel(carriers);
     return View("Index", model);
 }
        public async Task<IActionResult> Index(SearchViewModel searchVM)
        {
            string searchString = searchVM == null ? null : searchVM.SearchString;
            var carriers = await _carrierRepository.GetCarriersAsync(searchString);
            var model = new CarrierListViewModel(carriers);

            return View("Index", model);
        }
Esempio n. 4
0
        public async Task <ActionResult> List(Guid id, bool?backToOverview = null)
        {
            ViewBag.BackToOverview = backToOverview.GetValueOrDefault();
            var model = new CarrierListViewModel();

            var response =
                await mediator.SendAsync(new GetCarriersByNotificationId(id));

            model.NotificationId = id;
            model.Carriers       = new List <CarrierData>(response);

            return(View(model));
        }
Esempio n. 5
0
        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<ActionResult> List(Guid id, bool? backToOverview = null)
        {
            ViewBag.BackToOverview = backToOverview.GetValueOrDefault();
            var model = new CarrierListViewModel();

            var response =
                await mediator.SendAsync(new GetCarriersByNotificationId(id));

            model.NotificationId = id;
            model.Carriers = new List<CarrierData>(response);

            return View(model);
        }