コード例 #1
0
        public async System.Threading.Tasks.Task TestList()
        {
            string firstName  = "firstName";
            string secondName = "secondName";

            var loginUser = randomNewUserName("NewLoginUser", 6);
            var strId     = await LoginAndRegisterAsNewUser(loginUser);

            // C - Create first
            var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service);

            ViewModels.LicenceEvent viewmodel_adoxio_event = new ViewModels.LicenceEvent()
            {
                Name = firstName
            };

            string jsonString = JsonConvert.SerializeObject(viewmodel_adoxio_event);

            request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json");

            var response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            // Create second
            request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service);

            ViewModels.LicenceEvent viewmodel_adoxio_event2 = new ViewModels.LicenceEvent()
            {
                Name = secondName
            };

            jsonString = JsonConvert.SerializeObject(viewmodel_adoxio_event2);

            request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json");

            var response2 = await _client.SendAsync(request);

            response2.EnsureSuccessStatusCode();

            // List

            var listRequest  = new HttpRequestMessage(HttpMethod.Get, "/api/" + service);
            var listResponse = await _client.SendAsync(listRequest);

            listResponse.EnsureSuccessStatusCode();

            jsonString = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();

            await LogoutAndCleanupTestUser(strId);
        }
コード例 #2
0
        // Converts a dynamics entity into a view model
        public static ViewModels.LicenceEvent ToViewModel(this MicrosoftDynamicsCRMadoxioEvent item, IDynamicsClient dynamicsClient)
        {
            ViewModels.LicenceEvent result = null;
            if (item != null)
            {
                result = new ViewModels.LicenceEvent();
                if (item.AdoxioEventid != null)
                {
                    result.Id = item.AdoxioEventid;
                }
                result.Status           = (LicenceEventStatus?)item.Statuscode;
                result.Name             = item.AdoxioName;
                result.StartDate        = item.AdoxioStartdate?.Date;
                result.EndDate          = item.AdoxioEnddate?.Date;
                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;
            }

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

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

            return(result);
        }
コード例 #3
0
        // Converts a view model into a dynamics entity
        public static void CopyValues(this MicrosoftDynamicsCRMadoxioEvent to, ViewModels.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.AdoxioStartdate = 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.AdoxioEnddate = 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;
        }
コード例 #4
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));
        }
コード例 #5
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());
        }
コード例 #6
0
        public async System.Threading.Tasks.Task TestCRUD()
        {
            string venue        = "Venue Description";
            string changedVenue = "New Venue Description";

            var loginUser = randomNewUserName("NewLoginUser", 6);
            var strId     = await LoginAndRegisterAsNewUser(loginUser);

            // C - Create
            var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service);

            ViewModels.LicenceEvent viewmodel_adoxio_event = new ViewModels.LicenceEvent()
            {
                VenueDescription = venue
            };

            string jsonString = JsonConvert.SerializeObject(viewmodel_adoxio_event);

            request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json");

            var response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            // parse as JSON.
            jsonString = await response.Content.ReadAsStringAsync();

            ViewModels.LicenceEvent responseViewModel = JsonConvert.DeserializeObject <ViewModels.LicenceEvent>(jsonString);

            Assert.Equal(venue, responseViewModel.VenueDescription);
            Guid id = new Guid(responseViewModel.Id);

            // R - Read

            request  = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id);
            response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            jsonString = await response.Content.ReadAsStringAsync();

            responseViewModel = JsonConvert.DeserializeObject <ViewModels.LicenceEvent>(jsonString);
            Assert.Equal(venue, responseViewModel.VenueDescription);

            // U - Update
            ViewModels.LicenceEvent patchModel = new ViewModels.LicenceEvent()
            {
                Id = id.ToString(),
                VenueDescription = changedVenue
            };

            request = new HttpRequestMessage(HttpMethod.Put, "/api/" + service + "/" + id)
            {
                Content = new StringContent(JsonConvert.SerializeObject(patchModel), Encoding.UTF8, "application/json")
            };
            response = await _client.SendAsync(request);

            jsonString = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();

            // verify that the update persisted.

            request  = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id);
            response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            jsonString = await response.Content.ReadAsStringAsync();

            responseViewModel = JsonConvert.DeserializeObject <ViewModels.LicenceEvent>(jsonString);
            Assert.Equal(responseViewModel.VenueDescription, changedVenue);

            // D - Delete

            request  = new HttpRequestMessage(HttpMethod.Delete, "/api/" + service + "/" + id);
            response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            // second delete should return a 404.
            request  = new HttpRequestMessage(HttpMethod.Delete, "/api/" + service + "/" + id);
            response = await _client.SendAsync(request);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);

            // should get a 404 if we try a get now.
            request  = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id);
            response = await _client.SendAsync(request);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);

            await LogoutAndCleanupTestUser(strId);
        }
