コード例 #1
0
        public async Task <ActionResult> Register(RegisteredUserInsertVM registeredUserInsertVM)
        {
            countryApi = new CountryApiClient();

            if (ModelState.IsValid)
            {
                registeredUserApi = new RegisteredUserApiClient();

                string  code    = registeredUserInsertVM.SelectedCountry.Substring(0, 2);
                Country country = await countryApi.GetCountry(code);

                registeredUserInsertVM.Country = country;

                RegisteredUser registeredUser = await registeredUserApi.RegisterUser(registeredUserInsertVM);

                if (registeredUser != null)
                {
                    Session["RegisteredUser"] = registeredUser;

                    return(RedirectToAction("Index", "Home"));
                }
            }

            List <Country> countries = await countryApi.GetCountries();

            SelectList selectListItemCountries = new SelectList(countries);

            registeredUserInsertVM.Countries = selectListItemCountries;

            return(View(registeredUserInsertVM));
        }
コード例 #2
0
        public async Task <ActionResult> EditProfile(int id)
        {
            countryApi = new CountryApiClient();

            List <Country> countries = await countryApi.GetCountries();

            SelectList selectListItemCountries = new SelectList(countries);

            registeredUserApi = new RegisteredUserApiClient();

            RegisteredUser registeredUser = await registeredUserApi.GetRegisteredUser(id);

            RegisteredUserEditVM registeredUserEditVM = new RegisteredUserEditVM()
            {
                Username  = registeredUser.Username,
                Email     = registeredUser.Email,
                FirstName = registeredUser.FirstName,
                LastName  = registeredUser.LastName,
                Address   = registeredUser.Location.Address,
                City      = registeredUser.Location.City.Name,
                Countries = selectListItemCountries
            };

            return(View(registeredUserEditVM));
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: mucnjakf/SisanjeHR
        public async Task <ActionResult> Search()
        {
            if (Session["RegisteredUser"] == null)
            {
                countryApi = new CountryApiClient();

                List <Country> countries = await countryApi.GetCountries();

                SelectList selectListItemCountries = new SelectList(countries);

                HairSalonSearchVM hairSalonSearchVM = new HairSalonSearchVM()
                {
                    Countries = selectListItemCountries
                };

                return(View(hairSalonSearchVM));
            }

            RegisteredUser registeredUser = (RegisteredUser)Session["RegisteredUser"];

            return(await Search(new HairSalonSearchVM()
            {
                Address = registeredUser.Location.Address,
                City = registeredUser.Location.City.Name,
                SelectedCountry = registeredUser.Location.City.Country.Name
            }));
        }
コード例 #4
0
        public AddNewRegisteredUser()
        {
            InitializeComponent();

            ls = new LoadingScreen();

            countryApi        = new CountryApiClient();
            registeredUserApi = new RegisteredUserApiClient();
        }
コード例 #5
0
        public AddNewHairSalon(Owner owner)
        {
            InitializeComponent();

            ls = new LoadingScreen();

            countryApi   = new CountryApiClient();
            hairSalonApi = new HairSalonApiClient();

            this.owner = owner;
        }
コード例 #6
0
        public EditRegisteredUser(RegisteredUser registeredUser)
        {
            InitializeComponent();

            ls = new LoadingScreen();

            countryApi        = new CountryApiClient();
            registeredUserApi = new RegisteredUserApiClient();

            this.registeredUser = registeredUser;

            SetRegisteredUserValues();
        }
コード例 #7
0
        public EditHairSalon(HairSalon hairSalon)
        {
            InitializeComponent();

            ls = new LoadingScreen();

            countryApi   = new CountryApiClient();
            hairSalonApi = new HairSalonApiClient();

            this.hairSalon = hairSalon;

            SetHairSalonValues();
        }
コード例 #8
0
        public async Task <ActionResult> Register()
        {
            countryApi = new CountryApiClient();

            List <Country> countries = await countryApi.GetCountries();

            SelectList selectListItemCountries = new SelectList(countries);

            RegisteredUserInsertVM registeredUserInsertVM = new RegisteredUserInsertVM()
            {
                Countries = selectListItemCountries
            };

            return(View(registeredUserInsertVM));
        }
コード例 #9
0
        public async Task GetCountriesAsync_ThrowsExceptionWithUnsuccessfulGet()
        {
            _appSettings.SetupGet(a => a.CurrentValue)
            .Returns(new AppSettingsOptions {
                CountryApiUrl = "http://mytest.com/?id={0}"
            });
            var testHandler =
                new TestHttpClientMessageHandler(HttpStatusCode.InternalServerError, "something happened");

            using (var httpClient = new HttpClient(testHandler))
            {
                var client = new CountryApiClient(httpClient, _appSettings.Object);
                await client.GetCountriesAsync("Wales");
            }
        }
コード例 #10
0
        public async Task GetCountriesAsync_ReturnsDeserializedData()
        {
            _appSettings.SetupGet(a => a.CurrentValue)
            .Returns(new AppSettingsOptions {
                CountryApiUrl = "http://mytest.com/?id={0}"
            });
            var testHandler =
                new TestHttpClientMessageHandler(HttpStatusCode.OK, TestResponses.ValidCountryResponse);

            using (var httpClient = new HttpClient(testHandler))
            {
                var client = new CountryApiClient(httpClient, _appSettings.Object);
                var result = await client.GetCountriesAsync("United Kingdom");

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual("GBR", result.First().Alpha3Code);

                //TODO: Perhaps not ideal to test output and behaviour in the same
                //test but it saves a lot of code!
                _appSettings.VerifyGet(a => a.CurrentValue, Times.Once);
            }
        }
コード例 #11
0
ファイル: HomeController.cs プロジェクト: mucnjakf/SisanjeHR
        public async Task <ActionResult> Search(HairSalonSearchVM hairSalonSearchVM)
        {
            if (ModelState.IsValid)
            {
                Session["SearchQuery"] = $"{hairSalonSearchVM.Address}, {hairSalonSearchVM.City}, {hairSalonSearchVM.SelectedCountry.Substring(5)} - {hairSalonSearchVM.Distance} km";

                hairSalonApi = new HairSalonApiClient();

                List <HairSalon> hairSalonsNearMe = await hairSalonApi.GetHairSalonsNearMe(hairSalonSearchVM);

                return(View("HairSalons", hairSalonsNearMe));
            }

            countryApi = new CountryApiClient();

            List <Country> countries = await countryApi.GetCountries();

            SelectList selectListItemCountries = new SelectList(countries);

            hairSalonSearchVM.Countries = selectListItemCountries;

            return(View(hairSalonSearchVM));
        }
コード例 #12
0
 public async Task GetCountriesAsync_ThrowsExceptionWithEmptyCountry()
 {
     var client = new CountryApiClient(new HttpClient(), _appSettings.Object);
     await client.GetCountriesAsync(String.Empty);
 }
コード例 #13
0
 public void Ctor_ThrowsExceptionWithNullAppSettings()
 {
     _ = new CountryApiClient(new HttpClient(), null);
 }
コード例 #14
0
 public void Ctor_ThrowsExceptionWithNullClient()
 {
     _ = new CountryApiClient(null, _appSettings.Object);
 }