Пример #1
0
        public async Task <CourseTemplatesModel> GetCourseTemplates(int?subjectId = null, int?categoryId = null)
        {
            var newToken = await _token.GetNewToken();

            var client = new Client(newToken);

            var lastAppDate = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");
            var startDate   = DateTime.Today.AddDays(1).ToString("yyyy-MM-ddTHH:mm:ssZ");

            var courseTemplateQuery =
                $@"?$select=CourseTemplateId,CourseName,StartTime,EndTime,CourseDescriptionShort&$expand=Categories($select=CategoryId,CategoryName),Subjects($select=SubjectId,SubjectName),Events(
                    $select=AddressName,City,EventId,ParticipantNumberLeft,LastApplicationDate,MaxParticipantNumber,StartDate,EndDate,StatusId,StatusText,NumberOfBookedParticipants;
                    $expand=EventDates($select=StartDate,EndDate);
                    $filter=StatusId ne 3 and 
                    (ParticipantNumberLeft gt 0 or MaxParticipantNumber eq null) and 
                    LastApplicationDate gt {lastAppDate} and StartDate gt {startDate} and HasPublicPriceName eq true)
                &$filter=ShowOnWeb eq true and 
                    Events/any(e1:e1/StatusId ne 3 and 
                        e1/LastApplicationDate gt {lastAppDate} and 
                        e1/StartDate gt {startDate} and 
                        e1/HasPublicPriceName eq true and
                        (e1/ParticipantNumberLeft gt 0 or e1/MaxParticipantNumber eq null)
                    )" +
                (subjectId != null && subjectId > 0 ? $@" and Subjects/any(s:s/SubjectId eq {subjectId})" : "") +
                (categoryId != null && categoryId > 0 ? $@" and Categories/any(c:c/CategoryId eq {categoryId})" : "");

            var courseTemplates = await client.CourseTemplate.GetAsync(courseTemplateQuery);

            return(new CourseTemplatesModel
            {
                CourseTemplatesWithEvents = GetCourseTemplateEvents(courseTemplates.Value),
                Subjects = GetCourseTemplateSubjects(courseTemplates.Value),
                Categories = GetCourseTemplateCategories(courseTemplates.Value)
            });
        }
Пример #2
0
        public async Task <CourseTemplateModel> GetCourseTemplate(int courseTemplateId)
        {
            var newToken = await _token.GetNewToken();

            var client = new Client(newToken);

            var lastAppDate = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");
            var startDate   = DateTime.Today.AddDays(1).ToString("yyyy-MM-ddTHH:mm:ssZ");

            var courseTemplateQuery =
                $@"?$select=CourseDescriptionShort,InternalCourseName,CourseDescription,CourseGoal,CourseName,CourseTemplateId,ImageUrl,TargetGroup&$expand=Events(
                        $select=AddressName,City,EventId,ParticipantNumberLeft,LastApplicationDate,MaxParticipantNumber,StartDate,EndDate,StatusId,StatusText,NumberOfBookedParticipants;
                        $expand=EventDates($select=StartDate,EndDate);
                        $filter=StatusId ne 3 and 
                            (ParticipantNumberLeft gt 0 or MaxParticipantNumber eq null) and 
                            LastApplicationDate gt {lastAppDate} and 
                            StartDate gt {startDate} and HasPublicPriceName eq true)
                    &$filter=ShowOnWeb eq true";

            var courseTemplate = await client.CourseTemplate.GetSingleAsync(courseTemplateId, courseTemplateQuery);

            return(new CourseTemplateModel
            {
                CourseDescriptionShort = courseTemplate.CourseDescriptionShort,
                InternalCourseName = courseTemplate.InternalCourseName,
                CourseDescription = courseTemplate.CourseDescription,
                CourseGoal = courseTemplate.CourseGoal,
                EventCities = CreateEventCitiesList(courseTemplate.Events, courseTemplate.CourseTemplateId ?? 0),
                CourseName = courseTemplate.CourseName,
                CourseTemplateId = courseTemplate.CourseTemplateId ?? 0,
                ImageUrl = courseTemplate.ImageUrl,
                TargetGroup = courseTemplate.TargetGroup
            });
        }
