public void Setup()
        {
            certificateService = A.Fake <ICertificateService>();
            controller         =
                new ConfigurationController(
                    centresDataService,
                    mapsApiHelper,
                    logger,
                    imageResizeService,
                    certificateService
                    )
                .WithDefaultContext()
                .WithMockUser(true);

            A.CallTo(
                () => centresDataService.UpdateCentreWebsiteDetails(
                    A <int> ._,
                    A <string> ._,
                    A <double> ._,
                    A <double> ._,
                    A <string> ._,
                    A <string> ._,
                    A <string> ._,
                    A <string> ._,
                    A <string> ._,
                    A <string> ._,
                    A <string> ._
                    )
                ).DoesNothing();
        }
Esempio n. 2
0
        public IActionResult EditCentreWebsiteDetails(EditCentreWebsiteDetailsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            model.CentrePostcode = model.CentrePostcode !.Trim();
            var mapsResponse = mapsApiHelper.GeocodePostcode(model.CentrePostcode).Result;

            if (mapsResponse.HasNoResults())
            {
                ModelState.AddModelError(nameof(model.CentrePostcode), "Enter a UK postcode");
                return(View(model));
            }

            if (mapsResponse.ApiErrorOccurred())
            {
                logger.LogWarning
                (
                    $"Failed Maps API call when trying to get postcode {model.CentrePostcode} " +
                    $"- status of {mapsResponse.Status} - error message: {mapsResponse.ErrorMessage}"
                );
                return(new StatusCodeResult(500));
            }

            var latitude  = double.Parse(mapsResponse.Results[0].Geometry.Location.Latitude);
            var longitude = double.Parse(mapsResponse.Results[0].Geometry.Location.Longitude);

            var centreId = User.GetCentreId();

            centresDataService.UpdateCentreWebsiteDetails(
                centreId,
                model.CentrePostcode,
                latitude,
                longitude,
                model.CentreTelephone,
                model.CentreEmail !,
                model.OpeningHours,
                model.CentreWebAddress,
                model.OrganisationsCovered,
                model.TrainingVenues,
                model.OtherInformation
                );

            return(RedirectToAction("Index"));
        }