public ActionResult RegistrationDetails(Guid itemId)
        {
            if (!Utilities.IsValidCart())
            {
                return(RedirectToAction("Index", "home"));
            }

            var regAction = SessionManager.CurrentCart.ActionItems[itemId];
            var reg       = (Registration)regAction.ActionObject;

            // update address to current user address
            reg.Address1   = CurrentUser.Address1;
            reg.Address2   = CurrentUser.Address2;
            reg.Locality   = CurrentUser.Locality;
            reg.RegionId   = CurrentUser.RegionId;
            reg.PostalCode = CurrentUser.PostalCode;
            reg.Birthday   = DateTime.Now.AddYears(-30).Date;

            var wave    = _service.GetEventWaveById(reg.EventWaveId);
            int eventId = wave.EventDate.EventId;

            var tShirtSizeList = DirtyGirlExtensions.ConvertToSelectList <TShirtSize>();

            tShirtSizeList.RemoveAt(0);

            var allowSurvivors = (_service.GetSurvivorRegistrationsCountByEventDate(wave.EventDateId) < DirtyGirlServiceConfig.Settings.SurvivorSpots);

            var vm = new vmRegistration_Details
            {
                EventWave                = _service.GetEventWaveById(reg.EventWaveId),
                EventOverview            = _service.GetEventOverviewById(eventId),
                RegionList               = _service.GetRegionsByCountry(DirtyGirlConfig.Settings.DefaultCountryId),
                RegistrationTypeList     = DirtyGirlExtensions.ConvertToSelectList <RegistrationType>(),
                TShirtSizeList           = tShirtSizeList,
                PacketDeliveryOptionList = DirtyGirlExtensions.ConvertToSelectList <RegistrationMaterialsDeliveryOption>(),
                EventLeadList            = _service.GetEventLeads(eventId, true),
                RegistrationDetails      = reg,
                ItemId = itemId,
                survivorSpotsAvailable = allowSurvivors
            };

            return(View(vm));
        }
        public ActionResult RegistrationDetails(vmRegistration_Details model)
        {
            if (!Utilities.IsValidCart())
            {
                return(RedirectToAction("Index", "home"));
            }

            var regAction = SessionManager.CurrentCart.ActionItems[model.ItemId];
            var reg       = (Registration)regAction.ActionObject;

            if (_service.IsDuplicateRegistration(reg.EventWaveId, CurrentUser.UserId,
                                                 model.RegistrationDetails.FirstName, model.RegistrationDetails.LastName))
            {
                ModelState.AddModelError("FirstName",
                                         "You have already registered for this event wave. You may select another wave above, or, if you would like to register another participant for this wave, please enter their name below.");
            }

            var fullName = model.RegistrationDetails.FirstName + model.RegistrationDetails.LastName;

            if (fullName.Replace(" ", "") == model.RegistrationDetails.EmergencyContact.Replace(" ", ""))
            {
                ModelState.AddModelError("EmergencyContact", "Emergency contact cannot be the same as the registrant.");
            }

            EventWave wave = _service.GetEventWaveById(reg.EventWaveId);

            if (model.RegistrationDetails.Birthday.HasValue)
            {
                if (model.RegistrationDetails.Birthday.Value.AddYears(14) > wave.EventDate.DateOfEvent)
                {
                    ModelState.AddModelError("Birthday", "The participant must be 14 years or older to join the event..");
                }
            }
            else
            {
                ModelState.AddModelError("Birthday", "Registrants Birthday is required.");
            }

            model.RegistrationDetails.Address1   = reg.Address1 = CurrentUser.Address1;
            model.RegistrationDetails.Address2   = reg.Address2 = CurrentUser.Address2;
            model.RegistrationDetails.Locality   = reg.Locality = CurrentUser.Locality;
            model.RegistrationDetails.RegionId   = reg.RegionId = CurrentUser.RegionId;
            model.RegistrationDetails.PostalCode = reg.PostalCode = CurrentUser.PostalCode;

            if (ModelState.IsValid)
            {
                reg.AgreeToTerms               = model.RegistrationDetails.AgreeToTerms;
                reg.CartItemId                 = model.RegistrationDetails.CartItemId;
                reg.DateAdded                  = model.RegistrationDetails.DateAdded;
                reg.Email                      = model.RegistrationDetails.Email;
                reg.EmergencyContact           = model.RegistrationDetails.EmergencyContact;
                reg.EmergencyPhone             = model.RegistrationDetails.EmergencyPhone;
                reg.EventLeadId                = model.RegistrationDetails.EventLeadId;
                reg.FirstName                  = model.RegistrationDetails.FirstName;
                reg.Gender                     = model.RegistrationDetails.Gender;
                reg.IsFemale                   = model.RegistrationDetails.IsFemale;
                reg.IsOfAge                    = model.RegistrationDetails.IsOfAge;
                reg.IsThirdPartyRegistration   = model.RegistrationDetails.IsThirdPartyRegistration;
                reg.LastName                   = model.RegistrationDetails.LastName;
                reg.MedicalInformation         = model.RegistrationDetails.MedicalInformation;
                reg.ParentRegistrationId       = model.RegistrationDetails.ParentRegistrationId;
                reg.Phone                      = model.RegistrationDetails.Phone;
                reg.ReferenceAnswer            = model.RegistrationDetails.ReferenceAnswer;
                reg.RegistrationStatus         = RegistrationStatus.Active;
                reg.RegistrationType           = model.RegistrationDetails.RegistrationType;
                reg.SpecialNeeds               = model.RegistrationDetails.SpecialNeeds;
                reg.Birthday                   = model.RegistrationDetails.Birthday.Value.Date;
                reg.TShirtSize                 = model.RegistrationDetails.TShirtSize;
                reg.PacketDeliveryOption       = (model.RegistrationDetails.PacketDeliveryOption.HasValue ? model.RegistrationDetails.PacketDeliveryOption : RegistrationMaterialsDeliveryOption.OnSitePickup);
                reg.UserId                     = CurrentUser.UserId;
                reg.Signature                  = model.RegistrationDetails.Signature;
                reg.IsIAmTheParticipant        = model.RegistrationDetails.IsIAmTheParticipant;
                reg.IsSignatureConsent         = model.RegistrationDetails.IsSignatureConsent;
                reg.AgreeTrademark             = model.RegistrationDetails.AgreeTrademark;
                reg.ConfirmationCode           = model.RegistrationDetails.ConfirmationCode;
                regAction.ActionObject         = reg;
                regAction.ItemReadyForCheckout = true;


                // should check this better...
                if (((int)reg.PacketDeliveryOption.Value == 1))
                {
                    ActionItem shippingFeeItem = _service.CreateShippingFee(model.ItemId, reg.EventWaveId, reg.PacketDeliveryOption);
                    SessionManager.CurrentCart.ActionItems.Add(Guid.NewGuid(), shippingFeeItem);
                }

                if (CheckAddProcessingFee(reg, model.ItemId))
                {
                    ActionItem processingFeeItem = _service.CreateProcessingFee(model.ItemId, reg.EventWaveId,
                                                                                reg.PacketDeliveryOption);
                    SessionManager.CurrentCart.ActionItems.Add(Guid.NewGuid(), processingFeeItem);
                }
                else
                {
                    // check to see if the processing fee is already in the cart.  If so, we know we do not want it, so remove it.
                    RemoveProcessingFee(model.ItemId);
                }
                return(RedirectToAction("checkout", "cart"));
            }



            model.EventWave                = wave;
            model.EventOverview            = _service.GetEventOverviewById(wave.EventDate.EventId);
            model.RegionList               = _service.GetRegionsByCountry(DirtyGirlConfig.Settings.DefaultCountryId);
            model.RegistrationTypeList     = DirtyGirlExtensions.ConvertToSelectList <RegistrationType>();
            model.EventLeadList            = _service.GetEventLeads(wave.EventDate.EventId, true);
            model.PacketDeliveryOptionList = DirtyGirlExtensions.ConvertToSelectList <RegistrationMaterialsDeliveryOption>();
            model.TShirtSizeList           = DirtyGirlExtensions.ConvertToSelectList <TShirtSize>();
            model.TShirtSizeList.RemoveAt(0);

            return(View(model));
        }