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 ActionResult CreateTeamPost(int teamId, string post) { ITeamService teamService = new TeamService(new RepositoryGroup(), false); var team = _teamService.GetTeamById(teamId); if (team == null) { Response.StatusCode = 403; return Content("Invalid TeamId Submitted"); } if (CurrentUser != null && team.Registrations.FirstOrDefault(x => x.UserId == CurrentUser.UserId) != null) { var teamPost = new TeamPost {TeamId = teamId, Post = post, UserId = CurrentUser.UserId}; var dbResult = teamService.CreateTeamPost(teamPost); if (dbResult.Success) { //success var teamRefresh = _teamService.GetTeamById(teamId); var entity = teamRefresh.TeamPosts.OrderBy(x => x.DateAdded).ToList(); return PartialView("Partial/MessageBoardPosts", entity); } Response.StatusCode = 500; return Content("Invalid TeamId Submitted"); } Response.StatusCode = 403; return Content("Only members of a team may post messages."); }