public CompetitionResponse Delete(CompetitionRequest request) { this.log.Debug("Got DELETE request: " + request); var session = this.GetSession() as CustomUserSession; if (session == null || session.User == null) { // This really shouldn't happen since we have attributed for authenticate this.log.Error("Session is null in DELETE request."); throw new Exception("You need to authenticate"); } if (string.IsNullOrEmpty(request.CompetitionId)) { throw new Exception("You didn't supply a competition ID"); } this.logic.CurrentUser = session.User; this.log.Debug("User is " + this.logic.CurrentUser); this.logic.DeleteCompetition(Guid.Parse(request.CompetitionId)); // This is needed to get IE to be happy. return new CompetitionResponse(); }
public CompetitionResponse Post(CompetitionRequest request) { this.log.Debug("Got POST request: " + request); var session = this.GetSession() as CustomUserSession; if (session == null) { // This really shouldn't happen since we have attributed for authenticate this.log.Error("Session is null in POST request."); throw new Exception("You need to authenticate"); } this.logic.CurrentUser = session.User; this.log.Debug("User is " + this.logic.CurrentUser); if (string.IsNullOrEmpty(request.CompetitionId)) { request.ValidateValues(true); this.log.Debug("Adding a competition."); request.CompetitionId = this.logic.AddCompetition(session.User, request.GetDatabaseCompetition()).Id.ToString(); this.log.DebugFormat("New competition ID is {0}.", request.CompetitionId); } else { request.ValidateValues(false); this.log.Debug("Updating a competition."); this.logic.UpdateCompetition(request.GetDatabaseCompetition()); } // We have updated, read from database and return. return this.Get(request); }
/// <summary> /// The any. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="CompetitionResponse"/>. /// </returns> public CompetitionResponse Get(CompetitionRequest request) { try { this.log.Debug("Got GET request: " + request); var requestedCompetitionId = Guid.Parse(request.CompetitionId); var session = this.GetSession() as CustomUserSession; this.logic.CurrentUser = session == null || session.User == null ? null : session.User; if (this.logic.CurrentUser == null) { this.log.Debug("User is anonymous."); } else { this.log.Debug("User is " + this.logic.CurrentUser); } var dbcompetition = this.logic.GetCompetition(requestedCompetitionId); if (dbcompetition != null) { this.log.Debug("Returned competition: " + dbcompetition); return new CompetitionResponse(dbcompetition); } } catch (Exception exception) { this.log.Warn(exception); throw; } this.log.Warn("Could not find competition accordng to search criteria."); throw new Exception(string.Format("Could not find competition with Guid {0}", request.CompetitionId)); }