Ejemplo n.º 1
0
        public string GetShareBodyText(Team team, EventWave eventWave, User user, EventDate eventDate,
                              bool includeJavascriptLineBreaks)
        {
            if (team == null || user == null || eventDate == null)
                return string.Empty;

            var filePath = HostingEnvironment.MapPath(string.Format("~/{0}/{1}", DirtyGirlServiceConfig.Settings.EmailTemplatePath,
                                                      DirtyGirlServiceConfig.Settings.TeamInviteBody)) ?? "";
            var bodyText =
                System.IO.File.ReadAllText(filePath)
                      .Replace("{RegistrantName}",
                               string.Format("{0} {1}", user.FirstName, user.LastName))
                      .Replace("{EventID}", team.Event.EventId.ToString())
                      .Replace("{RaceLocation}", team.Event.GeneralLocality)
                      .Replace("{DayOfWeek}", eventDate.DateOfEvent.ToString("dddd"))
                      .Replace("{Month}", eventDate.DateOfEvent.ToString("MMMM"))
                      .Replace("{Day}", eventDate.DateOfEvent.ToString("dd"))
                      .Replace("{Year}", eventDate.DateOfEvent.ToString("yyyy"))
                      .Replace("{WaveNumber}", eventWave.EventWaveId.ToString())
                      .Replace("{BeginTime}", eventWave.StartTime.ToString("hh:mm tt"))
                      .Replace("{EndTime}", eventWave.EndTime.ToString("hh:mm tt"))
                      .Replace("{TeamCode}", team.Code)
                      .Replace("{LineBreak}", (includeJavascriptLineBreaks ? "\\" : ""));
            return bodyText;
        }
Ejemplo n.º 2
0
        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;
        }
        private void CreateNewTeam(vmRegistration_CreateTeam model, Registration reg)
        {
            if (string.IsNullOrEmpty(model.TeamName))
            {
                ModelState.AddModelError("TeamName", "Team Name is Required");
                return;
            }

            Match match = Regex.Match(model.TeamName, @"([a-zA-Z].*?){3}", RegexOptions.IgnoreCase);

            if (!match.Success)
            {
                ModelState.AddModelError("TeamName", "Team Name must contain at least 3 letters.");
                return;
            }

            Team newTeam = new Team {EventId = model.EventId, Name = model.TeamName, CreatorID = CurrentUser.UserId};

            ServiceResult tempTeamResult = _service.GenerateTempTeam(newTeam);

            if (!tempTeamResult.Success)
                Utilities.AddModelStateErrors(ModelState, tempTeamResult.GetServiceErrors());
            else
                reg.Team = newTeam;
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
 protected bool ValidateTeam(Team teamToValidate, ServiceResult serviceResult)
 {
     if (_repository.Teams.Filter(t => t.EventId == teamToValidate.EventId && t.Name.Equals(teamToValidate.Name)).Any())
     {
         serviceResult.AddServiceError("Name", "A team with that name already exists for this event.");
     }
     return serviceResult.Success;
 }
Ejemplo n.º 6
0
        public JsonResult CreateTeam(vmTeam_Create teamCreate)
        {
            string errors = string.Empty;
            if (ModelState.IsValid)
            {
                if (!_teamService.CheckTeamNameForDirtyWords(teamCreate.TeamName))
                {
                    return Json("The requested team name contains a naughty word.");
                }

                if (_teamService.CheckTeamNameAvailability(teamCreate.EventId, teamCreate.TeamName))
                {
                    var newTeam = new Team { EventId = teamCreate.EventId, Name = teamCreate.TeamName, CreatorID = CurrentUser.UserId};
                    ServiceResult result = _teamService.CreateTeam(newTeam, teamCreate.RegistrationId);
                    if (result.Success)
                    {
                        return Json(new { redirect = Url.Action("ViewTeam", "Team", new { teamId = newTeam.TeamId}) });
                    }
                    result.GetServiceErrors().ForEach(x => errors += x.ErrorMessage + "<br/>");
                    errors += string.Format("\nEventID: {0}, name: {1}, regid: {2}\n", teamCreate.EventId,
                                            teamCreate.TeamName, teamCreate.RegistrationId);
                    return Json(errors);
                }
                return Json("The requested team name is already in use for this event. Please select a different team name.");
            }
            ModelState.Values.ForEach(x => errors += x.Errors + "<br/>");
            return Json(errors);
        }