コード例 #7
0
        public async System.Threading.Tasks.Task TestDates()
        {
            string venue = "Venue Description";

            // January 1, 1970 - 00:00 with Pacific time.
            // note that this field expects no time.

            DateTimeOffset startDate = DateTimeOffset.Parse("01/01/1970 00:00 -8:00");
            DateTimeOffset endDate   = DateTimeOffset.Parse("02/02/1970 00:00 -8:00");
            List <ViewModels.LicenceEventSchedule> schedule = new List <ViewModels.LicenceEventSchedule>();

            schedule.Add(new ViewModels.LicenceEventSchedule()
            {
                EventStartDateTime   = DateTimeOffset.Parse("01/01/1970 09:00 -8:00"),
                EventEndDateTime     = DateTimeOffset.Parse("02/02/1970 17:00 -8:00"),
                ServiceStartDateTime = DateTimeOffset.Parse("01/01/1970 09:00 -8:00"),
                ServiceEndDateTime   = DateTimeOffset.Parse("02/02/1970 17:00 -8:00")
            });

            var loginUser = randomNewUserName("NewLoginUser", 6);
            var strId     = await LoginAndRegisterAsNewUser(loginUser);

            // C - Create
            var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service);

            ViewModels.LicenceEvent viewmodel_adoxio_event = new ViewModels.LicenceEvent()
            {
                VenueDescription = venue,
                StartDate        = startDate,
                EndDate          = endDate,
                Schedules        = schedule
            };

            string jsonString = JsonConvert.SerializeObject(viewmodel_adoxio_event);

            request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json");

            var response = await _client.SendAsync(request);

            jsonString = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();

            viewmodel_adoxio_event = JsonConvert.DeserializeObject <ViewModels.LicenceEvent>(jsonString);

            Assert.Equal(((DateTimeOffset)viewmodel_adoxio_event.StartDate).Month, startDate.Month);
            Assert.Equal(((DateTimeOffset)viewmodel_adoxio_event.StartDate).Day, startDate.Day);
            Assert.Equal(((DateTimeOffset)viewmodel_adoxio_event.StartDate).Year, startDate.Year);
            Assert.Equal(((DateTimeOffset)viewmodel_adoxio_event.EndDate).Month, endDate.Month);
            Assert.Equal(((DateTimeOffset)viewmodel_adoxio_event.EndDate).Day, endDate.Day);
            Assert.Equal(((DateTimeOffset)viewmodel_adoxio_event.EndDate).Year, endDate.Year);



            // R -Read
            request  = new HttpRequestMessage(HttpMethod.Get, $"/api/{service}/{viewmodel_adoxio_event.Id}");
            response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            jsonString = await response.Content.ReadAsStringAsync();

            viewmodel_adoxio_event = JsonConvert.DeserializeObject <ViewModels.LicenceEvent>(jsonString);
            Assert.NotNull(viewmodel_adoxio_event?.Id);

            Assert.Equal(startDate.Month, ((DateTimeOffset)viewmodel_adoxio_event.StartDate).Month);
            Assert.Equal(startDate.Year, ((DateTimeOffset)viewmodel_adoxio_event.StartDate).Year);
            Assert.Equal(startDate.Day, ((DateTimeOffset)viewmodel_adoxio_event.StartDate).Day);

            Assert.Equal(endDate.Month, ((DateTimeOffset)viewmodel_adoxio_event.EndDate).Month);
            Assert.Equal(endDate.Year, ((DateTimeOffset)viewmodel_adoxio_event.EndDate).Year);
            Assert.Equal(endDate.Day, ((DateTimeOffset)viewmodel_adoxio_event.EndDate).Day);

            // D - Delete

            request  = new HttpRequestMessage(HttpMethod.Delete, $"/api/{service}/" + viewmodel_adoxio_event.Id);
            response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            // second delete should return a 404.
            request  = new HttpRequestMessage(HttpMethod.Delete, $"/api/{service}/" + viewmodel_adoxio_event.Id);
            response = await _client.SendAsync(request);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);


            // should get a 404 if we try a get now.
            request  = new HttpRequestMessage(HttpMethod.Get, $"/api/{service}/" + viewmodel_adoxio_event.Id);
            response = await _client.SendAsync(request);

            jsonString = await response.Content.ReadAsStringAsync();

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);

            await Logout();
        }