public ActionResult Signup(string id, ContestSignupModel model) { if (!ModelState.IsValid) return View(model); try { switch (model.Type.Value) { case ContestSignupModel.SignupType.Attend: Contest.ByName(id).Attend(); break; case ContestSignupModel.SignupType.Virtual: if (model.StartTime == null) { ModelState.AddModelError("StartTime", "开始时间非法"); return View(model); } Contest.ByName(id).VirtualAttend(model.StartTime.Value); break; case ContestSignupModel.SignupType.Practice: Contest.ByName(id).PracticeAttend(); break; case ContestSignupModel.SignupType.Cancel: Contest.ByName(id).Disattended(); break; } } catch (ContestNotFoundException) { return RedirectToAction("Error", "Shared", new { msg = "没有这场比赛" }); } catch (UserNotLoginException) { throw; } catch (AlreadyAttendedContestException) { return RedirectToAction("Error", "Shared", new { msg = "不可重复参加比赛" }); } catch (ContestEndedException) { return RedirectToAction("Error", "Shared", new { msg = "比赛已结束,不可报名" }); } catch (ContestNotStartedException) { return RedirectToAction("Error", "Shared", new { msg = "比赛尚未开始" }); } catch (ContestStartedException) { return RedirectToAction("Error", "Shared", new { msg = "比赛已经开始,不可取消参赛" }); } catch (VirtualStartTooEarlyException) { return RedirectToAction("Error", "Shared", new { msg = "模拟比赛开始时间不得早于当前时间" }); } return RedirectToAction("Show", new { id = id }); }
public ActionResult Signup(string id) { Contest contest; try { contest = Contest.ByName(id); } catch (ContestNotFoundException) { return RedirectToAction("Error", "Shared", new { msg = "没有相应的比赛" }); } ContestSignupModel model = new ContestSignupModel { Contest = contest, StartTime = DateTime.Now.AddMinutes(5) }; return View(model); }