コード例 #1
0
        public static string GetDocumentFolderName(this MicrosoftDynamicsCRMadoxioEvent eventEntity)
        {
            string entityIdCleaned = CleanGuidForSharePoint(eventEntity.AdoxioEventid);
            string folderName      = $"event_{entityIdCleaned}";

            return(folderName);
        }
コード例 #2
0
        public async Task <IActionResult> CreateLicenceEvent([FromBody] LicenceEvent item)
        {
            MicrosoftDynamicsCRMadoxioEvent dynamicsEvent = new MicrosoftDynamicsCRMadoxioEvent();

            if (item?.Status == LicenceEventStatus.Submitted)
            {
                bool alwaysAuthorization;
                try
                {
                    var licence = _dynamicsClient.Licenceses.GetByKey(item.LicenceId);
                    alwaysAuthorization = licence.AdoxioIseventapprovalalwaysrequired == null ? false : (bool)licence.AdoxioIseventapprovalalwaysrequired;
                }
                catch (HttpOperationException ex)
                {
                    _logger.LogError(ex, "Error creating event");
                    return(BadRequest());
                }
                item.EventClass = item.DetermineEventClass(alwaysAuthorization);
                if (item.EventClass != EventClass.Authorization || item.EventCategory == EventCategory.Market)
                {
                    item.Status = LicenceEventStatus.Approved;
                }
                else
                {
                    item.Status = LicenceEventStatus.InReview;
                }
            }

            dynamicsEvent.CopyValues(item);

            // get the current user.
            UserSettings userSettings = UserSettings.CreateFromHttpContext(_httpContextAccessor);

            dynamicsEvent.AccountODataBind = _dynamicsClient.GetEntityURI("accounts", userSettings.AccountId);

            if (!string.IsNullOrEmpty(item.LicenceId))
            {
                dynamicsEvent.LicenceODataBind = _dynamicsClient.GetEntityURI("adoxio_licenceses", item.LicenceId);
            }

            try
            {
                dynamicsEvent = _dynamicsClient.Events.Create(dynamicsEvent);
            }
            catch (HttpOperationException ex)
            {
                _logger.LogError(ex, "Error creating event");
                return(BadRequest());
            }

            LicenceEvent viewModelEvent = dynamicsEvent.ToViewModel(_dynamicsClient);

            // create event schedules - if any
            viewModelEvent.Schedules = CreateEventSchedules(item, dynamicsEvent);
            // create TUA event locations - if any
            viewModelEvent.EventLocations = CreateEventLocations(item, dynamicsEvent);

            return(new JsonResult(viewModelEvent));
        }