Пример #3
0
        public async Task <InterestRegistrationBasicCreated> CreateInterestReg(InterestRegModel model)
        {
            var newToken = await _token.GetNewToken();

            var client = new Client(newToken);

            try
            {
                var createInterestReg = await client.InterestRegistration.PostBasic(new PostInterestRegistrationBasic
                {
                    CompanyName          = model.CompanyName,
                    CourseTemplateId     = model.CourseTemplateId,
                    Email                = model.Email,
                    FirstName            = model.FirstName,
                    LastName             = model.LastName,
                    Mobile               = model.Mobile,
                    Notes                = model.Notes,
                    NumberOfParticipants = model.PartNr
                });

                return(createInterestReg);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        public async Task <BookModel> GetNewBookModel(int eventId, int courseTemplateId, string backUrl)
        {
            var newToken = await _token.GetNewToken();

            var client = new EduAdminAPIClient.Client(newToken);

            var courseTemplateQuery = "?$select=CourseDescription,CourseTemplateId,RequireCivicRegistrationNumber&" +
                                      "$expand=Events(" +
                                      "$select=EventId,EventName,ParticipantNumberLeft,StartDate,LastApplicationDate;" +
                                      "$expand=" +
                                      "PriceNames(" +
                                      "$select=PriceNameId,PriceNameDescription,Price)," +
                                      "Sessions(" +
                                      "$select=SessionId,StartDate,EndDate,SessionName,InternalSessionName;" +
                                      "$expand=PriceNames($select=PriceNameId,Price)" +
                                      ");" +
                                      $"$filter=EventId eq {eventId})&$filter=ShowOnWeb eq true";

            var courseTemplate = await client.CourseTemplate.GetSingleAsync(courseTemplateId, courseTemplateQuery);

            var currentEvent = courseTemplate?.Events?.FirstOrDefault();

            var lastApplicationDate = currentEvent != null && currentEvent.LastApplicationDate.HasValue ? (DateTime?)currentEvent.LastApplicationDate.Value.DateTime : null;
            var startDate           = currentEvent != null && currentEvent.StartDate.HasValue ? (DateTime?)currentEvent.StartDate.Value.DateTime : null;

            if (currentEvent == null || DateHasPassed(startDate) || DateHasPassed(lastApplicationDate))
            {
                return(new BookModel
                {
                    HasError = true,
                    BackUrl = backUrl
                });
            }

            var questions = await GetBookingQuestions(eventId, client);

            return(new BookModel
            {
                StartDate = startDate,
                LastApplicationDate = lastApplicationDate,
                Description = courseTemplate.CourseDescription,
                BookingQuestions = questions.BookingQuestions,
                EventId = currentEvent?.EventId ?? 0,
                EventName = currentEvent?.EventName,
                FullyBooked = currentEvent?.ParticipantNumberLeft != null && (currentEvent?.ParticipantNumberLeft ?? 0) <= 0,
                CourseTemplateId = courseTemplate.CourseTemplateId ?? 0,
                Customer = CreateEmptyCustomer(),
                RequireCivicRegistrationNumber = courseTemplate.RequireCivicRegistrationNumber ?? false,
                Participants = GetAndSetParticipants(currentEvent, courseTemplate, questions.ParticipantQuestions),
                BackUrl = backUrl
            });
        }
Пример #5
0
        public async Task <EduAdminAPIClient.Models.Token> GetNewToken()
        {
            EduAdminAPIClient.Models.Token token = null;

            try
            {
                token = _cache.Get <EduAdminAPIClient.Models.Token>("_token");
            }
            catch
            {
                // ignored
            }

            if (token != null)
            {
                return(token);
            }

            var client = new EduAdminAPIClient.Client();

            try
            {
                if (Constants.API.userName.Length > 0 && Constants.API.password.Length > 0)
                {
                    token = await client.Authenticate(Constants.API.userName, Constants.API.password);
                }
            }
            catch
            {
                throw new NotImplementedException("The token used is not valid.");
            }

            var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(30));

            _cache.Set("_token", token, cacheEntryOptions);
            return(token);
        }
        public async Task <ActionResult> CreateBooking(CreateBookingModel createBookingModel)
        {
            createBookingModel = CreateBookingModelWithoutInfoQuestions(createBookingModel);

            if (createBookingModel.EventId <= 0)
            {
                throw new Exception(_localizer["AnErrorOccurred"]);
            }

            if (!ModelState.IsValid)
            {
                return(GetJsonResultFromModelStateErrors());
            }

            if (_bookingService.DateHasPassed(createBookingModel.StartDate) || _bookingService.DateHasPassed(createBookingModel.LastApplicationDate))
            {
                ModelState.AddModelError("", _localizer["BookingLastDayPassedError"]);
                return(GetJsonResultFromModelStateErrors());
            }

            var newToken = await _token.GetNewToken();

            var client = new EduAdminAPIClient.Client(newToken);

            var booking = new PostBooking
            {
                Answers       = _questionService.GetBookingAnswers(createBookingModel.BookingQuestions),
                ContactPerson = new PostBookingContactPerson
                {
                    FirstName = createBookingModel.CustomerContact?.FirstName,
                    LastName  = createBookingModel.CustomerContact?.LastName,
                    Email     = createBookingModel.CustomerContact?.Email
                },
                Customer = new PostBookingCustomer
                {
                    CustomerName       = createBookingModel.Customer?.CustomerName,
                    OrganisationNumber = createBookingModel.Customer?.InvoiceOrgnr,
                    Address            = createBookingModel.Customer?.Address1,
                    Zip  = createBookingModel.Customer?.Zip,
                    City = createBookingModel.Customer?.City
                },
                EventId      = createBookingModel.EventId,
                Participants = createBookingModel.Participants?.Select(x => new BookingParticipant
                {
                    Answers   = _questionService.GetBookingAnswers(x.ParticipantQuestions),
                    FirstName = x.FirstName,
                    LastName  = x.LastName,
                    Email     = x.Email,
                    CivicRegistrationNumber = x.CivicRegistrationNumber,
                    PriceNameId             = x.PriceNameId != 0 ? (int?)x.PriceNameId : null,
                    Sessions = x.Sessions?.Where(s => s.Participating).Select(y => new BookingParticipantSession
                    {
                        SessionId   = y.SessionId,
                        PriceNameId = y.PriceNameId
                    }).ToList()
                }).ToList(),
                SendConfirmationEmail = new SendInfoBase
                {
                    SendToParticipants = true
                },
            };

            BookingCreated newBooking;

            try
            {
                newBooking = await client.Booking.PostAsync(booking);
            }
            catch (EduAdminApi.EduAdminException <ForbiddenResponse> ex)
            {
                var errorResult = ex.Result;
                var errorStr    = "";

                foreach (var item in errorResult.Errors)
                {
                    //If multiple errors would exist, separate these
                    if (!string.IsNullOrWhiteSpace(errorStr))
                    {
                        errorStr += "<br />";
                    }

                    switch (item?.ErrorCode ?? 0)
                    {
                    case 40:
                        //No seats left
                        errorStr += _localizer["NotEnoughSeatsLeft"];
                        break;

                    case 45:
                        //Person already booked
                        errorStr += _localizer["BookingContainsBookedParticipants"];
                        break;

                    case 200:
                        //Person exists on overlapping sessions
                        errorStr += _localizer["BookingContainsOverlapPersons"];
                        break;

                    default:
                        errorStr += _localizer["CouldntCreateBookingTryAgain"];
                        break;
                    }
                }

                ModelState.AddModelError("", errorStr);
                return(GetJsonResultFromModelStateErrors());
            }

            return(Json(new CreateBookingResult
            {
                Success = true,
                SuccessRedirectUrl = Url.Action("BookingCreated", "Booking", new { eclID = newBooking.BookingId })
            }));
        }
        private async Task <EventQuestions> GetBookingQuestions(int eventId, EduAdminAPIClient.Client client)
        {
            var eventBookingQuestions = await client.Event.GetBookingQuestionsAsync(eventId, true);

            var bookQuestionValue        = eventBookingQuestions.BookingQuestions;
            var participantQuestionValue = eventBookingQuestions.ParticipantQuestions;

            var bookingQuestions     = new List <Question>();
            var participantQuestions = new List <Question>();

            foreach (var questionBase in bookQuestionValue)
            {
                if (questionBase.GetType() == typeof(EduAdminAPIClient.TextQuestion))
                {
                    AddTextQuestion(bookingQuestions, (EduAdminAPIClient.TextQuestion)questionBase);
                }

                if (questionBase.GetType() == typeof(EduAdminAPIClient.InfoTextQuestion))
                {
                    AddInfotextQuestion(bookingQuestions, (EduAdminAPIClient.InfoTextQuestion)questionBase);
                }

                if (questionBase.GetType() == typeof(EduAdminAPIClient.CheckboxQuestion))
                {
                    AddCheckBoxQuestion(bookingQuestions, (EduAdminAPIClient.CheckboxQuestion)questionBase);
                }

                if (questionBase.GetType() == typeof(EduAdminAPIClient.DropdownQuestion))
                {
                    AddDropDownListQuestion(bookingQuestions, (EduAdminAPIClient.DropdownQuestion)questionBase);
                }

                if (questionBase.GetType() == typeof(EduAdminAPIClient.NumberQuestion))
                {
                    AddNumberQuestion(bookingQuestions, (EduAdminAPIClient.NumberQuestion)questionBase);
                }

                if (questionBase.GetType() == typeof(EduAdminAPIClient.RadioQuestion))
                {
                    AddRadioButtonQuestion(bookingQuestions, (EduAdminAPIClient.RadioQuestion)questionBase);
                }
            }

            foreach (var questionBase in participantQuestionValue)
            {
                if (questionBase.GetType() == typeof(EduAdminAPIClient.TextQuestion))
                {
                    AddTextQuestion(participantQuestions, (EduAdminAPIClient.TextQuestion)questionBase);
                }

                if (questionBase.GetType() == typeof(EduAdminAPIClient.InfoTextQuestion))
                {
                    AddInfotextQuestion(participantQuestions, (EduAdminAPIClient.InfoTextQuestion)questionBase);
                }

                if (questionBase.GetType() == typeof(EduAdminAPIClient.CheckboxQuestion))
                {
                    AddCheckBoxQuestion(participantQuestions, (EduAdminAPIClient.CheckboxQuestion)questionBase);
                }

                if (questionBase.GetType() == typeof(EduAdminAPIClient.DropdownQuestion))
                {
                    AddDropDownListQuestion(participantQuestions, (EduAdminAPIClient.DropdownQuestion)questionBase);
                }

                if (questionBase.GetType() == typeof(EduAdminAPIClient.NumberQuestion))
                {
                    AddNumberQuestion(participantQuestions, (EduAdminAPIClient.NumberQuestion)questionBase);
                }

                if (questionBase.GetType() == typeof(EduAdminAPIClient.RadioQuestion))
                {
                    AddRadioButtonQuestion(participantQuestions, (EduAdminAPIClient.RadioQuestion)questionBase);
                }
            }

            return(new EventQuestions
            {
                BookingQuestions = bookingQuestions,
                ParticipantQuestions = participantQuestions
            });
        }