public ConnectorClient() { _restClient = new RestClient("https://ch-core-mp.azurewebsites.net/v1/") { Authenticator = new HttpBasicAuthenticator(ConfigService.Get(Constants.UserToken), string.Empty) }; }
public async Task <IEnumerable <Meeting> > GetOpenMeetingsByRoomId(long roomId) { using (var db = new HackDbContext(ConfigService.Get(Constants.DbConnectionKey))) { return(await db.Meetings.Where(m => m.RoomId == roomId && m.DateEnd == null).ToListAsync()); } }
public async Task <string> GetSparkRoomId(long roomId) { using (var db = new HackDbContext(ConfigService.Get(Constants.DbConnectionKey))) { var room = await db.Rooms.FindAsync(roomId); return(room == null ? string.Empty : room.RoomId); } }
public async Task <Answer> GetNextMeetingPushAsync(long meetId) { using (var db = new HackDbContext(ConfigService.Get(Constants.DbConnectionKey))) { return(await db.Answers .Where(a => a.MeetingId == meetId && a.Ans1 == null && a.Ans2 == null && a.Ans3 == null) .OrderBy(a => a.Id) .FirstOrDefaultAsync()); } }
public async Task <int> DeleteAnswersInMiting(long meetId) { using (var db = new HackDbContext(ConfigService.Get(Constants.DbConnectionKey))) { var anss = await db.Answers.Where(a => a.MeetingId == meetId).ToListAsync(); db.Answers.RemoveRange(anss); return(await db.SaveChangesAsync()); } }
public async Task <Room> FindRoom(long roomId) { using (var db = new HackDbContext(ConfigService.Get(Constants.DbConnectionKey))) { var room = await db.Rooms.FirstOrDefaultAsync(r => r.Id == roomId); if (room == null) { throw new ApplicationException("not found roomId=" + roomId); } return(room); } }
public Task PushEndOfMeetingAsync(string botName, string userId) { var message = ConfigService.Get(Constants.TemplateMessage3); var pushData = new ExternalMessage { Count = 1, ForcedState = string.Empty, Messages = new List <string> { message } }; return(PerformPushRequest(botName, userId, pushData)); }
public async Task <IEnumerable <Answer> > GetLastMeetingAnswersByRoomId(long roomId) { using (var db = new HackDbContext(ConfigService.Get(Constants.DbConnectionKey))) { var lastMeet = await db.Meetings .Where(m => m.RoomId == roomId && m.DateEnd != null) .OrderByDescending(m => m.Id) .FirstOrDefaultAsync(); if (lastMeet == null) { return(new List <Answer>()); } return(await db.Answers.Where(a => a.MeetingId == lastMeet.Id).ToListAsync()); } }
public async Task <List <ChatRoomUser> > GetUsersAsync(string roomId, string botName) { if (string.IsNullOrEmpty(roomId) || string.IsNullOrEmpty(botName)) { throw new ArgumentNullException(); } var userToken = ConfigService.Get(Constants.UserToken); var urlApi = string.Format(ConfigService.Get(Constants.UrlApiGetChatRoomUsers), userToken, botName, roomId); Trace.TraceInformation("[ChatRoomUserService.GetUsers] get url: " + urlApi); var users = await this.GetUsersAsync(urlApi); return(users); }
public async Task <Meeting> UpdateMeeting(long meetId, Meeting meet) { using (var db = new HackDbContext(ConfigService.Get(Constants.DbConnectionKey))) { var dbMeet = await db.Meetings.FirstOrDefaultAsync(m => m.Id == meetId); if (dbMeet == null) { return(null); } dbMeet.DateEnd = meet.DateEnd; dbMeet.DateStart = meet.DateStart; db.Entry(dbMeet).State = EntityState.Modified; await db.SaveChangesAsync(); return(dbMeet); } }
public Task PushRemoteChatService(string botName, string userId, string userName) { //0 - userId, 1 - userName const string templatePerson = "<@personId:{0}|{1}>"; var templateMsg1 = string.Format(ConfigService.Get(Constants.TemplateMessage1), templatePerson); var templateMsg2 = ConfigService.Get(Constants.TemplateMessage2); var pushData = new ExternalMessage { Count = 1, ForcedState = ConfigService.Get(Constants.ForcedState), Messages = new List <string> { string.Format(templateMsg1, userId, userName), templateMsg2 } }; return(PerformPushRequest(botName, userId, pushData)); }
public async Task <Meeting> SaveMeeting(Room room, IEnumerable <ChatRoomUser> users) { using (var db = new HackDbContext(ConfigService.Get(Constants.DbConnectionKey))) { using (var transaction = db.Database.BeginTransaction()) { try { var meet = new Meeting { DateStart = DateTime.UtcNow, RoomId = room.Id }; meet = db.Meetings.Add(meet); await db.SaveChangesAsync(); var prepareAnswers = users.Select(u => new Answer { MeetingId = meet.Id, UserId = u.userId, UserName = u.userName.Split(' ').FirstOrDefault() }).ToList(); db.Answers.AddRange(prepareAnswers); await db.SaveChangesAsync(); transaction.Commit(); return(meet); } catch { transaction.Rollback(); throw; } } } }
public DalService() : this(ConfigService.Get(Constants.DbConnectionKey)) { }