コード例 #3
0
        // Converts a dynamics entity into a view model
        public static LicenceEvent ToViewModel(this MicrosoftDynamicsCRMadoxioEvent item, IDynamicsClient dynamicsClient)
        {
            LicenceEvent result = null;

            if (item != null)
            {
                result = new LicenceEvent();
                if (item.AdoxioEventid != null)
                {
                    result.Id = item.AdoxioEventid;
                }
                result.Status           = (LicenceEventStatus?)item.Statuscode;
                result.Name             = item.AdoxioName;
                result.StartDate        = item.AdoxioEventstartdate;
                result.EndDate          = item.AdoxioEventenddate;
                result.VenueDescription = item.AdoxioVenuenamedescription;
                result.AdditionalLocationInformation = item.AdoxioAdditionallocationinfo;
                result.FoodService              = (FoodService?)item.AdoxioFoodservice;
                result.FoodServiceDescription   = item.AdoxioFoodservicedescription;
                result.Entertainment            = (Entertainment?)item.AdoxioEntertainment;
                result.EntertainmentDescription = item.AdoxioEntertainmentdescription;
                result.ContactPhone             = item.AdoxioContactphonenumber;
                result.ExternalId           = item.AdoxioExternalid;
                result.ContactName          = item.AdoxioContactname;
                result.ContactEmail         = item.AdoxioContactemail;
                result.EventNumber          = item.AdoxioEventnumber;
                result.ClientHostname       = item.AdoxioClienthostname;
                result.EventType            = (EventType?)item.AdoxioEventtype;
                result.EventTypeDescription = item.AdoxioEventdescription;
                result.ImportSequenceNumber = item.Importsequencenumber;
                result.SpecificLocation     = (SpecificLocation?)item.AdoxioSpecificlocation;
                result.EventClass           = (EventClass?)item.AdoxioClass;
                result.MaxAttendance        = item.AdoxioMaxattendance;
                result.MaxStaffAttendance   = item.AdoxioMaxstaffattendance;
                result.MinorsAttending      = item.AdoxioAttendanceminors;
                result.CommunityApproval    = item.AdoxioCommunityapproval;
                result.NotifyEventInspector = item.AdoxioNotifyeventinspector;
                result.LicenceId            = item._adoxioLicenceValue;
                result.AccountId            = item._adoxioAccountValue;
                result.Street1    = item.AdoxioStreet1;
                result.Street2    = item.AdoxioStreet2;
                result.City       = item.AdoxioCity;
                result.Province   = item.AdoxioProvince;
                result.PostalCode = item.AdoxioPostalcode;
                result.ModifiedOn = item.Modifiedon;
                result.Schedules  = new List <LicenceEventSchedule>();
                // Security Plan
                result.SecurityPlanRequested                             = item.AdoxioRequestsafetysecurityplan;
                result.EventLiquorLayout                                 = item.AdoxioEventliquorlayout;
                result.DailyEventAttendees                               = item.AdoxioNumberdailyeventattendees;
                result.DailyMinorAttendees                               = item.AdoxioNumberdailyminorattendees;
                result.OccupantLoad                                      = item.AdoxioEventoccupantload;
                result.OccupantLoadAvailable                             = item.AdoxioIseventloadavailable;
                result.OccupantLoadServiceArea                           = item.AdoxioEventoccupantloadservicesarea;
                result.OccupantLoadServiceAreaAvailable                  = item.AdoxioIsservicearealoadavailable;
                result.ServiceAreaControlledDetails                      = item.AdoxioEventliquorcontainment;
                result.StaffingManagers                                  = item.AdoxioEventstaffingmanagers;
                result.StaffingBartenders                                = item.AdoxioEventstaffingbartenders;
                result.StaffingServers                                   = item.AdoxioEventstaffingservers;
                result.SecurityPersonnel                                 = item.AdoxioSecuritycompanysummary;
                result.SecurityPersonnelThroughCompany                   = item.AdoxioSecuritypersonnelnumberhired;
                result.SecurityCompanyName                               = item.AdoxioSecuritycompanyname;
                result.SecurityCompanyAddress                            = item.AdoxioSecuritycompanystreet;
                result.SecurityCompanyCity                               = item.AdoxioSecuritycompanycity;
                result.SecurityCompanyPostalCode                         = item.AdoxioSecuritycompanypostal;
                result.SecurityCompanyContactPerson                      = item.AdoxioSecuritycompanycontactname;
                result.SecurityCompanyPhoneNumber                        = item.AdoxioSecuritycompanycontactphone;
                result.SecurityCompanyEmail                              = item.AdoxioSecuritycompanycontactemail;
                result.SecurityPoliceOfficerSummary                      = item.AdoxioPoliceofficersummary;
                result.SafeAndResponsibleMinorsNotAttending              = item.AdoxioIsminorsattending;
                result.SafeAndResponsibleLiquorAreaControlled            = item.AdoxioIsliquorareacontrolled;
                result.SafeAndResponsibleLiquorAreaControlledDescription = item.AdoxioLiquorareacontrolleddetails;
                result.SafeAndResponsibleMandatoryID                     = item.AdoxioIstwopiecesidrequired;
                result.SafeAndResponsibleSignsAdvisingMinors             = item.AdoxioIssignsadvisingminors;
                result.SafeAndResponsibleMinorsOther                     = item.AdoxioIsotherminorssafety;
                result.SafeAndResponsibleMinorsOtherDescription          = item.AdoxioIsotherminorssafetydetails;
                result.SafeAndResponsibleSignsAdvisingRemoval            = item.AdoxioIssignsintoxicatedpersons;
                result.SafeAndResponsibleSignsAdvisingTwoDrink           = item.AdoxioIssignstwodrinkmax;
                result.SafeAndResponsibleOverConsumptionOther            = item.AdoxioIsotherconsumptionsafety;
                result.SafeAndResponsibleOverConsumptionOtherDescription = item.AdoxioIsotherconsumptionsafetydetails;
                result.SafeAndResponsibleReadAppendix2                   = item.AdoxioIsdisturbanceappendix2;
                result.SafeAndResponsibleDisturbancesOther               = item.AdoxioIsotherdisturbance;
                result.SafeAndResponsibleDisturbancesOtherDescription    = item.AdoxioIsotherdisturbancedetails;
                result.SafeAndResponsibleAdditionalSafetyMeasures        = item.AdoxioAdditionalsafetydetails;
                result.SafeAndResponsibleServiceAreaSupervision          = item.AdoxioServiceareaentrancesupervisiondetails;
                result.DeclarationIsAccurate                             = item.AdoxioIsdeclarationaccurate;
                result.SecurityPlanSubmitted                             = item.AdoxioSafetysecurityplanchangessubmitted;
                result.SEPLicensee           = item.AdoxioSeplicensee;
                result.SEPLicenceNumber      = item.AdoxioSeplicencenumber;
                result.SEPContactName        = item.AdoxioSepcontactname;
                result.SEPContactPhoneNumber = item.AdoxioSepcontactphonenumber;
                //market events
                result.IsNoPreventingSaleofLiquor  = item.AdoxioIsnopreventingsaleofliquor;
                result.IsMarketManagedorCarried    = item.AdoxioIsmarketmanagedorcarried;
                result.IsMarketOnlyVendors         = item.AdoxioIsmarketonlyvendors;
                result.IsNoImportedGoods           = item.AdoxioIsnoimportedgoods;
                result.IsMarketHostsSixVendors     = item.AdoxioIsmarkethostssixvendors;
                result.IsMarketMaxAmountorDuration = item.AdoxioIsmarketmaxamountorduration;
                result.MKTOrganizerContactName     = item.AdoxioMktorganizercontactname;
                result.MKTOrganizerContactPhone    = item.AdoxioMktorganizercontactphone;
                result.RegistrationNumber          = item.AdoxioRegistrationnumber;
                result.BusinessNumber             = item.AdoxioBusinessnumber;
                result.MarketName                 = item.AdoxioMarketname;
                result.MarketWebsite              = item.AdoxioMarketwebsite;
                result.MarketDuration             = (MarketDuration?)item.AdoxioMarketduration;
                result.IsAllStaffServingitRight   = item.AdoxioIsallstaffservingitright;
                result.IsSalesAreaAvailandDefined = item.AdoxioIssalesareaavailanddefined;
                result.IsSampleSizeCompliant      = item.AdoxioIssamplesizecompliant;
                result.EventCategory              = (EventCategory?)item.AdoxioEventcategory;
                result.MarketEventType            = (MarketEventType?)item.AdoxioMarketeventtype;

                // temporary use area (TUA) events
                result.EventName           = item.AdoxioEventname;
                result.TuaEventType        = (TuaEventType?)item.AdoxioTuaeventtype;
                result.IsClosedToPublic    = item.AdoxioIsclosedtopublic;
                result.IsWedding           = item.AdoxioIswedding;
                result.IsNetworkingParty   = item.AdoxioIsnetworkingparty;
                result.IsConcert           = item.AdoxioIsconcert;
                result.IsBanquet           = item.AdoxioIsbanquet;
                result.IsAmplifiedSound    = item.AdoxioIsamplifiedsound;
                result.IsDancing           = item.AdoxioIsdancing;
                result.IsReception         = item.AdoxioIsreception;
                result.IsLiveEntertainment = item.AdoxioIsliveentertainment;
                result.IsGambling          = item.AdoxioIsgambling;
                result.IsNoneOfTheAbove    = item.AdoxioIsnoneoftheabove;
                result.IsAgreement1        = item.AdoxioIsagreement1;
                result.IsAgreement2        = item.AdoxioIsagreement2;
                result.EventLocations      = new List <LicenceEventLocation>();
            }

            MicrosoftDynamicsCRMadoxioEventscheduleCollection eventSchedules = dynamicsClient.GetEventSchedulesByEventId(result.Id);

            foreach (var schedule in eventSchedules.Value)
            {
                result.Schedules.Add(schedule.ToViewModel());
            }

            // TUA event locations
            MicrosoftDynamicsCRMadoxioEventlocationCollection eventLocations = dynamicsClient.GetEventLocationsByEventId(result.Id);

            foreach (var loc in eventLocations?.Value)
            {
                result.EventLocations.Add(loc.ToViewModel());
            }

            return(result);
        }
