Esempio n. 1
0
        public ActionResult DownloadiCal(int eventSlotId)
        {
            var eventTypes = _dataTypeProvider.GetEventTypes();
            var eventSlot  = _eventSlotRepository.GetById(eventSlotId);

            eventSlot.EventTypeName = eventTypes.SingleOrDefault(et => et.Id == eventSlot.EventTypeId)?.Name;

            var calendar = new Calendar();

            calendar.Events.Add(new CalendarEvent
            {
                Class   = "PUBLIC",
                Summary = eventSlot.EventTypeName, //TODO - Make this a better summary
                Created = new CalDateTime(DateTime.Now),
                //Description = res.Details,
                Start = new CalDateTime(eventSlot.Date),
                //End = new CalDateTime(Convert.ToDateTime(res.EndDate)),
                Sequence = 0,
                Uid      = Guid.NewGuid().ToString(),
                //Location = res.Location,
            });

            var serializer         = new CalendarSerializer(new SerializationContext());
            var serializedCalendar = serializer.SerializeToString(calendar);
            var bytesCalendar      = Encoding.UTF8.GetBytes(serializedCalendar);

            return(File(bytesCalendar, "text/calendar", "event.ics"));
        }
Esempio n. 2
0
        public EventResponse BookEvent(BookEventRequest model)
        {
            var response = new EventResponse();
            var member   = _memberProvider.GetLoggedInMember();

            if (member == null)
            {
                response.Error = "Unable to find logged in member record.";
                return(response);
            }

            var  membershipExpiry    = member.GetValue <DateTime>(MemberProperty.MembershipExpiry);
            bool isMembershipExpired = membershipExpiry < DateTime.Now;

            if (isMembershipExpired)
            {
                response.Error = "Your membership has expired, please renew your membership before booking any events.";
                return(response);
            }

            var memberType = member.GetValue <MembershipTypeEnum>(MemberProperty.membershipType);
            var isGuest    = memberType == MembershipTypeEnum.Guest;

            if (string.Equals(model.EventTypeName, "Open Water Swim", StringComparison.OrdinalIgnoreCase) && !isGuest && !member.GetValue <bool>(MemberProperty.OpenWaterIndemnityAcceptance))
            {
                response.Error = "You need to signup for open water swimming (on your member details page) before you can book onto open water swim sessions.";
                return(response);
            }

            if (string.Equals(model.EventTypeName, "Pool Swim", StringComparison.OrdinalIgnoreCase) && !CanBookPoolSwim(member, model.EventSlotId))
            {
                response.Error = "You need to signup for swim subs (on your member details page) before you can book onto pool swim sessions.";
                return(response);
            }

            if (member.GetValue <int>(MemberProperty.TrainingCredits) < model.Cost)
            {
                response.Error = "You do not have enough training credits to book that event.";
                return(response);
            }

            var eventSlot = _eventSlotRepository.GetById(model.EventSlotId);

            if (!eventSlot.HasSpace)
            {
                response.Error = "There is no space remaining on that training slot.";
                return(response);
            }

            if (eventSlot.EventParticipants.Any(ep => ep.MemberId == member.Id))
            {
                response.Error = "You are already booked onto that event.";
                return(response);
            }

            var eventParticipant = new EventParticipant()
            {
                EventSlotId  = model.EventSlotId,
                AmountPaid   = model.Cost,
                MemberId     = member.Id,
                RaceDistance = string.IsNullOrEmpty(model.RaceDistance) ? null : model.RaceDistance
            };

            //Debit cost from members credits
            var credits = member.GetValue <int>(MemberProperty.TrainingCredits);

            credits = credits - model.Cost;
            member.SetValue(MemberProperty.TrainingCredits, credits);
            Services.MemberService.Save(member);

            eventParticipant = _eventParticipantRepository.Create(eventParticipant);
            Logger.Info(typeof(EventController), $"New event slot booking - Member: {member.Name} , Event: {model.EventTypeName} on {eventSlot.Date.ToString("dd/MM/yyyy")} for £{model.Cost}.");

            return(response);
        }