/// <summary>
        /// process, get (the) area routing detail by...
        /// </summary>
        /// <param name="theLocation">the location</param>
        /// <param name="inScope">in logging scope</param>
        /// <returns>the currently running task containing the response message (success or fail)</returns>
        internal async Task <HttpResponseMessage> ProcessGetAreaRoutingDetailBy(string theLocation, IScopeLoggingContext inScope)
        {
            await inScope.EnterMethod();

            theLocation = theLocation?.Trim();

            It.IsEmpty(theLocation)
            .AsGuard <MalformedRequestException>();

            await inScope.Information($"seeking the routing details for: '{theLocation}'");

            await inScope.Information($"analysing the expression type...");

            var theExpressionType = Analyser.GetTypeOfExpressionFor(theLocation);

            await inScope.Information($"seeking the action for expression type: '{theExpressionType}'");

            var actionDo = Actions.GetActionFor(theExpressionType);

            await inScope.Information($"action for expression type: '{actionDo.Method.Name}'");

            var theTouchpoint = await actionDo(theLocation, inScope);

            await inScope.Information($"action execution complete...");

            await inScope.ExitMethod();

            return(await ProcessGetAreaRoutingDetailFor(theTouchpoint, inScope));
        }
        /// <summary>
        /// process, get (the) area routing detail for...
        /// </summary>
        /// <param name="theTouchpointID">the touchpoint id</param>
        /// <param name="inScope">in logging scope</param>
        /// <returns>the currently running task containing the response message (success only)</returns>
        internal async Task <HttpResponseMessage> ProcessGetAreaRoutingDetailFor(string theTouchpointID, IScopeLoggingContext inScope)
        {
            await inScope.EnterMethod();

            It.IsEmpty(theTouchpointID)
            .AsGuard <MalformedRequestException>();

            await inScope.Information($"seeking the routing details: '{theTouchpointID}'");

            var theDetail = await RoutingDetails.Get(theTouchpointID);

            It.IsNull(theDetail)
            .AsGuard <MalformedRequestException>(theTouchpointID);

            await inScope.Information($"candidate search complete: '{theDetail.TouchpointID}'");

            await inScope.Information($"preparing response...");

            var response = Respond.Ok().SetContent(theDetail);

            await inScope.Information($"preparation complete...");

            await inScope.ExitMethod();

            return(response);
        }
        /// <summary>
        /// get (the) touchpoint id from (the) Postcode
        /// </summary>
        /// <param name="theCandidate">the candidate</param>
        /// <param name="usingScope">using (the logging) scope</param>
        /// <returns>the LAD code</returns>
        public async Task <string> GetTouchpointIDFromPostcode(string theCandidate, IScopeLoggingContext usingScope)
        {
            await usingScope.EnterMethod();

            await usingScope.Information($"seeking postcode '{theCandidate}'");

            var result = await Postcode.LookupAsync(theCandidate);

            It.IsNull(result)
            .AsGuard <InvalidPostcodeException>(theCandidate);
            It.IsEmpty(result.Postcode)
            .AsGuard <InvalidPostcodeException>(theCandidate);

            await usingScope.Information($"found postcode for '{result.Postcode}'");

            await usingScope.Information($"seeking local authority '{result.Codes.AdminDistrict}'");

            var authority = await Authority.Get(result.Codes.AdminDistrict);

            await usingScope.Information($"found local authority '{authority.LADCode}'");

            await usingScope.ExitMethod();

            return(authority.TouchpointID);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// process, add new authority for...
        /// submission choices...
        /// {"LADCode": "E00060060", "Name": "Widdicombe Sands" }
        /// {"TouchpointID":"0000000102", "LADCode": "E00060060", "Name": "Widdicombe Sands" }
        /// </summary>
        /// <param name="theTouchpoint">the touchpoint</param>
        /// <param name="usingContent">using content</param>
        /// <param name="inScope">in scope</param>
        /// <returns>the result of the operation</returns>
        public async Task <HttpResponseMessage> ProcessAddNewAuthorityFor(
            string theTouchpoint,
            string usingContent,
            IScopeLoggingContext inScope)
        {
            await inScope.EnterMethod();

            It.IsEmpty(theTouchpoint)
            .AsGuard <ArgumentNullException>(nameof(theTouchpoint));
            It.IsEmpty(usingContent)
            .AsGuard <ArgumentNullException>(nameof(usingContent));

            await inScope.Information($"deserialising the submitted content: '{usingContent}'");

            var theCandidate = JsonConvert.DeserializeObject <IncomingLocalAuthority>(usingContent);

            It.IsNull(theCandidate)
            .AsGuard <MalformedRequestException>(nameof(ILocalAuthority.LADCode));

            await inScope.Information("deserialisation complete...");

            if (It.IsEmpty(theCandidate.TouchpointID))
            {
                await inScope.Information($"applying missing touchpoint details: '{theTouchpoint}'");

                theCandidate.TouchpointID = theTouchpoint;
            }

            await inScope.Information($"validating the candidate: '{theCandidate.LADCode}'");

            await Authority.Validate(theCandidate);

            await inScope.Information($"validation complete...");

            await inScope.Information($"adding the candidate: '{theCandidate.LADCode}'");

            var result = await Authorities.Add(theCandidate);

            await inScope.Information($"candidate addition complete...");

            await inScope.Information($"preparing response...");

            var response = Respond.Created().SetContent(result);

            await inScope.Information($"preparation complete...");

            await inScope.ExitMethod();

            return(response);
        }
        /// <summary>
        /// inform on...
        /// </summary>
        /// <param name="theException">the exception</param>
        /// <param name="useLoggingScope">using (the) logging scope</param>
        /// <returns>the currently running task</returns>
        internal async Task InformOn(Exception theException, IScopeLoggingContext useLoggingScope)
        {
            await useLoggingScope.Information(theException.Message);

            if (It.Has(theException.InnerException))
            {
                await InformOn(theException.InnerException, useLoggingScope);
            }
        }
        /// <summary>
        /// process, delete an area routing detail using...
        /// </summary>
        /// <param name="theTouchpointID">the touchpoint id</param>
        /// <param name="inScope">in logging scope</param>
        /// <returns>the currently running task containing the response message (success or fail)</returns>
        internal async Task <HttpResponseMessage> ProcessDeleteAreaRoutingDetailUsing(string theTouchpointID, IScopeLoggingContext inScope)
        {
            await inScope.EnterMethod();

            await inScope.Information($"deleting the routing details for '{theTouchpointID}'");

            await RoutingDetails.Delete(theTouchpointID);

            await inScope.Information($"preparing response...");

            var response = Respond.Ok();

            await inScope.Information($"preparation complete...");

            await inScope.ExitMethod();

            return(response);
        }
        /// <summary>
        /// this is the default unknown candidate type action
        /// </summary>
        /// <param name="theCandidate">the candidate</param>
        /// <param name="usingScope">using scope</param>
        /// <param name="forExpression">for (the) expression</param>
        /// <returns>nothing, this should throw</returns>
        public async Task <string> UnknownCandidateTypeAction(string theCandidate, IScopeLoggingContext usingScope)
        {
            await usingScope.EnterMethod();

            await usingScope.Information($"malformed request candidate: '{theCandidate}'");

            await usingScope.ExitMethod();

            throw new MalformedRequestException(theCandidate);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// process, get (the) local authority for...
        /// </summary>
        /// <param name="theTouchpoint">the touchpoint</param>
        /// <param name="theLADCode">the local adinistrative district code</param>
        /// <param name="inScope">in scope</param>
        /// <returns>the result of the operation</returns>
        public async Task <HttpResponseMessage> ProcessGetAuthorityFor(
            string theTouchpoint,
            string theLADCode,
            IScopeLoggingContext inScope)
        {
            await inScope.EnterMethod();

            It.IsEmpty(theTouchpoint)
            .AsGuard <ArgumentNullException>(nameof(theTouchpoint));
            It.IsEmpty(theLADCode)
            .AsGuard <ArgumentNullException>(nameof(theLADCode));

            await inScope.Information($"seeking the admin district: '{theLADCode}'");

            var result = await Authorities.Get(theLADCode);

            It.IsNull(result)
            .AsGuard <ArgumentNullException>(theLADCode);
            It.IsEmpty(result.LADCode)
            .AsGuard <ArgumentNullException>(theLADCode);

            await inScope.Information($"candidate search complete: '{result.LADCode}'");

            await inScope.Information($"validating touchpoint integrity: '{result.TouchpointID}' == '{theTouchpoint}'");

            (result.TouchpointID != theTouchpoint)
            .AsGuard <MalformedRequestException>(theTouchpoint);

            await inScope.Information($"preparing response...");

            var response = Respond.Ok().SetContent(result);

            await inScope.Information($"preparation complete...");

            await inScope.ExitMethod();

            return(response);
        }
        /// <summary>
        /// process, get all route id's
        /// </summary>
        /// <param name="inScope">in logging scope</param>
        /// <returns>the currently running task containing the response message (success only)</returns>
        internal async Task <HttpResponseMessage> ProcessGetAllRouteIDs(IScopeLoggingContext inScope)
        {
            await inScope.EnterMethod();

            await inScope.Information("seeking all routing ids");

            var result = await RoutingDetails.GetAllIDs();

            await inScope.Information($"found {result.Count} record(s)...");

            var theCandidate = $"{{ [{string.Join(", ", result.Select(x => $"\"{x}\""))}] }}";

            await inScope.Information($"candidate content: '{theCandidate}'");

            await inScope.Information($"preparing response...");

            var response = Respond.Ok().SetContent(theCandidate);

            await inScope.Information($"preparation complete...");

            await inScope.ExitMethod();

            return(response);
        }
        /// <summary>
        /// get (the) touchpoint id using the outward code
        /// </summary>
        /// <param name="theCandidate">the candidate</param>
        /// <param name="usingScope">using (the logging) scope</param>
        /// <returns>the LAD code</returns>
        public async Task <string> GetTouchpointIDFromOutwardCode(string theCandidate, IScopeLoggingContext usingScope)
        {
            await usingScope.EnterMethod();

            It.IsEmpty(theCandidate)
            .AsGuard <ArgumentNullException>(nameof(theCandidate));

            await usingScope.Information($"seeking postcode via outward code: '{theCandidate}'");

            var result = await Postcode.LookupOutwardCodeAsync(theCandidate);

            It.IsEmpty(result)
            .AsGuard <NoContentException>();

            await usingScope.ExitMethod();

            return(await GetTouchpointIDFromPostcode(result.FirstOrDefault(), usingScope));
        }
        /// <summary>
        /// process, add new area routing detail
        /// </summary>
        /// <param name="theTouchpoint">the touchpoint</param>
        /// <param name="usingContent">using content</param>
        /// <param name="inScope">in scope</param>
        /// <returns>the result of the operation</returns>
        public async Task <HttpResponseMessage> ProcessAddAreaRoutingDetailUsing(
            string theContent,
            IScopeLoggingContext inScope)
        {
            await inScope.EnterMethod();

            It.IsEmpty(theContent)
            .AsGuard <MalformedRequestException>();

            await inScope.Information($"deserialising the submitted content: '{theContent}'");

            var theCandidate = JsonConvert.DeserializeObject <IncomingRoutingDetail>(theContent);

            await inScope.Information("deserialisation complete...");

            It.IsNull(theCandidate)
            .AsGuard <MalformedRequestException>();

            await inScope.Information($"validating the candidate: '{theCandidate.TouchpointID}'");

            await RoutingDetail.Validate(theCandidate);

            await inScope.Information($"validation complete...");

            await inScope.Information($"adding the candidate: '{theCandidate.TouchpointID}'");

            var result = await RoutingDetails.Add(theCandidate);

            await inScope.Information($"candidate addition complete...");

            await inScope.Information($"preparing response...");

            var response = Respond.Created().SetContent(result);

            await inScope.Information($"preparation complete...");

            await inScope.ExitMethod();

            return(response);
        }