Ejemplo n.º 1
0
        private MicrosoftDynamicsCRMadoxioSpecialeventlocation ExtractLocation(Sol sol)
        {
            if (sol?.Location == null)
            {
                return(null);
            }
            MicrosoftDynamicsCRMadoxioSpecialeventlocation location =
                new MicrosoftDynamicsCRMadoxioSpecialeventlocation()
            {
                AdoxioLocationdescription   = sol.Location.LocationDescription,
                AdoxioLocationname          = sol.Location.LocationName,
                AdoxioMaximumnumberofguests = sol.Location.MaximumGuests.ToString(),
                AdoxioPermitnumber          = sol.SolLicenceNumber
            };

            // licensed area

            if (sol.Location?.LicencedArea != null)
            {
                location.AdoxioSpecialeventlocationLicencedareas =
                    new List <MicrosoftDynamicsCRMadoxioSpecialeventlicencedarea>();

                location.AdoxioSpecialeventlocationLicencedareas.Add(new MicrosoftDynamicsCRMadoxioSpecialeventlicencedarea()
                {
                    AdoxioLicencedareadescription = sol.Location.LicencedArea.Description,
                    AdoxioMinorpresent            = sol.Location.LicencedArea.MinorsPresent,
                    // Setting - Indoor, Outdoor or Both
                    AdoxioSetting = (int?)sol.Location.LicencedArea.Setting,
                    AdoxioMaximumnumberofguests = sol.Location.LicencedArea.MaxGuests.ToString(),
                    AdoxioNumberofminors        = sol.Location?.LicencedArea?.NumberOfMinors.ToString()
                });
            }

            if (sol.Location?.EventDates != null)
            {
                location.AdoxioSpecialeventlocationSchedule = new List <MicrosoftDynamicsCRMadoxioSpecialeventschedule>();
                foreach (var item in sol.Location.EventDates)
                {
                    location.AdoxioSpecialeventlocationSchedule.Add(new MicrosoftDynamicsCRMadoxioSpecialeventschedule()
                    {
                        AdoxioServicestart = AdjustDateTime(item.LiquorServiceStartTime),
                        AdoxioServiceend   = AdjustDateTime(item.LiquorServiceEndTime),
                        AdoxioEventstart   = AdjustDateTime(item.EventStartDateTime),
                        AdoxioEventend     = AdjustDateTime(item.EventEndDateTime)
                    });
                }
            }

            if (sol.Location?.Address != null)
            {
                location.AdoxioEventlocationstreet1    = sol.Location.Address.Address1;
                location.AdoxioEventlocationstreet2    = sol.Location.Address.Address2;
                location.AdoxioEventlocationcity       = sol.Location.Address.City;
                location.AdoxioEventlocationprovince   = sol.Location.Address.Province;
                location.AdoxioEventlocationpostalcode = sol.Location.Address.PostalCode;
            }

            return(location);
        }
