public ActionResult EditCompetition(long competitionID) { Competition competition = null; if (competitionID > 0) { using (CompetitionRepository repository = new CompetitionRepository()) { competition = repository.GetCompetition(competitionID); if (competition == null) { throw new ApplicationException(string.Format("Unable to retrieve Competition object for competitionID: ", competitionID)); } competition.UseDefaultImage = competition.IsUsingDefaultImage(); competition.CompetitionProgressBars = ControllerHelpers.GetCompetitionProgressBars(repository, competitionID); ViewBag.AllowEdit = (IsUserAdmin || competition.CreatorUserID == UserID); } } else { competition = new Competition() { IsActive = true }; ViewBag.AllowEdit = true; } //if another method redirected to here show the purr message if (TempData[ControllerHelpers.PURR] != null) { ViewBag.Purr = TempData[ControllerHelpers.PURR]; TempData[ControllerHelpers.PURR] = null; } return(View(competition)); }
public ActionResult Index(SweatyTShirt sweatyTShirt) { int userID = UserID; sweatyTShirt.UserID = userID; using (CompetitionRepository competitionRepository = new CompetitionRepository()) { if (sweatyTShirt.IsSave) { sweatyTShirt.CreatedDate = DateTime.Now; competitionRepository.AddSweatyTShirt(sweatyTShirt); ViewBag.Purr = new Purr() { Title = "Success", Message = "Sweaty-T-Shirt was successfully added." }; } sweatyTShirt.Competitions = competitionRepository .GetUserInCompetitionsForUser(userID) .Where(o => o.IsActive) .Select(o => o.Competition).ToList(); if (sweatyTShirt.Competitions.Count > 0) { if (sweatyTShirt.CompetitionID > 0) { sweatyTShirt.Competition = sweatyTShirt.Competitions.FirstOrDefault(o => o.CompetitionID == sweatyTShirt.CompetitionID); } else { sweatyTShirt.Competition = sweatyTShirt.Competitions[0]; sweatyTShirt.CompetitionID = sweatyTShirt.Competition.CompetitionID; } if (sweatyTShirt.Competition == null) { throw new ApplicationException(string.Format("Unable to retrieve Competition object for sweatyTShirt.CompetitionID {0}", sweatyTShirt.CompetitionID)); } sweatyTShirt.Competition.CompetitionProgressBars = ControllerHelpers.GetCompetitionProgressBars(competitionRepository, sweatyTShirt.CompetitionID); if (sweatyTShirt.IsSave) { /* emails are sent in separate thread, see global.asax.cs*/ if (sweatyTShirt.PostToFacebook) { FacebookRepository.PostToFacebook(sweatyTShirt); } } } } if (TempData[ControllerHelpers.PURR] != null) { ViewBag.Purr = TempData[ControllerHelpers.PURR]; TempData[ControllerHelpers.PURR] = null; } sweatyTShirt.IsSave = false; sweatyTShirt.Description = null; //will get client side validation errors because manually adding model to view, need to clear them. ModelState.Clear(); return(View(sweatyTShirt)); }