internal void NextRound(string debate_id) { RoundState debateState = _roundStateRepository.GetById(int.Parse(debate_id)); if (debateState != null) { UserDebate ud = _userDebateRepository.GetById(int.Parse(debate_id.ToString())); User pro_username = _userRepository.GetByUsername(ud.pro_username); User con_username = _userRepository.GetByUsername(ud.con_username); DebateInfo di = _debateRepository.GetById(int.Parse(debate_id)); if (debateState.next_round == 6) { di.state = "incheiat"; _debateRepository.Update(di); MailService.SendDoneDebateMail(pro_username, con_username, di); } else { int currentRound = debateState.next_round; debateState.next_round = ++currentRound; long actualTime = AuthToken.GetNistTime(); long nextRoundTime = actualTime + threeDaysInMillis; debateState.time_to_next = nextRoundTime.ToString(); _roundStateRepository.Update(debateState); MailService.SendNextRoundMail(pro_username, con_username, di, debateState.next_round); } } }
public void Add(UserDebate userDebate) { try { using (var context = new dezbateriEntities()) { context.UserDebates.Add(userDebate); context.SaveChanges(); } } catch (Exception ex) { throw new UserDebateException("Add", ex); } }
internal DebateModel GetDebate(string param, string username) { DebateModel dm = new DebateModel(); DebateInfo di = _debateRepository.GetById(int.Parse(param)); dm.DebateId = di.debate_id.ToString(); dm.Subject = di.subject; dm.Date_created = di.date_created; dm.State = di.state; dm.Description = di.description; List <CategoryDebate> categDebList = _categoryDebateRepository.GetAll().FindAll(categ => categ.debate_id.ToString() == dm.DebateId); List <String> debateCategories = new List <String>(); foreach (CategoryDebate cd in categDebList) { debateCategories.Add(_categoryRepository.GetById(cd.category_id).name); } dm.Category = debateCategories; UserDebate userDebList = _userDebateRepository.GetById(int.Parse(dm.DebateId)); dm.Pro_username = userDebList.pro_username; dm.Con_username = userDebList.con_username; RoundState roundState = _roundStateRepository.GetById(int.Parse(dm.DebateId)); dm.Next_round = roundState.next_round.ToString(); dm.Time_to_next = roundState.time_to_next; Content debContent = _contentRepository.GetById(int.Parse(dm.DebateId)); dm.Round_1 = debContent.round_1; dm.Round_2 = debContent.round_2; dm.Round_3 = debContent.round_3; dm.Round_4 = debContent.round_4; dm.Round_5 = debContent.round_5; dm.Round_6 = debContent.round_6; CheckRoundVisible(username, dm); return(dm); }
internal List <DebateModel> GetAllDebates() { List <DebateInfo> allDebates = _debateRepository.GetAll(); List <DebateModel> allModelDebates = new List <DebateModel>(); foreach (DebateInfo deb in allDebates) { DebateModel dm = new DebateModel(); dm.DebateId = deb.debate_id.ToString(); dm.Subject = deb.subject; dm.Date_created = deb.date_created; dm.Description = deb.description; dm.State = deb.state; List <CategoryDebate> categDebList = _categoryDebateRepository.GetAll().FindAll(categ => categ.debate_id.ToString() == dm.DebateId); List <String> debateCategories = new List <String>(); foreach (CategoryDebate cd in categDebList) { debateCategories.Add(_categoryRepository.GetById(cd.category_id).name); } dm.Category = debateCategories; UserDebate userDebList = _userDebateRepository.GetById(int.Parse(dm.DebateId)); dm.Pro_username = userDebList.pro_username; dm.Con_username = userDebList.con_username; RoundState roundState = _roundStateRepository.GetById(int.Parse(dm.DebateId)); dm.Next_round = roundState.next_round.ToString(); dm.Time_to_next = roundState.time_to_next; Content debContent = _contentRepository.GetById(int.Parse(dm.DebateId)); dm.Round_1 = debContent.round_1; dm.Round_2 = debContent.round_2; dm.Round_3 = debContent.round_3; dm.Round_4 = debContent.round_4; dm.Round_5 = debContent.round_5; dm.Round_6 = debContent.round_6; allModelDebates.Add(dm); } return(allModelDebates); }
public void Update(UserDebate userDebate) { try { using (var context = new dezbateriEntities()) { var userDebateUpdated = context.UserDebates.FirstOrDefault(userDebateObj => userDebateObj.debate_id == userDebate.debate_id); if (userDebateUpdated == null) { throw new UserDebateException("No userDebate found"); } userDebateUpdated.pro_username = userDebate.pro_username; userDebateUpdated.con_username = userDebate.con_username; context.SaveChanges(); } } catch (Exception ex) { throw new UserDebateException("Update", ex); } }
internal void JoinDebate(string debate_id, string user_id) { RoundState rs = _roundStateRepository.GetById(int.Parse(debate_id.ToString())); long next_speech = AuthToken.GetNistTime() + threeDaysInMillis; rs.time_to_next = next_speech.ToString(); _roundStateRepository.Update(rs); User us = _userRepository.GetByUsername(user_id); UserDebate ud = _userDebateRepository.GetById(int.Parse(debate_id.ToString())); ud.con_username = us.Username; _userDebateRepository.Update(ud); User pro_us = _userRepository.GetByUsername(ud.pro_username); DebateInfo di = _debateRepository.GetById(int.Parse(debate_id.ToString())); di.state = "desfasurare"; _debateRepository.Update(di); MailService.SendStartDebateMail(pro_us, us, di); }