public static string GetDocumentFolderName(this MicrosoftDynamicsCRMadoxioSpecialevent specialEvent) { string idCleaned = CleanGuidForSharePoint(specialEvent.AdoxioSpecialeventid); string folderName = $"{specialEvent.AdoxioEventname}_{idCleaned}"; return(folderName); }
public static ViewModels.SpecialEventSummary ToSummaryViewModel(this MicrosoftDynamicsCRMadoxioSpecialevent specialEvent) { ViewModels.SpecialEventSummary result = null; if (specialEvent != null) { result = new ViewModels.SpecialEventSummary() { SpecialEventId = specialEvent.AdoxioSpecialeventid, EventStartDate = specialEvent.AdoxioEventstartdate, EventName = specialEvent.AdoxioEventname, InvoiceId = specialEvent._adoxioInvoiceValue, IsInvoicePaid = specialEvent.AdoxioIsinvoicepaid, MaximumNumberOfGuests = specialEvent.AdoxioMaxnumofguests, DateSubmitted = specialEvent.AdoxioDatesubmitted, PoliceAccount = specialEvent.AdoxioPoliceAccountId.ToViewModel(), PoliceDecisionBy = specialEvent.AdoxioPoliceRepresentativeId.ToViewModel(), PoliceApproval = (ApproverStatus?)specialEvent.AdoxioPoliceapproval, //LcrbApprovalBy = specialEvent.AdoxioLCRBRepresentativeId.ToViewModel(), LcrbApproval = (ApproverStatus?)specialEvent.AdoxioLcrbapproval, DenialReason = specialEvent.AdoxioDenialreason, CancelReason = specialEvent.AdoxioCancellationreason, DateOfPoliceDecision = specialEvent.AdoxioDatepoliceapproved }; if (specialEvent.AdoxioTypeofevent != null) { result.EventType = (EventType)specialEvent.AdoxioTypeofevent; } if (specialEvent.Statuscode != null) { result.EventStatus = (EventStatus)specialEvent.Statuscode; } if (specialEvent.AdoxioSpecialeventSpecialeventtsacs != null) { result.TermsAndConditions = new List <SepTermAndCondition>(); specialEvent.AdoxioSpecialeventSpecialeventtsacs.ToList() .ForEach(term => { result.TermsAndConditions.Add(new SepTermAndCondition { Id = term.AdoxioSpecialeventtandcid, Content = term.AdoxioTermsandcondition, Originator = term.AdoxioOriginator }); }); } } return(result); }
public static void CopyValues(this MicrosoftDynamicsCRMadoxioSpecialevent to, ViewModels.SpecialEvent from) { to.AdoxioSpecialeventid = from.Id; to.AdoxioAdmissionfee = from.AdmissionFee; to.AdoxioBeergarden = from.BeerGarden; to.AdoxioCapacity = from.Capacity; to.AdoxioIsagreetsandcs = from.IsAgreeTsAndCs; to.AdoxioIsprivateresidence = from.IsPrivateResidence; to.AdoxioDateagreedtotsandcs = from.DateAgreedToTsAndCs; to.AdoxioChargingforliquorreason = (int?)from.ChargingForLiquorReason; to.AdoxioDatesubmitted = from.DateSubmitted; to.AdoxioDrinksincluded = from.DrinksIncluded; to.AdoxioDonatedorconsular = (int?)from.DonatedOrConsular; to.AdoxioEventenddate = from.EventEndDate; to.AdoxioEventname = from.EventName; to.AdoxioEventstartdate = from.EventStartDate; to.AdoxioFundraisingpurpose = (int?)from.FundRaisingPurpose; to.AdoxioHowproceedswillbeuseddescription = from.HowProceedsWillBeUsedDescription; to.AdoxioHostorganisationaddress = from.HostOrganizationAddress; to.AdoxioHostorganisationcategory = (int?)from.HostOrganizationCategory; to.AdoxioHostorganisationname = from.HostOrganizationName; to.AdoxioInvoicetrigger = from.InvoiceTrigger; to.AdoxioIsannualevent = from.IsAnnualEvent; to.AdoxioIsonpublicproperty = from.IsOnPublicProperty; to.AdoxioIslocationlicensedos = (int?)from.IsLocationLicensed; to.AdoxioIsmajorsignificance = from.IsMajorSignificance; to.AdoxioIsgstregisteredorg = from.IsGstRegisteredOrg; to.AdoxioIsmanufacturingexclusivity = from.IsManufacturingExclusivity; to.AdoxioIslocalsignificance = from.IsLocalSignificance; to.AdoxioMajorsignificancerationale = from.MajorSignificanceRationale; to.AdoxioMaxnumofguests = from.MaximumNumberOfGuests; to.AdoxioNonprofitname = from.NonProfitName; to.AdoxioPoliceapproval = (int?)from.PoliceApproval; to.AdoxioPrivateorpublic = (int?)from.PrivateOrPublic; to.AdoxioDenialreason = from.DenialReason; to.AdoxioCancellationreason = from.CancelReason; to.AdoxioResponsiblebevservicenumber = from.ResponsibleBevServiceNumber; to.AdoxioResponsiblebevnumberdoesnothave = from.ResponsibleBevServiceNumberDoesNotHave; to.AdoxioSpecialeventcity = from.SpecialEventCity; to.AdoxioSpecialeventdescripton = from.SpecialEventDescription; to.AdoxioSpecialeventpermitnumber = from.SpecialEventPermitNumber; to.AdoxioSpecialeventpostalcode = from.SpecialEventPostalCode; to.AdoxioSpecialeventprovince = from.SpecialEventProvince; to.AdoxioSpecialeventstreet1 = from.SpecialEventStreet1; to.AdoxioSpecialeventstreet2 = from.SpecialEventStreet2; to.AdoxioTastingevent = from.TastingEvent; to.AdoxioTotalservings = from.TotalServings; to.AdoxioIssupportlocalartsorsports = from.IsSupportLocalArtsOrSports; }
public ActionResult Cancel([FromRoute] string solId, [FromBody] CancelReason cancelReason) { if (string.IsNullOrEmpty(solId)) { return(BadRequest()); } // string locationReference = sol.SolLicenceNumber.Substring(sepLicenceNumber.Length); string solIdEscaped = solId.Replace("'", "''"); if (solIdEscaped.Contains("-")) { solIdEscaped = solIdEscaped.Substring(0, solIdEscaped.IndexOf("-")); } // get the given sol record. MicrosoftDynamicsCRMadoxioSpecialevent record = _dynamicsClient.GetSpecialEventByLicenceNumber(solIdEscaped); if (record == null) { return(NotFound()); } else { // cancel the record. MicrosoftDynamicsCRMadoxioSpecialevent patchRecord = new MicrosoftDynamicsCRMadoxioSpecialevent() { Statuscode = 845280000, // Cancel AdoxioCancellationreason = cancelReason?.Reason }; try { _dynamicsClient.Specialevents.Update(record.AdoxioSpecialeventid, patchRecord); } catch (HttpOperationException httpOperationException) { _logger.Error(httpOperationException, "Error updating special event record"); // fail return(StatusCode(500, "Error updating record.")); } } return(Ok()); }
/// <summary> /// Update entity in adoxio_specialevents /// </summary> /// <param name='adoxioSpecialeventid'> /// key: adoxio_specialeventid of adoxio_specialevent /// </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 adoxioSpecialeventid, MicrosoftDynamicsCRMadoxioSpecialevent body, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (adoxioSpecialeventid == null) { throw new ValidationException(ValidationRules.CannotBeNull, "adoxioSpecialeventid"); } 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("adoxioSpecialeventid", adoxioSpecialeventid); 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_specialevents({adoxio_specialeventid})").ToString(); _url = _url.Replace("{adoxio_specialeventid}", System.Uri.EscapeDataString(adoxioSpecialeventid)); // 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_specialevents /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='adoxioSpecialeventid'> /// key: adoxio_specialeventid of adoxio_specialevent /// </param> /// <param name='body'> /// New property values /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> public static HttpOperationResponse UpdateWithHttpMessages(this ISpecialevents operations, string adoxioSpecialeventid, MicrosoftDynamicsCRMadoxioSpecialevent body, Dictionary <string, List <string> > customHeaders = null) { return(operations.UpdateWithHttpMessagesAsync(adoxioSpecialeventid, body, customHeaders, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult()); }
/// <summary> /// Update entity in adoxio_specialevents /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='adoxioSpecialeventid'> /// key: adoxio_specialeventid of adoxio_specialevent /// </param> /// <param name='body'> /// New property values /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task UpdateAsync(this ISpecialevents operations, string adoxioSpecialeventid, MicrosoftDynamicsCRMadoxioSpecialevent body, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.UpdateWithHttpMessagesAsync(adoxioSpecialeventid, body, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Update entity in adoxio_specialevents /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='adoxioSpecialeventid'> /// key: adoxio_specialeventid of adoxio_specialevent /// </param> /// <param name='body'> /// New property values /// </param> public static void Update(this ISpecialevents operations, string adoxioSpecialeventid, MicrosoftDynamicsCRMadoxioSpecialevent body) { operations.UpdateAsync(adoxioSpecialeventid, body).GetAwaiter().GetResult(); }
/// <summary> /// Add new entity to adoxio_specialevents /// </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 <MicrosoftDynamicsCRMadoxioSpecialevent> CreateWithHttpMessages(this ISpecialevents operations, MicrosoftDynamicsCRMadoxioSpecialevent 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_specialevents /// </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 <MicrosoftDynamicsCRMadoxioSpecialevent> CreateAsync(this ISpecialevents operations, MicrosoftDynamicsCRMadoxioSpecialevent 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_specialevents /// </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 MicrosoftDynamicsCRMadoxioSpecialevent Create(this ISpecialevents operations, MicrosoftDynamicsCRMadoxioSpecialevent body, string prefer = "return=representation") { return(operations.CreateAsync(body, prefer).GetAwaiter().GetResult()); }
/// <summary> /// Convert a given SpecialEvent to a ViewModel /// </summary> public static ViewModels.SpecialEvent ToViewModel(this MicrosoftDynamicsCRMadoxioSpecialevent specialEvent, IDynamicsClient dynamicsClient) { ViewModels.SpecialEvent result = null; if (specialEvent != null) { result = new ViewModels.SpecialEvent { EventLocations = new List <ViewModels.SepEventLocation>(), Id = specialEvent.AdoxioSpecialeventid, AdmissionFee = specialEvent.AdoxioAdmissionfee, BeerGarden = specialEvent.AdoxioBeergarden, Capacity = specialEvent.AdoxioCapacity, NetEstimatedPST = specialEvent.AdoxioNetestimatedpst, ChargingForLiquorReason = (ViewModels.ChargingForLiquorReasons?)specialEvent.AdoxioChargingforliquorreason, DateSubmitted = specialEvent.AdoxioDatesubmitted, DrinksIncluded = specialEvent.AdoxioDrinksincluded, DonatedOrConsular = (ViewModels.DonatedOrConsular?)specialEvent.AdoxioDonatedorconsular, EventEndDate = specialEvent.AdoxioEventenddate, EventName = specialEvent.AdoxioEventname, EventStartDate = specialEvent.AdoxioEventstartdate, FundRaisingPurpose = (ViewModels.FundRaisingPurposes?)specialEvent.AdoxioFundraisingpurpose, HostOrganizationAddress = specialEvent.AdoxioHostorganisationaddress, HostOrganizationCategory = (ViewModels.HostOrgCatergory?)specialEvent.AdoxioHostorganisationcategory, HostOrganizationName = specialEvent.AdoxioHostorganisationname, HowProceedsWillBeUsedDescription = specialEvent.AdoxioHowproceedswillbeuseddescription, IsAnnualEvent = specialEvent.AdoxioIsannualevent, IsOnPublicProperty = specialEvent.AdoxioIsonpublicproperty, IsMajorSignificance = specialEvent.AdoxioIsmajorsignificance, IsLocalSignificance = specialEvent.AdoxioIslocalsignificance, IsSupportLocalArtsOrSports = specialEvent.AdoxioIssupportlocalartsorsports, IsGstRegisteredOrg = specialEvent.AdoxioIsgstregisteredorg, IsManufacturingExclusivity = specialEvent.AdoxioIsmanufacturingexclusivity, IsAgreeTsAndCs = specialEvent.AdoxioIsagreetsandcs, IsPrivateResidence = specialEvent.AdoxioIsprivateresidence, ResponsibleBevServiceNumber = specialEvent.AdoxioResponsiblebevservicenumber, ResponsibleBevServiceNumberDoesNotHave = specialEvent.AdoxioResponsiblebevnumberdoesnothave, DateAgreedToTsAndCs = specialEvent.AdoxioDateagreedtotsandcs, DateIssued = specialEvent.AdoxioDateissued, MajorSignificanceRationale = specialEvent.AdoxioMajorsignificancerationale, NonProfitName = specialEvent.AdoxioNonprofitname, PoliceAccount = specialEvent.AdoxioPoliceAccountId.ToViewModel(), PoliceDecisionBy = specialEvent.AdoxioPoliceRepresentativeId.ToViewModel(), PoliceApproval = (ViewModels.ApproverStatus?)specialEvent.AdoxioPoliceapproval, IsLocationLicensed = (ViewModels.LicensedSEPLocationValue?)specialEvent.AdoxioIslocationlicensedos, LcrbApproval = (ViewModels.ApproverStatus?)specialEvent.AdoxioLcrbapproval, PrivateOrPublic = (ViewModels.SEPPublicOrPrivate?)specialEvent.AdoxioPrivateorpublic, DenialReason = specialEvent.AdoxioDenialreason, CancelReason = specialEvent.AdoxioCancellationreason, SpecialEventCity = specialEvent.AdoxioSpecialeventcity, SpecialEventDescription = specialEvent.AdoxioSpecialeventdescripton, SpecialEventPermitNumber = specialEvent.AdoxioSpecialeventpermitnumber, SpecialEventPostalCode = specialEvent.AdoxioSpecialeventpostalcode, SpecialEventProvince = specialEvent.AdoxioSpecialeventprovince, SpecialEventStreet1 = specialEvent.AdoxioSpecialeventstreet1, SpecialEventStreet2 = specialEvent.AdoxioSpecialeventstreet2, Statecode = specialEvent.Statecode, EventStatus = (EventStatus?)specialEvent.Statuscode, // Event Status: Draft, Submitted, Pending Review, etc. TastingEvent = specialEvent.AdoxioTastingevent, TotalServings = specialEvent.AdoxioTotalservings, SepCity = specialEvent.AdoxioSpecialEventCityDistrictId?.ToViewModel(), Applicant = specialEvent.AdoxioContactId?.ToViewModel(), Invoice = specialEvent.AdoxioInvoice?.ToViewModel(), TotalProceeds = 0, TotalPurchaseCost = 0, TotalRevenue = 0 }; var locations = specialEvent?.AdoxioSpecialeventSpecialeventlocations; if (locations?.Count > 0) { result.EventLocations = locations.Select(eventLocation => eventLocation.ToViewModel()) .ToList(); } var forecast = specialEvent?.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent; if (forecast?.Count > 0) { result.DrinksSalesForecasts = forecast.Select(drinkSalesForecast => drinkSalesForecast.ToViewModel()) .ToList(); } var drinkTypes = dynamicsClient.Sepdrinktypes.Get().Value .ToList(); string beerTypeId = drinkTypes.Where(drinkType => drinkType.AdoxioName == "Beer/Cider/Cooler") .Select(drinkType => drinkType.AdoxioSepdrinktypeid) .FirstOrDefault(); string wineTypeId = drinkTypes.Where(drinkType => drinkType.AdoxioName == "Wine") .Select(drinkType => drinkType.AdoxioSepdrinktypeid) .FirstOrDefault(); string spiritsTypeId = drinkTypes.Where(drinkType => drinkType.AdoxioName == "Spirits") .Select(drinkType => drinkType.AdoxioSepdrinktypeid) .FirstOrDefault(); if (specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent == null) { result.Beer = 0; result.Wine = 0; result.Spirits = 0; } else { result.Beer = specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent .Where(sepDrinkSalesForecast => sepDrinkSalesForecast._adoxioTypeValue == beerTypeId) .Select(sepDrinkSalesForecast => sepDrinkSalesForecast.AdoxioEstimatedservings) .FirstOrDefault(); result.AverageBeerPrice = specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent .Where(sepDrinkSalesForecast => sepDrinkSalesForecast._adoxioTypeValue == beerTypeId) .Select(sepDrinkSalesForecast => sepDrinkSalesForecast.AdoxioPriceperserving) .FirstOrDefault(); result.Wine = specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent .Where(sepDrinkSalesForecast => sepDrinkSalesForecast._adoxioTypeValue == wineTypeId) .Select(sepDrinkSalesForecast => sepDrinkSalesForecast.AdoxioEstimatedservings) .FirstOrDefault(); result.AverageWinePrice = specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent .Where(sepDrinkSalesForecast => sepDrinkSalesForecast._adoxioTypeValue == wineTypeId) .Select(sepDrinkSalesForecast => sepDrinkSalesForecast.AdoxioPriceperserving) .FirstOrDefault(); result.Spirits = specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent .Where(sepDrinkSalesForecast => sepDrinkSalesForecast._adoxioTypeValue == spiritsTypeId) .Select(sepDrinkSalesForecast => sepDrinkSalesForecast.AdoxioEstimatedservings) .FirstOrDefault(); result.AverageSpiritsPrice = specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent .Where(sepDrinkSalesForecast => sepDrinkSalesForecast._adoxioTypeValue == spiritsTypeId) .Select(sepDrinkSalesForecast => sepDrinkSalesForecast.AdoxioPriceperserving) .FirstOrDefault(); } result.TotalProceeds = specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent == null ? 0 : specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent .Sum(sepDrinkSalesForecast => sepDrinkSalesForecast.AdoxioEstimatedrevenue.GetValueOrDefault() - sepDrinkSalesForecast.AdoxioEstimatedcost.GetValueOrDefault()); result.TotalRevenue = specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent == null ? 0 : specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent .Sum(sepDrinkSalesForecast => sepDrinkSalesForecast.AdoxioEstimatedrevenue.GetValueOrDefault()); result.TotalPurchaseCost = specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent == null ? 0 : specialEvent.AdoxioSpecialeventAdoxioSepdrinksalesforecastSpecialEvent .Sum(sepDrinkSalesForecast => sepDrinkSalesForecast.AdoxioEstimatedcost.GetValueOrDefault()); if (specialEvent.AdoxioSpecialeventSpecialeventtsacs != null) { result.TermsAndConditions = new List <SepTermAndCondition>(); specialEvent.AdoxioSpecialeventSpecialeventtsacs.ToList() .ForEach(term => { result.TermsAndConditions.Add(new SepTermAndCondition { Id = term.AdoxioSpecialeventtandcid, Content = term.AdoxioTermsandcondition, Originator = term.AdoxioOriginator }); }); } } return(result); }