public ServiceResult CreateTeam(Team team, int registrationId) { ServiceResult result = new ServiceResult(); try { team.Name = team.Name.Trim(); team.DateAdded = DateTime.Now; if (ValidateTeam(team, result)) { team.Code = GenerateTeamCode(team.EventId); _repository.Teams.Create(team); var reg = _repository.Registrations.Find(x => x.RegistrationId == registrationId); reg.Team = team; _repository.Registrations.Update(reg); if (!_sharedRepository) _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(ex.Message); } return result; }
public ServiceResult ChangeTeamName(int teamId, string newTeamName) { ServiceResult result = new ServiceResult(); try { var team = this.GetTeamById(teamId); team.Name = newTeamName; _repository.Teams.Update(team); _repository.SaveChanges(); } catch (Exception ex) { result.AddServiceError(ex.Message); } return result; }
public ServiceResult RemoveEventLead(int eventLeadId) { var result = new ServiceResult(); try { var eventLeadToDelete = _repository.EventLeads.Find(x => x.EventLeadId == eventLeadId); _repository.EventLeads.Delete(eventLeadToDelete); if (!_sharedRepository) _repository.SaveChanges(); } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult CreateRedemptionCode(RedemptionCode redemptionCode) { var result = new ServiceResult(); try { _repository.RedemptionCodes.Create(redemptionCode); if (!_sharedRepository) _repository.SaveChanges(); } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult CreateEventLead(EventLead eventLead) { var result = new ServiceResult(); try { if (ValidateEventLead(eventLead, result)) { _repository.EventLeads.Create(eventLead); if (!_sharedRepository) _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult CreateCoupon(Coupon coupon) { var result = new ServiceResult(); try { if (ValidateCoupon(coupon, result)) { _repository.Coupons.Create(coupon); if (!_sharedRepository) _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult UpdateRegistration(Registration r) { var result = new ServiceResult(); try { var target = _repository.Registrations.Find(x => x.RegistrationId == r.RegistrationId); if (ValidateRegistration(r, result)) { target.Address1 = r.Address1; target.Address2 = r.Address2; target.AgreeToTerms = r.AgreeToTerms; target.AgreeTrademark = r.AgreeTrademark; target.Birthday = r.Birthday; target.CartItemId = r.CartItemId; target.Email = r.Email; target.EmergencyContact = r.EmergencyContact; target.EmergencyPhone = r.EmergencyPhone; target.EventLeadId = r.EventLeadId; target.EventWaveId = r.EventWaveId; target.FirstName = r.FirstName; target.Gender = r.Gender; target.IsFemale = r.IsFemale; target.IsOfAge = r.IsOfAge; target.IsThirdPartyRegistration = r.IsThirdPartyRegistration; target.LastName = r.LastName; target.Locality = r.Locality; target.MedicalInformation = r.MedicalInformation; target.ParentRegistrationId = r.ParentRegistrationId; target.Phone = r.Phone; target.PostalCode = r.PostalCode; target.PacketDeliveryOption = r.PacketDeliveryOption; target.ReferenceAnswer = r.ReferenceAnswer; target.RegionId = r.RegionId; target.RegistrationStatus = r.RegistrationStatus; target.RegistrationType = r.RegistrationType; target.SpecialNeeds = r.SpecialNeeds; target.TShirtSize = r.TShirtSize; target.TeamId = r.TeamId; target.UserId = r.UserId; target.DateUpdated = DateTime.Now; target.ConfirmationCode = r.ConfirmationCode; if (!_sharedRepository) _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult GenerateTempTeam(Team newTeam) { var result = new ServiceResult(); try { ITeamService teamService = new TeamService(_repository); if (!teamService.CheckTeamNameForDirtyWords(newTeam.Name)) { result.AddServiceError("TeamName", "Team name contains a naughty word."); } else { if (teamService.CheckTeamNameAvailability(newTeam.EventId, newTeam.Name)) newTeam.Code = teamService.GenerateTeamCode(newTeam.EventId); else result.AddServiceError("TeamName", "Team name is already taken for this event."); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult CreateNewRegistration(Registration r) { var result = new ServiceResult(); try { if (ValidateRegistration(r, result)) { _repository.Registrations.Create(r); if (!_sharedRepository) _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult UpdateEventWave(EventWave ew) { var result = new ServiceResult(); try { if (ValidateEventWave(ew, result)) { EventWave updateWave = _repository.EventWaves.Find(x => x.EventWaveId == ew.EventWaveId); updateWave.StartTime = ew.StartTime; updateWave.EndTime = ew.EndTime; updateWave.IsActive = ew.IsActive; updateWave.MaxRegistrants = ew.MaxRegistrants; _repository.EventWaves.Update(updateWave); if (!_sharedRepository) _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult UpdateEventLead(EventLead eventLead) { var result = new ServiceResult(); try { if (ValidateEventLead(eventLead, result)) { EventLead updateLead = _repository.EventLeads.Find(x => x.EventLeadId == eventLead.EventLeadId); updateLead.EventLeadTypeId = eventLead.EventLeadTypeId; updateLead.DisplayText = eventLead.DisplayText; updateLead.EventId = eventLead.EventId.HasValue ? eventLead.EventId : null; updateLead.Title = eventLead.Title; if (!_sharedRepository) _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult UpdateEventDate(EventDate ed) { var result = new ServiceResult(); try { if (ValidateEventDate(ed, result)) { EventDate updateDate = _repository.EventDates.Find(x => x.EventDateId == ed.EventDateId); updateDate.DateOfEvent = ed.DateOfEvent; foreach (EventWave w in updateDate.EventWaves) { w.StartTime = new DateTime(ed.DateOfEvent.Year, ed.DateOfEvent.Month, ed.DateOfEvent.Day, w.StartTime.Hour, w.StartTime.Minute, w.StartTime.Second); w.EndTime = new DateTime(ed.DateOfEvent.Year, ed.DateOfEvent.Month, ed.DateOfEvent.Day, w.EndTime.Hour, w.EndTime.Minute, w.EndTime.Second); } _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult ProcessCart(CartCheckOut checkOutDetails, SessionCart tempCart, int userId) { ServiceResult result = new ServiceResult(); if (checkOutDetails != null && checkOutDetails.CartSummary != null && checkOutDetails.CartSummary.TotalCost > 0) { DateTime expired = new DateTime(); expired.AddYears(checkOutDetails.ExpirationYear); expired.AddMonths(checkOutDetails.ExpirationMonth); if (DateTime.Now.CompareTo(expired) < 0) result.AddServiceError("This credit card is expired"); Regex rg = new Regex(@"^[a-zA-Z].*$"); if (string.IsNullOrWhiteSpace(checkOutDetails.CardHolderFirstname)) { result.AddServiceError("Cardholder first name is required."); } else if (!rg.IsMatch(checkOutDetails.CardHolderFirstname)) { result.AddServiceError("Cardholder first name is invalid."); } if (string.IsNullOrWhiteSpace(checkOutDetails.CardHolderLastname)) { result.AddServiceError("Cardholder last name is required."); } else if (!rg.IsMatch(checkOutDetails.CardHolderLastname)) { result.AddServiceError("Cardholder last name is invalid."); } } if (result.GetServiceErrors().Count > 0) { return result; } try { CartSummary summary = GenerateCartSummary(tempCart); string transactionId = string.Empty; CartType cartType; if (summary.TotalCost == 0) { transactionId = GenerateCartCode(); cartType = CartType.Free; } else { IGatewayResponse payment; payment = ChargeConsumer(checkOutDetails, summary); if (payment.Approved) { transactionId = payment.TransactionID; cartType = CartType.Standard; } else { switch (int.Parse(payment.ResponseCode)) { case 2: result.AddServiceError("This Card has been declined."); break; case 3: result.AddServiceError(payment.Message); break; default: result.AddServiceError("Card Error"); break; } return result; } } if (!SaveCart(tempCart, summary, userId, transactionId, cartType)) result.AddServiceError("An error occured saving the shopping cart"); } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
protected bool ValidateCoupon(Coupon couponToValidate, ServiceResult serviceResult) { if (couponToValidate.EndDateTime < couponToValidate.StartDateTime) serviceResult.AddServiceError("EndDateTime", "The effective end date must be after the effective start date."); if (couponToValidate.Value <= 0) serviceResult.AddServiceError("Value", "Value must be positive."); if (couponToValidate.MaxRegistrantCount <= 0) serviceResult.AddServiceError("MaxRegistrantCount", "Max registrant count must be positive or empty"); if (_repository.DiscountItems.Filter(x => x.DiscountItemId != couponToValidate.DiscountItemId && x.Code.ToUpper() == couponToValidate.Code.ToUpper()).Any()) serviceResult.AddServiceError("Code", "The code you entered is already in use by another discount."); // does not need to be associated with an event null == all events //if (couponToValidate.CouponType == CouponType.Registration && !couponToValidate.EventId.HasValue) // serviceResult.AddServiceError("EventId", "Registration coupons must be associated to an event."); return serviceResult.Success; }
public ServiceResult ValidateRedemptionCodeForUserId(string code, int userId) { ServiceResult result = new ServiceResult(); try { //User user = _repository.Users.Find(x => x.UserId == userId); RedemptionCode redemptionCode = _repository.RedemptionCodes.Find(x => x.Code.ToLower() == code.ToLower()); if (redemptionCode != null) { if (redemptionCode.ResultingRegistrationId == null) { if (redemptionCode.RedemptionCodeType == RedemptionCodeType.Transfer && !(redemptionCode.DateAdded >= DateTime.Now.AddDays(-DirtyGirlServiceConfig.Settings.MaxTransferHeldDays))) { redemptionCode.GeneratingRegistration.RegistrationStatus = RegistrationStatus.Cancelled; redemptionCode.RedemptionCodeType = RedemptionCodeType.StraightValue; redemptionCode.GeneratingRegistration.DateUpdated = DateTime.Now; if (!_sharedRepository) _repository.SaveChanges(); } else if (redemptionCode.RedemptionCodeType == RedemptionCodeType.StraightValue && redemptionCode.GeneratingRegistration.UserId != userId) { result.AddServiceError("This redemption code is expired or doesn't belong to you."); } } else result.AddServiceError("This code has already been used."); } else result.AddServiceError("Discount does not exist."); } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult RemoveEventWave(int eventWaveId) { var result = new ServiceResult(); try { EventWave waveToDelete = _repository.EventWaves.Find(x => x.EventWaveId == eventWaveId); if (CanRemoveEventWave(waveToDelete, result)) { _repository.EventWaves.Delete(waveToDelete); if (!_sharedRepository) _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult UpdateEvent(Event e) { var result = new ServiceResult(); try { if (ValidateEvent(e)) { _repository.Events.Update(e); } if (!_sharedRepository) _repository.SaveChanges(); } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
private bool ValidateEventDate(EventDate dateToValidate, ServiceResult result) { if (dateToValidate.DateOfEvent.Date < DateTime.Now.Date) result.AddServiceError("DateOfEvent", "You can not add an event date that is in the past"); else { if ( _repository.EventDates.Find( x => dateToValidate.EventDateId != x.EventDateId && dateToValidate.DateOfEvent == x.DateOfEvent && dateToValidate.EventId == x.EventId) != null) result.AddServiceError("DateOfEvent", "This date is already attached to this event."); } return result.Success; }
public ServiceResult UpdateEventFee(EventFee fee) { var result = new ServiceResult(); try { if (ValidateEventFee(fee, result)) { EventFee updateFee = _repository.EventFees.Find(x => x.PurchaseItemId == fee.PurchaseItemId); updateFee.EffectiveDate = fee.EffectiveDate; updateFee.Cost = fee.Cost; if (!_sharedRepository) _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult CreateEventSponsor(EventSponsor sponsor) { var result = new ServiceResult(); try { if (ValidateSponsor(sponsor, result)) { _repository.EventSponsors.Create(sponsor); _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult UpdateEventSponsor(EventSponsor sponsor) { var result = new ServiceResult(); try { if (ValidateSponsor(sponsor, result)) { EventSponsor updateSponsor = _repository.EventSponsors.Find(x => x.EventSponsorId == sponsor.EventSponsorId); updateSponsor.SponsorName = sponsor.SponsorName; updateSponsor.Description = sponsor.Description; _repository.EventSponsors.Update(updateSponsor); _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult GenerateEventDate(int eventId, DateTime eventDate, DateTime startTime, DateTime endTime, int duration, int maxRegistrants) { var result = new ServiceResult(); try { var newDate = new EventDate {EventId = eventId, DateOfEvent = eventDate, IsActive = true}; if (ValidateEventDate(newDate, result)) { _repository.EventDates.Create(newDate); DateTime newWaveStartTime = startTime; while (newWaveStartTime.TimeOfDay < endTime.TimeOfDay) { var newWave = new EventWave { EventDateId = newDate.EventDateId, StartTime = new DateTime(eventDate.Year, eventDate.Month, eventDate.Day, newWaveStartTime.Hour, newWaveStartTime.Minute, newWaveStartTime.Second) }; newWave.EndTime = newWave.StartTime.AddMinutes(duration - 1); newWave.IsActive = true; newWave.MaxRegistrants = maxRegistrants; newWaveStartTime = newWaveStartTime.AddMinutes(duration); _repository.EventWaves.Create(newWave); } if (!_sharedRepository) _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult ChangeWave(int registrationId, int eventWaveId) { var result = new ServiceResult(); try { Registration existingReg = _repository.Registrations.Find(x => x.RegistrationId == registrationId); int eventId = existingReg.EventWave.EventDate.EventId; int newEventId = GetEventWaveById(eventWaveId).EventDate.EventId; if (existingReg.TeamId != null && eventId != newEventId) existingReg.TeamId = null; existingReg.EventWaveId = eventWaveId; existingReg.DateUpdated = DateTime.Now; if (!_sharedRepository) _repository.SaveChanges(); } catch(Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult CreateEventByTemplate(CreateNewEvent newEvent) { var result = new ServiceResult(); try { EventTemplate template = GetEventTemplateById(newEvent.SelectedTemplateId); var e = new Event { GeneralLocality = newEvent.GeneralLocality, RegionId = newEvent.RegionId, Place = template.DefaultPlaceName, IsActive = false }; int registrationTimeOffset = DirtyGirlServiceConfig.Settings.RegistrationCutoffHours * -1; e.RegistrationCutoff = newEvent.EventDate.AddHours(registrationTimeOffset); int emailPacketOffset = DirtyGirlServiceConfig.Settings.EmailPacketCutoffDays * -1; e.EmailCutoff = newEvent.EventDate.AddDays(emailPacketOffset); ServiceResult saveEventResult = CreateEvent(e); ServiceResult generateDateResult = GenerateEventDate(e.EventId, newEvent.EventDate, template.StartTime, template.EndTime, template.WaveDuration, template.MaxRegistrantsPerWave); var feeResult = new ServiceResult(); var rfee = new EventFee { EventId = e.EventId, EffectiveDate = DateTime.Now.Date, Cost = template.DefaultRegistrationCost, EventFeeType = EventFeeType.Registration, Discountable = true, Taxable = true }; var tFee = new EventFee { EventId = e.EventId, EffectiveDate = DateTime.Now.Date, Cost = template.DefaultTransferFeeCost, EventFeeType= EventFeeType.Transfer, Discountable = false, Taxable = false }; var chFee = new EventFee { EventId = e.EventId, EffectiveDate = DateTime.Now.Date, Cost = template.DefaultChangeFeeCost, EventFeeType = EventFeeType.ChangeEvent, Discountable = false, Taxable = false }; var cfee = new EventFee { EventId = e.EventId, EffectiveDate = DateTime.Now.Date, Cost = template.DefaultCancellationFeeCost, EventFeeType = EventFeeType.Cancellation, Discountable = false, Taxable = false }; var pfee = new EventFee { EventId = e.EventId, EffectiveDate = DateTime.Now.Date, Cost = template.DefaultProcessingFeeCost, EventFeeType = EventFeeType.ProcessingFee, Discountable = false, Taxable = false }; var sfee = new EventFee { EventId = e.EventId, EffectiveDate = DateTime.Now.Date, Cost = template.DefaultShippingFeeCost, EventFeeType = EventFeeType.Shipping, Discountable = false, Taxable = false }; CreateEventFee(rfee); CreateEventFee(tFee); CreateEventFee(chFee); CreateEventFee(cfee); CreateEventFee(sfee); CreateEventFee(pfee); foreach (EventTemplate_PayScale ps in template.PayScales) { var eventStart = newEvent.EventDate; eventStart = newEvent.EventDate.AddDays(-1*ps.DaysOut); // for registrations, if (ps.EventFeeType == EventFeeType.Registration) { while (eventStart.DayOfWeek != DayOfWeek.Wednesday) eventStart = eventStart.AddDays(1); } var newFee = new EventFee { EventId = e.EventId, EffectiveDate = eventStart.Date, Cost = ps.Cost, EventFeeType = ps.EventFeeType, Taxable = ps.Taxable, Discountable = ps.Discountable }; feeResult = CreateEventFee(newFee); if (!feeResult.Success) break; } if (saveEventResult.Success && generateDateResult.Success && feeResult.Success) { _repository.SaveChanges(); newEvent.EventId = e.EventId; } else result.AddServiceError("An Error Occured Creating this Event"); } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult CreateNewRegistration(Registration r, int? redemtpionId) { var result = new ServiceResult(); try { result = CreateNewRegistration(r); if (result.Success) { //Check to see if the discount id being passed in is a redemption code, if it is, update it. var code = _repository.RedemptionCodes.Find(x => x.DiscountItemId == redemtpionId); if (code != null) { code.GeneratingRegistration.RegistrationStatus = code.RedemptionCodeType == RedemptionCodeType.Transfer ? RegistrationStatus.Transferred : RegistrationStatus.Cancelled; code.ResultingRegistrationId = r.RegistrationId; r.ParentRegistrationId = code.GeneratingRegistrationId; if (!_sharedRepository) _repository.SaveChanges(); } } } catch(Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult RemoveEventDate(int eventDateId) { var result = new ServiceResult(); try { EventDate dateToDelete = _repository.EventDates.Find(x => x.EventDateId == eventDateId); List<int> waveIds = dateToDelete.EventWaves.Select(x => x.EventWaveId).ToList(); foreach (int waveId in waveIds) { EventWave wave = dateToDelete.EventWaves.Single(x => x.EventWaveId == waveId); if (CanRemoveEventWave(wave, result)) _repository.EventWaves.Delete(wave); } if (result.Success && CanRemoveEventDate(dateToDelete, result)) { _repository.EventDates.Delete(dateToDelete); _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult Save() { var result = new ServiceResult(); try { _repository.SaveChanges(); } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult RemoveEventSponsor(int sponsorId) { var result = new ServiceResult(); try { EventSponsor sponsorToDelete = _repository.EventSponsors.Find(x => x.EventSponsorId == sponsorId); if (CanRemoveSponsor(sponsorToDelete, result)) { _repository.EventSponsors.Delete(sponsorToDelete); _repository.SaveChanges(); } } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult ChangeEvent(int registrationId, int eventWaveId, int? cartItemId, string confirmationCode) { var result = new ServiceResult(); try { Registration existingReg = _repository.Registrations.Find(x => x.RegistrationId == registrationId); existingReg.RegistrationStatus = RegistrationStatus.Changed; existingReg.DateUpdated = DateTime.Now; var newReg = new Registration { EventWaveId = eventWaveId, RegistrationStatus = RegistrationStatus.Active, RegistrationType = existingReg.RegistrationType, ParentRegistrationId = existingReg.RegistrationId, FirstName = existingReg.FirstName, LastName = existingReg.LastName, Address1 = existingReg.Address1, Address2 = existingReg.Address2, Locality = existingReg.Locality, RegionId = existingReg.RegionId, PostalCode = existingReg.PostalCode, PacketDeliveryOption = existingReg.PacketDeliveryOption, Email = existingReg.Email, Phone = existingReg.Phone, EmergencyContact = existingReg.EmergencyContact, EmergencyPhone = existingReg.EmergencyPhone, SpecialNeeds = existingReg.SpecialNeeds, TShirtSize = existingReg.TShirtSize, Gender = existingReg.Gender, UserId = existingReg.UserId, CartItemId = cartItemId, AgreeToTerms = existingReg.AgreeToTerms, AgreeTrademark = existingReg.AgreeTrademark, IsFemale = existingReg.IsFemale, IsOfAge = existingReg.IsOfAge, EventLeadId = existingReg.EventLeadId, IsSignatureConsent = existingReg.IsSignatureConsent, IsThirdPartyRegistration = existingReg.IsThirdPartyRegistration, Signature = existingReg.Signature, Birthday = existingReg.Birthday, IsIAmTheParticipant = existingReg.IsIAmTheParticipant }; if (string.IsNullOrEmpty(confirmationCode)) newReg.ConfirmationCode = existingReg.ConfirmationCode; else newReg.ConfirmationCode = confirmationCode; _repository.Registrations.Create(newReg); if (!_sharedRepository) _repository.SaveChanges(); } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }
public ServiceResult RemoveEventSponsor(int eventId, string fileName) { var result = new ServiceResult(); try { IQueryable<EventSponsor> sponsorsToDelete = _repository.EventSponsors.Filter(x => x.FileName == fileName && x.EventId == eventId); foreach (EventSponsor sponsorToDelete in sponsorsToDelete) { if (CanRemoveSponsor(sponsorToDelete, result)) { _repository.EventSponsors.Delete(sponsorToDelete); } } _repository.SaveChanges(); } catch (Exception ex) { result.AddServiceError(Utilities.GetInnerMostException(ex)); } return result; }