Exemple #1
0
        public async Task <ActionResult <AdjustedCamper> > CreateCamper(int portalId, [FromBody] CamperModel camper)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                await ValidateCustomFields(portalId, camper.CustomFields);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            Camper newCamper = await _camperRepository.CreateCamper(portalId, camper);

            if (camper.CouponId != null)
            {
                await _redeemedCouponRepository.RedeemCoupon(camper.CouponId.Value, newCamper.Id);
            }

            await SaveCustomFields(newCamper.Id, camper.CustomFields);

            AdjustedCamper adjustedCamper = await AdjustCamper(newCamper);

            return(Ok(adjustedCamper));
        }
        private async Task <Registration> Register(int portalId, CamperOverrideModel camper, Event dbEvent,
                                                   int?paymentId)
        {
            Camper dbCamper = await _camperRepository.CreateCamper(portalId, camper);

            if (!string.IsNullOrEmpty(camper.Coupon))
            {
                IEnumerable <Coupon> dbCoupons = await _couponRepository.GetCouponsByCode(portalId, camper.Coupon);

                List <Coupon> coupons = dbCoupons.ToList();

                if (coupons.Any())
                {
                    await _redeemedCouponRepository.RedeemCoupon(coupons.First().Id, dbCamper.Id);
                }
            }

            await SaveCustomFields(dbCamper.Id, camper.CustomFields);

            RegistrationModel registrationModel = new RegistrationModel
            {
                Event           = dbEvent,
                EventId         = dbEvent.Id,
                CamperId        = dbCamper.Id,
                IsActive        = true,
                StartingBalance = camper.StartingBalance,
            };

            Registration registration = await _registrationRepository.CreateRegistration(portalId, registrationModel);

            if (paymentId != null)
            {
                await _paymentDonationRepository.AddRegistrationPayment(paymentId.Value, registration.Id);
            }

            return(registration);
        }