コード例 #4
0
        // Converts a view model into a dynamics entity
        public static void CopyValues(this MicrosoftDynamicsCRMadoxioEvent to, LicenceEvent from)
        {
            to.AdoxioEventid = from.Id;
            to.AdoxioName    = from.Name;
            to.Statuscode    = (int?)from.Status;
            if (from.StartDate.HasValue)
            {
                DateTimeOffset oldStart = (DateTimeOffset)from.StartDate;
                to.AdoxioEventstartdate = oldStart;

                /*DateTimeOffset startDate = new DateTimeOffset(oldStart.Year, oldStart.Month, oldStart.Day, 0, 0, 0, new TimeSpan(0, 0, 0));
                 * to.AdoxioStartdate = startDate;*/
            }
            if (from.EndDate.HasValue)
            {
                DateTimeOffset oldEnd = (DateTimeOffset)from.EndDate;
                to.AdoxioEventenddate = oldEnd;

                /*DateTimeOffset endDate = new DateTimeOffset(oldEnd.Year, oldEnd.Month, oldEnd.Day, 0, 0, 0, TimeZone.CurrentTimeZone);
                 * to.AdoxioEnddate = endDate;*/
            }
            to.AdoxioVenuenamedescription     = from.VenueDescription;
            to.AdoxioAdditionallocationinfo   = from.AdditionalLocationInformation;
            to.AdoxioFoodservice              = (int?)from.FoodService;
            to.AdoxioFoodservicedescription   = from.FoodServiceDescription;
            to.AdoxioEntertainment            = (int?)from.Entertainment;
            to.AdoxioEntertainmentdescription = from.EntertainmentDescription;
            to.AdoxioContactphonenumber       = from.ContactPhone;
            to.AdoxioContactname              = from.ContactName;
            to.AdoxioExternalid           = from.ExternalId;
            to.AdoxioContactemail         = from.ContactEmail;
            to.AdoxioEventnumber          = from.EventNumber;
            to.AdoxioClienthostname       = from.ClientHostname;
            to.AdoxioEventtype            = (int?)from.EventType;
            to.AdoxioEventdescription     = from.EventTypeDescription;
            to.Importsequencenumber       = from.ImportSequenceNumber;
            to.AdoxioSpecificlocation     = (int?)from.SpecificLocation;
            to.AdoxioClass                = (int?)from.EventClass;
            to.AdoxioMaxattendance        = from.MaxAttendance;
            to.AdoxioMaxstaffattendance   = from.MaxStaffAttendance;
            to.AdoxioAttendanceminors     = from.MinorsAttending;
            to.AdoxioCommunityapproval    = from.CommunityApproval;
            to.AdoxioNotifyeventinspector = from.NotifyEventInspector;
            to.AdoxioStreet1              = from.Street1;
            to.AdoxioStreet2              = from.Street2;
            to.AdoxioCity       = from.City;
            to.AdoxioProvince   = from.Province;
            to.AdoxioPostalcode = from.PostalCode;

            // Security Plan
            to.AdoxioRequestsafetysecurityplan             = from.SecurityPlanRequested;
            to.AdoxioEventliquorlayout                     = from.EventLiquorLayout;
            to.AdoxioNumberdailyeventattendees             = from.DailyEventAttendees;
            to.AdoxioNumberdailyminorattendees             = from.DailyMinorAttendees;
            to.AdoxioEventoccupantload                     = from.OccupantLoad;
            to.AdoxioIseventloadavailable                  = from.OccupantLoadAvailable;
            to.AdoxioEventoccupantloadservicesarea         = from.OccupantLoadServiceArea;
            to.AdoxioIsservicearealoadavailable            = from.OccupantLoadServiceAreaAvailable;
            to.AdoxioEventliquorcontainment                = from.ServiceAreaControlledDetails;
            to.AdoxioEventstaffingmanagers                 = from.StaffingManagers;
            to.AdoxioEventstaffingbartenders               = from.StaffingBartenders;
            to.AdoxioEventstaffingservers                  = from.StaffingServers;
            to.AdoxioSecuritycompanysummary                = from.SecurityPersonnel;
            to.AdoxioSecuritypersonnelnumberhired          = from.SecurityPersonnelThroughCompany;
            to.AdoxioSecuritycompanyname                   = from.SecurityCompanyName;
            to.AdoxioSecuritycompanystreet                 = from.SecurityCompanyAddress;
            to.AdoxioSecuritycompanycity                   = from.SecurityCompanyCity;
            to.AdoxioSecuritycompanypostal                 = from.SecurityCompanyPostalCode;
            to.AdoxioSecuritycompanycontactname            = from.SecurityCompanyContactPerson;
            to.AdoxioSecuritycompanycontactphone           = from.SecurityCompanyPhoneNumber;
            to.AdoxioSecuritycompanycontactemail           = from.SecurityCompanyEmail;
            to.AdoxioPoliceofficersummary                  = from.SecurityPoliceOfficerSummary;
            to.AdoxioIsminorsattending                     = from.SafeAndResponsibleMinorsNotAttending;
            to.AdoxioIsliquorareacontrolled                = from.SafeAndResponsibleLiquorAreaControlled;
            to.AdoxioLiquorareacontrolleddetails           = from.SafeAndResponsibleLiquorAreaControlledDescription;
            to.AdoxioIstwopiecesidrequired                 = from.SafeAndResponsibleMandatoryID;
            to.AdoxioIssignsadvisingminors                 = from.SafeAndResponsibleSignsAdvisingMinors;
            to.AdoxioIsotherminorssafety                   = from.SafeAndResponsibleMinorsOther;
            to.AdoxioIsotherminorssafetydetails            = from.SafeAndResponsibleMinorsOtherDescription;
            to.AdoxioIssignsintoxicatedpersons             = from.SafeAndResponsibleSignsAdvisingRemoval;
            to.AdoxioIssignstwodrinkmax                    = from.SafeAndResponsibleSignsAdvisingTwoDrink;
            to.AdoxioIsotherconsumptionsafety              = from.SafeAndResponsibleOverConsumptionOther;
            to.AdoxioIsotherconsumptionsafetydetails       = from.SafeAndResponsibleOverConsumptionOtherDescription;
            to.AdoxioIsdisturbanceappendix2                = from.SafeAndResponsibleReadAppendix2;
            to.AdoxioIsotherdisturbance                    = from.SafeAndResponsibleDisturbancesOther;
            to.AdoxioIsotherdisturbancedetails             = from.SafeAndResponsibleDisturbancesOtherDescription;
            to.AdoxioAdditionalsafetydetails               = from.SafeAndResponsibleAdditionalSafetyMeasures;
            to.AdoxioServiceareaentrancesupervisiondetails = from.SafeAndResponsibleServiceAreaSupervision;
            to.AdoxioIsdeclarationaccurate                 = from.DeclarationIsAccurate;

            to.AdoxioSepcontactphonenumber = from.SEPContactPhoneNumber;
            to.AdoxioSepcontactname        = from.SEPContactName;
            to.AdoxioSeplicencenumber      = from.SEPLicenceNumber;
            to.AdoxioSeplicensee           = from.SEPLicensee;

            to.AdoxioSafetysecurityplanchangessubmitted = from.SecurityPlanSubmitted;

            // market events
            to.AdoxioIsnopreventingsaleofliquor  = from.IsNoPreventingSaleofLiquor;
            to.AdoxioIsmarketmanagedorcarried    = from.IsMarketManagedorCarried;
            to.AdoxioIsmarketonlyvendors         = from.IsMarketOnlyVendors;
            to.AdoxioIsnoimportedgoods           = from.IsNoImportedGoods;
            to.AdoxioIsmarkethostssixvendors     = from.IsMarketHostsSixVendors;
            to.AdoxioIsmarketmaxamountorduration = from.IsMarketMaxAmountorDuration;
            to.AdoxioMktorganizercontactname     = from.MKTOrganizerContactName;
            to.AdoxioMktorganizercontactphone    = from.MKTOrganizerContactPhone;
            to.AdoxioRegistrationnumber          = from.RegistrationNumber;
            to.AdoxioBusinessnumber             = from.BusinessNumber;
            to.AdoxioMarketname                 = from.MarketName;
            to.AdoxioMarketwebsite              = from.MarketWebsite;
            to.AdoxioMarketduration             = (int?)from.MarketDuration;
            to.AdoxioIsallstaffservingitright   = from.IsAllStaffServingitRight;
            to.AdoxioIssalesareaavailanddefined = from.IsSalesAreaAvailandDefined;
            to.AdoxioIssamplesizecompliant      = from.IsSampleSizeCompliant;
            to.AdoxioEventcategory              = (int?)from.EventCategory;
            to.AdoxioMarketeventtype            = (int?)from.MarketEventType;

            // TUA events
            to.AdoxioEventname           = from.EventName;
            to.AdoxioTuaeventtype        = (int?)from.TuaEventType;
            to.AdoxioIsclosedtopublic    = from.IsClosedToPublic;
            to.AdoxioIswedding           = from.IsWedding;
            to.AdoxioIsnetworkingparty   = from.IsNetworkingParty;
            to.AdoxioIsconcert           = from.IsConcert;
            to.AdoxioIsbanquet           = from.IsBanquet;
            to.AdoxioIsamplifiedsound    = from.IsAmplifiedSound;
            to.AdoxioIsdancing           = from.IsDancing;
            to.AdoxioIsreception         = from.IsReception;
            to.AdoxioIsliveentertainment = from.IsLiveEntertainment;
            to.AdoxioIsgambling          = from.IsGambling;
            to.AdoxioIsnoneoftheabove    = from.IsNoneOfTheAbove;
            to.AdoxioIsagreement1        = from.IsAgreement1;
            to.AdoxioIsagreement2        = from.IsAgreement2;
        }