Ejemplo n.º 2
0
 public static void CopyValues(this MicrosoftDynamicsCRMadoxioSpecialeventlocation to, ViewModels.SepEventLocation from)
 {
     if (from == null)
     {
         return;
     }
     to.AdoxioEventlocationcity             = from.EventLocationCity;
     to.AdoxioEventlocationpostalcode       = from.EventLocationPostalCode.ToUpper();
     to.AdoxioEventlocationstreet1          = from.EventLocationStreet1;
     to.AdoxioEventlocationstreet2          = from.EventLocationStreet2;
     to.AdoxioLocationdescription           = from.LocationDescription;
     to.AdoxioMaximumnumberofguestslocation = from.MaximumNumberOfGuests;
     to.AdoxioNumberofminors = from.NumberOfMinors;
     to.AdoxioLocationname   = from.LocationName;
     to.AdoxioPermitnumber   = from.PermitNumber;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Convert a given voteQuestion to a ViewModel
        /// </summary>
        public static ViewModels.SepEventLocation ToViewModel(this MicrosoftDynamicsCRMadoxioSpecialeventlocation location)
        {
            ViewModels.SepEventLocation result = null;
            if (location == null)
            {
                return(result);
            }

            result = new ViewModels.SepEventLocation
            {
                Id                      = location.AdoxioSpecialeventlocationid,
                SpecialEventId          = location._adoxioSpecialeventidValue,
                LocationDescription     = location.AdoxioLocationdescription,
                EventLocationCity       = location.AdoxioEventlocationcity,
                EventLocationPostalCode = location.AdoxioEventlocationpostalcode,
                EventLocationStreet1    = location.AdoxioEventlocationstreet1,
                EventLocationStreet2    = location.AdoxioEventlocationstreet2,
                EventLocationProvince   = location.AdoxioEventlocationprovince,
                MaximumNumberOfGuests   = location.AdoxioMaximumnumberofguestslocation,
                LocationName            = location.AdoxioLocationname,
                PermitNumber            = location.AdoxioPermitnumber,
                NumberOfMinors          = location.AdoxioNumberofminors
            };

            if (location.AdoxioSpecialeventlocationLicencedareas != null)
            {
                result.ServiceAreas = location.AdoxioSpecialeventlocationLicencedareas
                                      .Select(area => area.ToViewModel())
                                      .ToList();
            }

            if (location.AdoxioSpecialeventlocationSchedule != null)
            {
                result.EventDates = location.AdoxioSpecialeventlocationSchedule
                                    .Select(sched => sched.ToViewModel())
                                    .ToList();
            }
            return(result);
        }
Ejemplo n.º 4
0
        //
        /// <summary>
        ///check to see if the location has already been submitted.
        /// </summary>
        /// <param name="specialEventId"></param>
        /// <param name="AdoxioPermitnumber"></param>
        /// <returns>true if the location has been submitted</returns>
        private bool CheckForExistingLocation(string specialEventId, string permitNumber)
        {
            bool   result = false;
            string permitNumberEscaped = permitNumber.Replace("'", "''");
            string filter = $"adoxio_permitnumber eq '{permitNumberEscaped}' and _adoxio_specialeventid_value eq {specialEventId}";

            // fetch from Dynamics.

            try
            {
                MicrosoftDynamicsCRMadoxioSpecialeventlocation record = _dynamicsClient.Specialeventlocations.Get(filter: filter).Value.FirstOrDefault();
                if (record != null)
                {
                    result = true;
                }
            }
            catch (HttpOperationException)
            {
                result = false;
            }


            return(result);
        }
        /// <summary>
        /// Update entity in adoxio_specialeventlocations
        /// </summary>
        /// <param name='adoxioSpecialeventlocationid'>
        /// key: adoxio_specialeventlocationid of adoxio_specialeventlocation
        /// </param>
        /// <param name='body'>
        /// New property values
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <exception cref="HttpOperationException">
        /// Thrown when the operation returned an invalid status code
        /// </exception>
        /// <exception cref="ValidationException">
        /// Thrown when a required parameter is null
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when a required parameter is null
        /// </exception>
        /// <return>
        /// A response object containing the response body and response headers.
        /// </return>
        public async Task <HttpOperationResponse> UpdateWithHttpMessagesAsync(string adoxioSpecialeventlocationid, MicrosoftDynamicsCRMadoxioSpecialeventlocation body, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (adoxioSpecialeventlocationid == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "adoxioSpecialeventlocationid");
            }
            if (body == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "body");
            }
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("adoxioSpecialeventlocationid", adoxioSpecialeventlocationid);
                tracingParameters.Add("body", body);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
            }
            // Construct URL
            var _baseUrl = Client.BaseUri.AbsoluteUri;
            var _url     = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "adoxio_specialeventlocations({adoxio_specialeventlocationid})").ToString();

            _url = _url.Replace("{adoxio_specialeventlocationid}", System.Uri.EscapeDataString(adoxioSpecialeventlocationid));
            // Create HTTP transport objects
            var _httpRequest = new HttpRequestMessage();
            HttpResponseMessage _httpResponse = null;

            _httpRequest.Method     = new HttpMethod("PATCH");
            _httpRequest.RequestUri = new System.Uri(_url);
            // Set Headers


            if (customHeaders != null)
            {
                foreach (var _header in customHeaders)
                {
                    if (_httpRequest.Headers.Contains(_header.Key))
                    {
                        _httpRequest.Headers.Remove(_header.Key);
                    }
                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
                }
            }

            // Serialize Request
            string _requestContent = null;

            if (body != null)
            {
                _requestContent      = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings);
                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
                _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
            }
            // Set Credentials
            if (Client.Credentials != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
            }
            // Send Request
            if (_shouldTrace)
            {
                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

            if (_shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
            }
            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string _responseContent = null;

            if ((int)_statusCode != 204)
            {
                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                if (_httpResponse.Content != null)
                {
                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                }
                else
                {
                    _responseContent = string.Empty;
                }
                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new HttpOperationResponse();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }
        public ActionResult CreateOrUpdate([FromBody] Sol sol)
        {
            if (sol == null || string.IsNullOrEmpty(sol.SolLicenceNumber) || !sol.SolLicenceNumber.Contains("-"))
            {
                return(BadRequest());
            }

            // format of the "SolLicenceNumber" field is {EventLicenceNumber}-{LocationReference}

            string solIdEscaped = sol.SolLicenceNumber.Replace("'", "''");

            if (solIdEscaped.Contains("-"))
            {
                solIdEscaped = solIdEscaped.Substring(0, solIdEscaped.IndexOf("-"));
            }


            // string locationReference = sol.SolLicenceNumber.Substring(sepLicenceNumber.Length);

            // determine if the record is new.
            MicrosoftDynamicsCRMadoxioSpecialevent existingRecord =
                _dynamicsClient.GetSpecialEventByLicenceNumber(solIdEscaped);

            if (existingRecord == null) // new record
            {
                MicrosoftDynamicsCRMadoxioSpecialevent newRecord = new MicrosoftDynamicsCRMadoxioSpecialevent()
                {
                    AdoxioCapacity = sol.Capacity,
                    AdoxioSpecialeventdescripton = sol.EventDescription,
                    AdoxioEventname = AdjustString255(sol.EventName),
                    AdoxioSpecialeventpermitnumber = solIdEscaped,
                    // applicant
                    AdoxioSpecialeventapplicant      = AdjustString255(sol.Applicant?.ApplicantName),
                    AdoxioSpecialeventapplicantemail = AdjustString255(sol.Applicant?.EmailAddress),
                    AdoxioSpecialeventapplicantphone = sol.Applicant?.PhoneNumber,
                    // location
                    AdoxioSpecialeventstreet1    = AdjustString255(sol.Applicant?.Address?.Address1),
                    AdoxioSpecialeventstreet2    = AdjustString255(sol.Applicant?.Address?.Address2),
                    AdoxioSpecialeventcity       = AdjustString255(sol.Applicant?.Address?.City),
                    AdoxioSpecialeventpostalcode = sol.Applicant?.Address?.PostalCode,
                    AdoxioSpecialeventprovince   = AdjustString255(sol.Applicant?.Address?.Province),
                    // responsible individual
                    AdoxioResponsibleindividualfirstname     = AdjustString255(sol.ResponsibleIndividual?.FirstName),
                    AdoxioResponsibleindividuallastname      = AdjustString255(sol.ResponsibleIndividual?.LastName),
                    AdoxioResponsibleindividualmiddleinitial = AdjustString255(sol.ResponsibleIndividual?.MiddleInitial),
                    AdoxioResponsibleindividualposition      = AdjustString255(sol.ResponsibleIndividual?.Position),
                    AdoxioResponsibleindividualsir           = sol.ResponsibleIndividual?.SirNumber,
                    // tasting event
                    AdoxioTastingevent = sol.TastingEvent
                };

                newRecord.AdoxioSpecialeventSpecialeventlocations = new List <MicrosoftDynamicsCRMadoxioSpecialeventlocation>();

                newRecord.AdoxioSpecialeventSpecialeventlocations.Add(ExtractLocation(sol));


                // notes
                if (sol.SolNote != null)
                {
                    newRecord.AdoxioSpecialeventSpecialeventnotes =
                        new List <MicrosoftDynamicsCRMadoxioSpecialeventnote>();

                    foreach (var item in sol.SolNote)
                    {
                        newRecord.AdoxioSpecialeventSpecialeventnotes.Add(
                            new MicrosoftDynamicsCRMadoxioSpecialeventnote()
                        {
                            AdoxioNote   = item.Text,
                            AdoxioAuthor = AdjustString255(item.Author),
                            Createdon    = AdjustDateTime(item.CreatedDate),
                            Modifiedon   = AdjustDateTime(item.LastUpdatedDate)
                        });
                    }
                }

                // terms and conditions
                if (sol.TsAndCs != null)
                {
                    newRecord.AdoxioSpecialeventSpecialeventtsacs =
                        new List <MicrosoftDynamicsCRMadoxioSpecialeventtandc>();
                    foreach (var item in sol.TsAndCs)
                    {
                        var newTandC = new MicrosoftDynamicsCRMadoxioSpecialeventtandc()
                        {
                            AdoxioTermsandcondition = item.Text,
                            AdoxioOriginator        = AdjustString255(item.Originator)
                        };

                        if (item.TandcType == TandcType.GlobalCondition)
                        {
                            newTandC.AdoxioTermsandconditiontype = true;
                        }

                        newRecord.AdoxioSpecialeventSpecialeventtsacs.Add(newTandC);
                    }
                }

                try
                {
                    newRecord = _dynamicsClient.Specialevents.Create(newRecord);
                    _logger.Information($"Created special event {newRecord.AdoxioSpecialeventid}");
                }
                catch (HttpOperationException httpOperationException)
                {
                    _logger.Error(httpOperationException, "Error creating special event record");
                    // fail
                    return(StatusCode(500, "Server Error creating record."));
                }
            }
            else // existing record.
            {
                if (sol.Location != null)
                {
                    MicrosoftDynamicsCRMadoxioSpecialeventlocation location = ExtractLocation(sol);

                    try
                    {
                        location = _dynamicsClient.Specialeventlocations.Create(location);
                        _logger.Information(
                            $"Created new special event location {location.AdoxioSpecialeventlocationid}");
                    }
                    catch (HttpOperationException httpOperationException)
                    {
                        _logger.Error(httpOperationException, "Error creating special event schedule");
                        // fail
                        return(StatusCode(500, "Server Error creating record."));
                    }

                    // now bind the record to the parent.

                    var specialEventLocationData = _dynamicsClient.GetEntityURI("adoxio_specialeventlocations",
                                                                                location.AdoxioSpecialeventlocationid);

                    var oDataIdEventLocation = new Odataid
                    {
                        OdataidProperty = specialEventLocationData
                    };
                    try
                    {
                        _dynamicsClient.Specialevents.AddReference(existingRecord.AdoxioSpecialeventid,
                                                                   "adoxio_specialevent_specialeventlocations", oDataIdEventLocation);
                    }
                    catch (HttpOperationException odee)
                    {
                        Log.Error(odee, "Error adding reference to adoxio_specialevent_specialeventlocations");
                    }
                }
            }


            return(Ok());
        }
 /// <summary>
 /// Update entity in adoxio_specialeventlocations
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='adoxioSpecialeventlocationid'>
 /// key: adoxio_specialeventlocationid of adoxio_specialeventlocation
 /// </param>
 /// <param name='body'>
 /// New property values
 /// </param>
 /// <param name='customHeaders'>
 /// Headers that will be added to request.
 /// </param>
 public static HttpOperationResponse UpdateWithHttpMessages(this ISpecialeventlocations operations, string adoxioSpecialeventlocationid, MicrosoftDynamicsCRMadoxioSpecialeventlocation body, Dictionary <string, List <string> > customHeaders = null)
 {
     return(operations.UpdateWithHttpMessagesAsync(adoxioSpecialeventlocationid, body, customHeaders, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Update entity in adoxio_specialeventlocations
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='adoxioSpecialeventlocationid'>
 /// key: adoxio_specialeventlocationid of adoxio_specialeventlocation
 /// </param>
 /// <param name='body'>
 /// New property values
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task UpdateAsync(this ISpecialeventlocations operations, string adoxioSpecialeventlocationid, MicrosoftDynamicsCRMadoxioSpecialeventlocation body, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.UpdateWithHttpMessagesAsync(adoxioSpecialeventlocationid, body, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
 /// <summary>
 /// Update entity in adoxio_specialeventlocations
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='adoxioSpecialeventlocationid'>
 /// key: adoxio_specialeventlocationid of adoxio_specialeventlocation
 /// </param>
 /// <param name='body'>
 /// New property values
 /// </param>
 public static void Update(this ISpecialeventlocations operations, string adoxioSpecialeventlocationid, MicrosoftDynamicsCRMadoxioSpecialeventlocation body)
 {
     operations.UpdateAsync(adoxioSpecialeventlocationid, body).GetAwaiter().GetResult();
 }
 /// <summary>
 /// Add new entity to adoxio_specialeventlocations
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='body'>
 /// New entity
 /// </param>
 /// <param name='prefer'>
 /// Required in order for the service to return a JSON representation of the
 /// object.
 /// </param>
 /// <param name='customHeaders'>
 /// Headers that will be added to request.
 /// </param>
 public static HttpOperationResponse <MicrosoftDynamicsCRMadoxioSpecialeventlocation> CreateWithHttpMessages(this ISpecialeventlocations operations, MicrosoftDynamicsCRMadoxioSpecialeventlocation body, string prefer = "return=representation", Dictionary <string, List <string> > customHeaders = null)
 {
     return(operations.CreateWithHttpMessagesAsync(body, prefer, customHeaders, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Add new entity to adoxio_specialeventlocations
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='body'>
 /// New entity
 /// </param>
 /// <param name='prefer'>
 /// Required in order for the service to return a JSON representation of the
 /// object.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <MicrosoftDynamicsCRMadoxioSpecialeventlocation> CreateAsync(this ISpecialeventlocations operations, MicrosoftDynamicsCRMadoxioSpecialeventlocation body, string prefer = "return=representation", CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateWithHttpMessagesAsync(body, prefer, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Add new entity to adoxio_specialeventlocations
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='body'>
 /// New entity
 /// </param>
 /// <param name='prefer'>
 /// Required in order for the service to return a JSON representation of the
 /// object.
 /// </param>
 public static MicrosoftDynamicsCRMadoxioSpecialeventlocation Create(this ISpecialeventlocations operations, MicrosoftDynamicsCRMadoxioSpecialeventlocation body, string prefer = "return=representation")
 {
     return(operations.CreateAsync(body, prefer).GetAwaiter().GetResult());
 }