/// <summary> /// Create a new QuickPollResult and add it to the appropriate places /// </summary> /// <param name="owner">The current participant</param> /// <param name="result">The result string</param> private void CreateNewQuickPollResult(ParticipantModel owner, string result) { using (Synchronizer.Lock(this.m_Model)) { // Create the QuickPollResultModel using (Synchronizer.Lock(owner.SyncRoot)) { this.m_Model.CurrentStudentQuickPollResult = new QuickPollResultModel(owner.Guid, result); } // Add to the QuickPollResults using (this.m_Model.Workspace.Lock()) { if (~this.m_Model.Workspace.CurrentPresentation != null) { using (Synchronizer.Lock((~this.m_Model.Workspace.CurrentPresentation).SyncRoot)) { if ((~this.m_Model.Workspace.CurrentPresentation).QuickPoll != null) { using (Synchronizer.Lock((~this.m_Model.Workspace.CurrentPresentation).QuickPoll.SyncRoot)) { if ((~this.m_Model.Workspace.CurrentPresentation).QuickPoll.QuickPollResults != null) { (~this.m_Model.Workspace.CurrentPresentation).QuickPoll.QuickPollResults.Add(this.m_Model.CurrentStudentQuickPollResult); } } } } } } } }
public RoleSynchronizer(SlideViewer sv, ParticipantModel pm) { this.m_SlideViewer = sv; this.m_Participant = pm; this.m_Participant.Changed["Role"].Add(new PropertyEventHandler(this.onRoleChange)); this.onRoleChange(this, null); }
protected override void OnItemActivate(EventArgs e) { base.OnItemActivate(e); ParticipantModel association = this.SelectedItems.Count > 0 ? this.SelectedItems[0].Tag as ParticipantModel : null; if (association != null) { using (Synchronizer.Lock(this.m_Model.Participant)) { if (this.m_Model.Participant.Role is InstructorModel || this.m_Model.Participant.Role == null) { this.m_Model.Participant.Role = new StudentModel(Guid.NewGuid()); } } using (Synchronizer.Lock(this.m_Model.Network.SyncRoot)) { this.m_Model.Network.Association = association; } } else { StartJoinButton.StartEmptyPresentation(this.m_Model); } }
public ActionResult SaveParticipant(ParticipantModel model) { ParticipantData MemRepo = new ParticipantData(); model.CLPid = 1; model.DateEntered = DateTime.Now; model.ModifiedDate = DateTime.Now; model.EnteredBy = 1; //user model.ModifiedBy = 1; //user if (ModelState.IsValid) { ResponseModel isSave = MemRepo.SaveParticipant(model); if (isSave.status == 1) { Connection.CommitTransaction(); Connection.CloseConnection(); return(Json(new { status = true, code = 2, msg = "Successfuly Created." }, JsonRequestBehavior.AllowGet)); } else { Connection.RollbackTransaction(); Connection.CloseConnection(); return(Json(new { status = false, code = 0, msg = "Something went wrong." }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { status = false, code = 0, msg = "Something went wrong." }, JsonRequestBehavior.AllowGet)); } }
private ParticipantItem CreateParticipantModel(Participant arg) { var part = new ParticipantModel(); part.Participant = arg; return(part); }
/// <summary> /// Set the disable status for student submission button /// </summary> /// <param name="disabled"></param> private void SetStudentSubmissionToolbar(bool disabled) { ParticipantModel participant = null; using (Synchronizer.Lock(this.m_Model.Workspace.CurrentPresentation.SyncRoot)) { if (this.m_Model.Workspace.CurrentPresentation.Value != null) { using (Synchronizer.Lock(this.m_Model.Workspace.CurrentPresentation.Value.SyncRoot)) { participant = this.m_Model.Workspace.CurrentPresentation.Value.Owner; } } } if (participant != null) { using (Synchronizer.Lock(participant.SyncRoot)) { using (Synchronizer.Lock(participant.Role.SyncRoot)) { ((InstructorModel)(participant.Role)).AcceptingStudentSubmissions = !disabled; } } } }
public static string ChangeProgress(string jsonString) { var cdb = new ConnectDB("Database1"); if (jsonString == "") { return("nil"); } var receivedData = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonString); try { var participant = new ParticipantModel { ProgressId = int.Parse(receivedData["progressId"]), ParticipantName = receivedData["participantName"], CurrentProgress = int.Parse(receivedData["currentProgress"]) }; var password = receivedData["progPassword"]; if (cdb.IsCorrectPassword(participant, password)) { cdb.ChangeProgress(participant); return("success"); } return("wrongPassword"); } catch (Exception ex) { var thisPage = new GetJsonString(); thisPage.WriteErrorLog(ex.Message); return("error"); } }
protected override void OnClick(EventArgs e) { base.OnClick(e); if (this.m_Association != null) { // Set the role accordingly using (Synchronizer.Lock(this.m_Model.Participant)) { if (this.m_Model.Participant.Role is InstructorModel || this.m_Model.Participant.Role == null) { this.m_Model.Participant.Role = new StudentModel(Guid.NewGuid()); } } // Set the network association using (Synchronizer.Lock(this.m_Model.Network.SyncRoot)) { this.m_Model.Network.Association = this.Association; } } else { // Instead Start an Empty Presentation StartJoinButton.StartEmptyPresentation(this.m_Model); } }
public bool UpdateParticipant(int leaderboardId, ParticipantModel trainer) { if (trainer == null) { return(false); } var leaderboard = GetLeaderboard(leaderboardId); if (leaderboard == null) { return(false); } var player = leaderboard.Participants.FirstOrDefault((participant) => participant.Username == trainer.Username); if (player == null) { return(false); } var index = leaderboard.Participants.IndexOf(player); leaderboard.Participants[index] = trainer; return(_database.UpdateLeaderboard(leaderboard)); }
public async Task <ActionResult <ParticipantModel> > Put(ParticipantModel model) { try { var participant = await _uow.GetRepository <Participants>().GetAsync(model.Id); if (participant == null) { return(NotFound($"Participant {model.Id} introuvable")); } if (string.IsNullOrWhiteSpace(model.Nom)) { return(BadRequest("Le nom de le Participant est obligatoire.")); } var updatedParticipant = _mapper.Map <Participants>(model); _uow.GetRepository <Participants>().Update(updatedParticipant); await _uow.CommitAsync(); var url = _linkGenerator.GetPathByAction(HttpContext, "Get", values: new { id = participant.Id }); return(Created(url, _mapper.Map <ParticipantModel>(updatedParticipant))); } catch (Exception ex) { _logger.LogError($"Error Participant-post-one : {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
private ParticipantModel AddLoss(ParticipantModel loser, int points) { loser.Losses++; loser.Points -= Math.Max(3, points); loser.Points = Math.Max(0, loser.Points); return(loser); }
public AddTrainerResponseCode AddTrainer(int leaderboardId, ParticipantModel trainer) { if (trainer == null) { return(AddTrainerResponseCode.UnknownError); } var leaderboard = GetLeaderboard(leaderboardId); if (leaderboard == null) { return(AddTrainerResponseCode.UnknownError); } if (leaderboard.Participants.Any(participant => participant.Username == trainer.Username)) { return(AddTrainerResponseCode.TrainerAlreadyParticipates); } trainer.Position = leaderboard.Participants.Count + 1; leaderboard.Participants.Add(trainer); leaderboard = RecalculatePositions(leaderboard); if (_database.UpdateLeaderboard(leaderboard)) { return(AddTrainerResponseCode.TrainerAddedSuccesfully); } else { return(AddTrainerResponseCode.UnknownError); } }
public async Task <ActionResult <ParticipantModel> > PostParticipant(ParticipantModel participant) { _context.Participants.Add(participant); await _context.SaveChangesAsync(); return(CreatedAtAction("GetParticipant", new { id = participant.Id }, participant)); }
/// <summary> /// Release all resources /// </summary> /// <param name="disposing">True if truely disposing</param> protected override void Dispose(bool disposing) { if (this.m_Disposed) { return; } try { if (disposing) { // Unregister event listeners this.m_CurrentResult = null; this.m_Model.Changed["CurrentStudentQuickPollResult"].Remove(this.m_CurrentQuickPollResultChangedDispatcher.Dispatcher); ParticipantModel participant = null; using (Synchronizer.Lock(this.m_Model.Workspace.CurrentPresentation.SyncRoot)) { if (this.m_Model.Workspace.CurrentPresentation.Value != null) { using (Synchronizer.Lock(this.m_Model.Workspace.CurrentPresentation.Value.SyncRoot)) { participant = this.m_Model.Workspace.CurrentPresentation.Value.Owner; } } } if (participant != null) { using (Synchronizer.Lock(participant.SyncRoot)) { ((InstructorModel)(participant.Role)).Changed["AcceptingQuickPollSubmissions"].Remove(this.m_QuickPollChangedDispatcher.Dispatcher); } } this.Role = null; } } finally { base.Dispose(disposing); } this.m_Disposed = true; }
public ParticipantModel GetParticipant(int id) { List <ParticipantModel> partLst = new List <ParticipantModel>(); ParticipantModel part = new ParticipantModel(); //string query = "Select * from [dbo].[CLPParticipant] WHERE Memberid = " + id; string query = "Select prt.id, prt.memberId, prt.CLPid, prt.GroupId, prt.statusID, mem.LastName + ', ' + mem.FirstName as name from [dbo].[CLPParticipant] prt " + "Inner Join[dbo].[Member] mem ON prt.memberId = mem.id WHERE Memberid = " + id; DataSet ds = Connection.connectSQLServerQuery(query); partLst = BaseReflection.DatasetBDToObjectList <ParticipantModel>(ds); if (partLst.Count > 0) { part = new ParticipantModel { id = partLst[0].id, memberId = partLst[0].memberId, name = partLst[0].name, GroupId = partLst[0].GroupId, CLPid = partLst[0].CLPid, statusID = partLst[0].statusID }; } //part.MemberList = ParticipantData.GetMemberParticipantListModify(); //GenericList model = (GroupList != null && GroupList.Count > 0) ? GroupList[0] : null; return(part); }
public bool IsExistSameName(ParticipantModel participant) { try { using (var conn = new SqlConnection(_connectString)) using (var cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = @" SELECT * FROM [dbo].[Participants] WITH(NOLOCK) WHERE ParticipantName = @ParticipantName AND ProgressId = @ProgressId;"; cmd.Parameters.Add(new SqlParameter("@ParticipantName", SqlDbType.NVarChar, 50)).Value = participant.ParticipantName; cmd.Parameters.Add(new SqlParameter("@ProgressId", SqlDbType.Int)).Value = participant.ProgressId; using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { return(true); } } return(false); } } catch { throw; } }
/// <summary> /// Handle AcceptingStudentSubmissions changing (disable when false) /// </summary> /// <param name="sender">The event sender</param> /// <param name="args">The arguments</param> private void HandleAcceptingSSubsChanged(object sender, PropertyEventArgs args) { InstructorModel instructor = null; ParticipantModel participant = null; using (Synchronizer.Lock(this.m_Model.Workspace.CurrentPresentation.SyncRoot)) { if (this.m_Model.Workspace.CurrentPresentation.Value != null) { using (Synchronizer.Lock(this.m_Model.Workspace.CurrentPresentation.Value.SyncRoot)) { participant = this.m_Model.Workspace.CurrentPresentation.Value.Owner; } } } if (participant != null) { using (Synchronizer.Lock(participant.SyncRoot)) { if (participant.Role != null) { instructor = participant.Role as InstructorModel; } } } if (instructor != null) { using (Synchronizer.Lock(instructor.SyncRoot)) { this.Enabled = instructor.AcceptingStudentSubmissions; } } }
public void LikeParticipant(UserModel user, ParticipantModel participant) { var userObject = this.movieAppDbContext.Users .Where(x => x.UserId == user.UserId) .FirstOrDefault(); if (userObject == null) { throw new ArgumentNullException("User not found!"); } var participantObject = this.movieAppDbContext.Participants .Where(x => x.ParticipantId == participant.ParticipantId) .FirstOrDefault(); if (userObject == null) { throw new ArgumentNullException("Participant not found!"); } if (userObject.LikedParticipants.Any(p => p.ParticipantId == participantObject.ParticipantId)) { throw new ArgumentException("Participant already liked!"); } userObject.LikedParticipants.Add(participantObject); participantObject.ParticipantLikedByUser.Add(userObject); this.movieAppDbContext.SaveChanges(); }
public void SetParticipant(ParticipantModel participant) { using (var conn = new SqlConnection(_connectString)) using (var cmd = conn.CreateCommand()) { conn.Open(); try { cmd.CommandText = @" INSERT INTO [dbo].[Participants] VALUES (@ProgressId, @ParticipantName, @CurrentProgress);"; cmd.Parameters.Add(new SqlParameter("@ProgressId", SqlDbType.Int)).Value = participant.ProgressId; cmd.Parameters.Add(new SqlParameter("@ParticipantName", SqlDbType.NVarChar, 50)).Value = participant.ParticipantName; cmd.Parameters.Add(new SqlParameter("@CurrentProgress", SqlDbType.Int)).Value = participant.CurrentProgress; cmd.ExecuteNonQuery(); } catch { throw; } } }
public TCPClient(IPEndPoint remoteEP, ParticipantModel participant, NetworkModel network, Guid serverID) { m_Connected = false; m_Network = network; m_Participant = participant; m_LastMsgReceived = DateTime.MaxValue; m_ServerId = serverID; m_ClientTimeout = TimeSpan.FromMilliseconds(TCP_HEARTBEAT_TIMEOUT_DEFAULT_MS); this.m_RemoteEP = remoteEP; m_Socket = null; m_ServerParticipant = null; m_ReceiveQueue = new Queue(); this.m_Encoder = new Chunk.ChunkEncoder(); m_NetworkStatus = new NetworkStatus(ConnectionStatus.Disconnected, ConnectionProtocolType.TCP, TCPRole.Client, 0); this.m_Network.RegisterNetworkStatusProvider(this, true, m_NetworkStatus); //Find out if client-side bridging is enabled m_BridgeEnabled = false; string enableBridge = System.Configuration.ConfigurationManager.AppSettings[this.GetType().ToString() + ".EnableBridge"]; if (enableBridge != null) { bool enable = false; if (bool.TryParse(enableBridge, out enable)) { Trace.WriteLine("Unicast to Multicast Bridge enabled=" + enable.ToString(), this.GetType().ToString()); m_BridgeEnabled = enable; } } }
public bool ChangeProgress(ParticipantModel participant) { using (var conn = new SqlConnection(_connectString)) using (var cmd = conn.CreateCommand()) { conn.Open(); try { cmd.CommandText = @" UPDATE [dbo].[Participants] SET CurrentProgress = @CurrentProgress WHERE ProgressId = @ProgressId AND ParticipantName = @ParticipantName;"; cmd.Parameters.Add(new SqlParameter("@CurrentProgress", SqlDbType.Int)).Value = participant.CurrentProgress; cmd.Parameters.Add(new SqlParameter("@ProgressId", SqlDbType.Int)).Value = participant.ProgressId; cmd.Parameters.Add(new SqlParameter("@ParticipantName", SqlDbType.NVarChar, 50)).Value = participant.ParticipantName; cmd.ExecuteNonQuery(); return(true); } catch (Exception ex) { throw; } } }
/// <summary> /// Run a query to get all participants /// </summary> public List <ParticipantModel> GetParticipants() { var Participants = new List <ParticipantModel>(); using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["PhotoConsentDB"].ToString())) { cn.Open(); var sql = string.Format("SELECT * FROM Participants"); SqlCommand sqlCommand = new SqlCommand(sql, cn); SqlDataReader reader = sqlCommand.ExecuteReader(); while (reader.Read()) { var model = new ParticipantModel(); model.FormID = (int)reader["FormID"]; model.Name = (string)reader["Name"]; model.ParticipantID = (int)reader["ParticipantID"]; model.ContactNumber = reader["ContactNumber"] == DBNull.Value ? "" : (string)reader["ContactNumber"]; model.Email = reader["Email"] == DBNull.Value ? "" : (string)reader["Email"]; Participants.Add(model); } cn.Close(); } return(Participants); }
public async Task <IActionResult> PutParticipant(int id, ParticipantModel participant) { if (id != participant.Id) { return(BadRequest()); } _context.Entry(participant).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ParticipantExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static Participant FromModel(this ParticipantModel model) { return(new Participant { Id = model.Id, Name = model.Name }); }
// GET: Participant/Edit/5 public ActionResult Edit(int id) { ParticipantRepository repository = new ParticipantRepository(); ParticipantModel model = repository.GetById(id); return(View(model)); }
public ClientData(Socket s, Guid id, ParticipantModel part) { Socket = s; Id = id; Participant = part; ConnectionState = ConnectionState.Connected; Timeout = DateTime.MaxValue; }
public async Task <bool> RemoveTrainerAsync(LeaderboardModel leaderboard, ParticipantModel participant) { if (participant == null || leaderboard == null) { return(false); } return(await _httpManager.DeleteAsync <bool>(ApiConstants.LeaderboardsURL + ApiConstants.LeagueExtension + leaderboard.ID.ToString() + "/" + ApiConstants.TrainerExtension + participant.Username)); }
public TCPHandshakeMessage(ParticipantModel participant, IPEndPoint ep) { this.ParticipantId = participant.Guid; this.EndPoint = ep; using (Synchronizer.Lock(participant.SyncRoot)) { this.HumanName = participant.HumanName; } LastMessageSequence = LastChunkSequence = 0; }
public IEnumerable <Role> ParticipantRolesPerMovie(ParticipantModel participant, MovieModel movie) { var pRoles = this.movieAppDbContext.Roles .Where(x => x.Participant.ParticipantId == participant.ParticipantId && x.Movie.MovieId == movie.MovieId); return(pRoles); }
public void AddMovieParticipantShouldCorrectlyAddParticipantToMovie_WhenCalledWithValidData() { // Assert var effort = new MovieAppDBContext( Effort.DbConnectionFactory.CreateTransient()); var mapperMock = new Mock <IMapper>(); var movieObject = new Movie() { Title = "Test Movie", Year = 1990 }; var participantObject = new Participant() { FirstName = "Arnold", LastName = "Ivanov" }; effort.Movies.Add(movieObject); effort.Participants.Add(participantObject); effort.SaveChanges(); var participantDto = new ParticipantModel() { ParticipantId = participantObject.ParticipantId, FirstName = participantObject.FirstName, LastName = participantObject.LastName }; var movieDto = new MovieModel() { MovieId = movieObject.MovieId, Title = movieObject.Title, Runtime = movieObject.Runtime }; var roleName = "Actor"; // Act var sut = new MovieService(effort, mapperMock.Object); sut.AddMovieParticipant(movieDto, participantDto, roleName); // Assert var participantAddedToMovie = movieObject.Participants.FirstOrDefault(); var movieAddedToParticipant = participantObject.Movies.FirstOrDefault(); var roleIsCorrect = effort.Roles.FirstOrDefault().RoleName == "Actor"; // Unit test should fail for only one reason // either change the method to be SRP or separate the test into 3 parts Assert.IsTrue(participantAddedToMovie == participantObject); Assert.IsTrue(movieAddedToParticipant == movieObject); Assert.IsTrue(roleIsCorrect); }
public void Function_Name() { Scenario("We have a participant model"); Given("we want to create a participant model"); When("we instantiate the participant model class", () => participantModel = new ParticipantModel() ); Then("we have a participant model", () => participantModel.ShouldNotBeNull() ); }