コード例 #5
0
 /// <summary>
 /// Update entity in adoxio_events
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='adoxioEventid'>
 /// key: adoxio_eventid of adoxio_event
 /// </param>
 /// <param name='body'>
 /// New property values
 /// </param>
 /// <param name='customHeaders'>
 /// Headers that will be added to request.
 /// </param>
 public static HttpOperationResponse UpdateWithHttpMessages(this IEvents operations, string adoxioEventid, MicrosoftDynamicsCRMadoxioEvent body, Dictionary <string, List <string> > customHeaders = null)
 {
     return(operations.UpdateWithHttpMessagesAsync(adoxioEventid, body, customHeaders, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult());
 }
コード例 #6
0
 /// <summary>
 /// Update entity in adoxio_events
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='adoxioEventid'>
 /// key: adoxio_eventid of adoxio_event
 /// </param>
 /// <param name='body'>
 /// New property values
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task UpdateAsync(this IEvents operations, string adoxioEventid, MicrosoftDynamicsCRMadoxioEvent body, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.UpdateWithHttpMessagesAsync(adoxioEventid, body, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
コード例 #7
0
 /// <summary>
 /// Update entity in adoxio_events
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='adoxioEventid'>
 /// key: adoxio_eventid of adoxio_event
 /// </param>
 /// <param name='body'>
 /// New property values
 /// </param>
 public static void Update(this IEvents operations, string adoxioEventid, MicrosoftDynamicsCRMadoxioEvent body)
 {
     operations.UpdateAsync(adoxioEventid, body).GetAwaiter().GetResult();
 }
コード例 #8
0
        private List <LicenceEventSchedule> CreateEventSchedules(LicenceEvent payload, MicrosoftDynamicsCRMadoxioEvent dynamicsEvent)
        {
            var schedules = new List <LicenceEventSchedule>();

            if (payload.Schedules != null && payload.Schedules.Count > 0 && dynamicsEvent != null)
            {
                foreach (var eventSchedule in payload.Schedules)
                {
                    var patchObject = new MicrosoftDynamicsCRMadoxioEventschedule();
                    patchObject.CopyValues(eventSchedule);
                    patchObject.EventODataBind = _dynamicsClient.GetEntityURI("adoxio_events", dynamicsEvent.AdoxioEventid);
                    var newEventSchedule = _dynamicsClient.Eventschedules.Create(patchObject);
                    schedules.Add(newEventSchedule.ToViewModel());
                }
            }
            return(schedules);
        }
コード例 #9
0
 /// <summary>
 /// Add new entity to adoxio_events
 /// </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 <MicrosoftDynamicsCRMadoxioEvent> CreateAsync(this IEvents operations, MicrosoftDynamicsCRMadoxioEvent body, string prefer = "return=representation", CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateWithHttpMessagesAsync(body, prefer, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
コード例 #10
0
 /// <summary>
 /// Add new entity to adoxio_events
 /// </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 MicrosoftDynamicsCRMadoxioEvent Create(this IEvents operations, MicrosoftDynamicsCRMadoxioEvent body, string prefer = "return=representation")
 {
     return(operations.CreateAsync(body, prefer).GetAwaiter().GetResult());
 }
コード例 #11
0
        public async Task <IActionResult> CreateLicenceEvent([FromBody] ViewModels.LicenceEvent item)
        {
            MicrosoftDynamicsCRMadoxioEvent dynamicsEvent = new MicrosoftDynamicsCRMadoxioEvent();

            if (item?.Status == LicenceEventStatus.Submitted)
            {
                bool alwaysAuthorization;
                try
                {
                    var licence = _dynamicsClient.Licenceses.GetByKey(item.LicenceId);
                    alwaysAuthorization = licence.AdoxioIseventapprovalalwaysrequired == null ? false : (bool)licence.AdoxioIseventapprovalalwaysrequired;
                }
                catch (HttpOperationException ex)
                {
                    _logger.LogError(ex, "Error creating event");
                    return(BadRequest());
                }
                item.EventClass = item.DetermineEventClass(alwaysAuthorization);
                if (item.EventClass != EventClass.Authorization || item.EventCategory == EventCategory.Market)
                {
                    item.Status = LicenceEventStatus.Approved;
                }
                else
                {
                    item.Status = LicenceEventStatus.InReview;
                }
            }

            dynamicsEvent.CopyValues(item);

            string       temp         = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
            UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp);

            dynamicsEvent.AccountODataBind = _dynamicsClient.GetEntityURI("accounts", userSettings.AccountId);

            if (!string.IsNullOrEmpty(item.LicenceId))
            {
                dynamicsEvent.LicenceODataBind = _dynamicsClient.GetEntityURI("adoxio_licenceses", item.LicenceId);
            }

            try
            {
                dynamicsEvent = _dynamicsClient.Events.Create(dynamicsEvent);
            }
            catch (HttpOperationException ex)
            {
                _logger.LogError(ex, "Error creating event");
                return(BadRequest());
            }

            LicenceEvent viewModelEvent = dynamicsEvent.ToViewModel(_dynamicsClient);

            if (item.Schedules != null && item.Schedules.Count > 0)
            {
                viewModelEvent.Schedules = new List <LicenceEventSchedule>();
                foreach (LicenceEventSchedule eventSchedule in item.Schedules)
                {
                    MicrosoftDynamicsCRMadoxioEventschedule dynamicsSchedule = new MicrosoftDynamicsCRMadoxioEventschedule();
                    dynamicsSchedule.CopyValues(eventSchedule);
                    dynamicsSchedule.EventODataBind = _dynamicsClient.GetEntityURI("adoxio_events", dynamicsEvent.AdoxioEventid);
                    MicrosoftDynamicsCRMadoxioEventschedule newEventSchedule = _dynamicsClient.Eventschedules.Create(dynamicsSchedule);
                    viewModelEvent.Schedules.Add(newEventSchedule.ToViewModel());
                }
            }

            return(new JsonResult(viewModelEvent));
        }
コード例 #12
0
        public async Task <IActionResult> UpdateLicenceEvent([FromBody] ViewModels.LicenceEvent item, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }

            MicrosoftDynamicsCRMadoxioEvent dynamicsEvent = _dynamicsClient.GetEventByIdWithChildren(id);

            if (dynamicsEvent == null || !CurrentUserHasAccessToEventOwnedBy(dynamicsEvent.AdoxioAccount.Accountid))
            {
                return(new NotFoundResult());
            }

            // not updating security plan
            if (item?.SecurityPlanSubmitted == null && item?.Status == LicenceEventStatus.Submitted)
            {
                // determine event class
                bool alwaysAuthorization;
                try
                {
                    var licence = _dynamicsClient.Licenceses.GetByKey(item.LicenceId);
                    alwaysAuthorization = licence.AdoxioIseventapprovalalwaysrequired == null ? false : (bool)licence.AdoxioIseventapprovalalwaysrequired;
                }
                catch (HttpOperationException ex)
                {
                    _logger.LogError(ex, "Error updating event");
                    return(BadRequest());
                }
                item.EventClass = item.DetermineEventClass(alwaysAuthorization);
                if (item.EventClass != EventClass.Authorization)
                {
                    item.Status = LicenceEventStatus.Approved;
                }
                else
                {
                    item.Status = LicenceEventStatus.InReview;
                }
            }

            MicrosoftDynamicsCRMadoxioEvent patchEvent = new MicrosoftDynamicsCRMadoxioEvent();

            patchEvent.CopyValues(item);
            if (!string.IsNullOrEmpty(item.LicenceId) && item.LicenceId != dynamicsEvent._adoxioLicenceValue)
            {
                patchEvent.LicenceODataBind = _dynamicsClient.GetEntityURI("adoxio_licenceses", item.LicenceId);
            }
            try
            {
                _dynamicsClient.Events.Update(id, patchEvent);
            }
            catch (HttpOperationException httpOperationException)
            {
                _logger.LogError(httpOperationException, "Error updating event");
            }

            dynamicsEvent = _dynamicsClient.GetEventByIdWithChildren(id);

            /* Get current event schedules and delete */
            LicenceEvent viewModelEvent = dynamicsEvent.ToViewModel(_dynamicsClient);

            if (viewModelEvent.Schedules != null && viewModelEvent.Schedules.Count > 0)
            {
                foreach (LicenceEventSchedule eventSchedule in viewModelEvent.Schedules)
                {
                    _dynamicsClient.Eventschedules.Delete(eventSchedule.Id);
                }
            }

            /* Create new event schedules */
            if (item.Schedules != null && item.Schedules.Count > 0)
            {
                viewModelEvent.Schedules = new List <LicenceEventSchedule>();
                foreach (LicenceEventSchedule eventSchedule in item.Schedules)
                {
                    MicrosoftDynamicsCRMadoxioEventschedule dynamicsSchedule = new MicrosoftDynamicsCRMadoxioEventschedule();
                    dynamicsSchedule.CopyValues(eventSchedule);
                    dynamicsSchedule.EventODataBind = _dynamicsClient.GetEntityURI("adoxio_events", dynamicsEvent.AdoxioEventid);
                    MicrosoftDynamicsCRMadoxioEventschedule newEventSchedule = _dynamicsClient.Eventschedules.Create(dynamicsSchedule);
                    viewModelEvent.Schedules.Add(newEventSchedule.ToViewModel());
                }
            }

            if (dynamicsEvent != null)
            {
                return(new JsonResult(dynamicsEvent.ToViewModel(_dynamicsClient)));
            }
            return(new NotFoundResult());
        }
コード例 #13
0
        private List <LicenceEventLocation> CreateEventLocations(LicenceEvent payload, MicrosoftDynamicsCRMadoxioEvent dynamicsEvent)
        {
            var locations = new List <LicenceEventLocation>();

            if (payload.EventLocations != null && payload.EventLocations.Count > 0 && dynamicsEvent != null)
            {
                foreach (var eventLocation in payload.EventLocations)
                {
                    var patchObject = new MicrosoftDynamicsCRMadoxioEventlocation();
                    patchObject.CopyValues(eventLocation);
                    patchObject.EventODataBind       = _dynamicsClient.GetEntityURI("adoxio_events", dynamicsEvent.AdoxioEventid);
                    patchObject.ServiceAreaODataBind = _dynamicsClient.GetEntityURI("adoxio_serviceareas", eventLocation.ServiceAreaId);
                    var newLocation = _dynamicsClient.Eventlocations.Create(patchObject);
                    locations.Add(newLocation.ToViewModel());
                }
            }
            return(locations);
        }
コード例 #14
0
        /// <summary>
        /// Update entity in adoxio_events
        /// </summary>
        /// <param name='adoxioEventid'>
        /// key: adoxio_eventid of adoxio_event
        /// </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 adoxioEventid, MicrosoftDynamicsCRMadoxioEvent body, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (adoxioEventid == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "adoxioEventid");
            }
            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("adoxioEventid", adoxioEventid);
                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_events({adoxio_eventid})").ToString();

            _url = _url.Replace("{adoxio_eventid}", System.Uri.EscapeDataString(adoxioEventid));
            // 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);
        }
コード例 #15
0
 /// <summary>
 /// Add new entity to adoxio_events
 /// </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 <MicrosoftDynamicsCRMadoxioEvent> CreateWithHttpMessages(this IEvents operations, MicrosoftDynamicsCRMadoxioEvent body, string prefer = "return=representation", Dictionary <string, List <string> > customHeaders = null)
 {
     return(operations.CreateWithHttpMessagesAsync(body, prefer, customHeaders, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult());
 }
コード例 #16
0
        public static void CreateEventDocumentLocation(this IDynamicsClient _dynamicsClient, MicrosoftDynamicsCRMadoxioEvent eventEntity, string folderName, string name)
        {
            // set the parent document library.
            var parentDocumentLibraryReference = _dynamicsClient.GetDocumentLocationReferenceByRelativeURL("adoxio_event");

            var eventUri = _dynamicsClient.GetEntityURI("adoxio_events", eventEntity.AdoxioEventid);
            // now create a document location to link them.

            // Create the SharePointDocumentLocation entity
            var mdcsdl = new MicrosoftDynamicsCRMsharepointdocumentlocation
            {
                RegardingobjectIdEventODataBind = eventUri,
                ParentsiteorlocationSharepointdocumentlocationODataBind =
                    _dynamicsClient.GetEntityURI("sharepointdocumentlocations", parentDocumentLibraryReference),
                Relativeurl = folderName,
                Description = "Event Files",
                Name        = name
            };

            var sharepointdocumentlocationid = _dynamicsClient.DocumentLocationExistsWithCleanup(mdcsdl);

            if (sharepointdocumentlocationid == null)
            {
                try
                {
                    mdcsdl = _dynamicsClient.Sharepointdocumentlocations.Create(mdcsdl);
                }
                catch (HttpOperationException odee)
                {
                    Log.Error(odee, "Error creating SharepointDocumentLocation");
                    mdcsdl = null;
                }

                if (mdcsdl != null)
                {
                    var sharePointLocationData = _dynamicsClient.GetEntityURI("sharepointdocumentlocations",
                                                                              mdcsdl.Sharepointdocumentlocationid);

                    var oDataId = new Odataid
                    {
                        OdataidProperty = sharePointLocationData
                    };
                    try
                    {
                        _dynamicsClient.Events.AddReference(eventEntity.AdoxioEventid,
                                                            "adoxio_event_SharePointDocumentLocations", oDataId);
                    }
                    catch (HttpOperationException odee)
                    {
                        Log.Error(odee, "Error adding reference to SharepointDocumentLocation");
                    }
                }
            }
        }
コード例 #17
0
        public async Task <IActionResult> UpdateLicenceEvent([FromBody] LicenceEvent item, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }

            MicrosoftDynamicsCRMadoxioEvent dynamicsEvent = _dynamicsClient.GetEventByIdWithChildren(id);

            if (dynamicsEvent == null || !CurrentUserHasAccessToEventOwnedBy(dynamicsEvent.AdoxioAccount.Accountid))
            {
                return(NotFound());
            }

            // not updating security plan
            if (item?.SecurityPlanSubmitted == null && item?.Status == LicenceEventStatus.Submitted)
            {
                // determine event class
                bool alwaysAuthorization;
                try
                {
                    var licence = _dynamicsClient.Licenceses.GetByKey(item.LicenceId);
                    alwaysAuthorization = licence.AdoxioIseventapprovalalwaysrequired == null ? false : (bool)licence.AdoxioIseventapprovalalwaysrequired;
                }
                catch (HttpOperationException ex)
                {
                    _logger.LogError(ex, "Error updating event");
                    return(BadRequest());
                }
                item.EventClass = item.DetermineEventClass(alwaysAuthorization);
                if (item.EventClass != EventClass.Authorization)
                {
                    item.Status = LicenceEventStatus.Approved;
                }
                else
                {
                    item.Status = LicenceEventStatus.InReview;
                }
            }

            MicrosoftDynamicsCRMadoxioEvent patchEvent = new MicrosoftDynamicsCRMadoxioEvent();

            patchEvent.CopyValues(item);
            if (!string.IsNullOrEmpty(item.LicenceId) && item.LicenceId != dynamicsEvent._adoxioLicenceValue)
            {
                patchEvent.LicenceODataBind = _dynamicsClient.GetEntityURI("adoxio_licenceses", item.LicenceId);
            }
            try
            {
                _dynamicsClient.Events.Update(id, patchEvent);
            }
            catch (HttpOperationException httpOperationException)
            {
                _logger.LogError(httpOperationException, "Error updating event");
            }

            // Re-fetch event information from Dynamics to bring in updated properties
            dynamicsEvent = _dynamicsClient.GetEventByIdWithChildren(id);
            if (dynamicsEvent == null)
            {
                return(NotFound());
            }

            /* Get current event schedules and delete */
            LicenceEvent viewModelEvent = dynamicsEvent.ToViewModel(_dynamicsClient);

            DeleteEventSchedules(viewModelEvent.Schedules);

            /* Create new event schedules */
            viewModelEvent.Schedules = CreateEventSchedules(item, dynamicsEvent);

            /* Delete current event locations (TUA events only) */
            DeleteEventLocations(viewModelEvent.EventLocations);

            /* Create new event locations (TUA events only) */
            viewModelEvent.EventLocations = CreateEventLocations(item, dynamicsEvent);

            return(new JsonResult(dynamicsEvent.ToViewModel(_dynamicsClient)));
        }