/* public void CollapseChatroom() { * using (ApplicationDbContext db = new ApplicationDbContext()) * { * var user = db.LiveUsers.SingleOrDefault(x => x.IsAdmin); * var user1 = db.LiveUsers.SingleOrDefault(x => x.ConnId == Context.ConnectionId); * if (Context.User.IsInRole("Admin")) * { * foreach (var item in db.LiveUsers.Where(x => !x.IsAdmin)) * { * db.LiveUsers.Remove(item); * } * user.IsOnline = false; * db.SaveChanges(); * * Clients.All.AdminOut("Консультант отключился."); * Clients.Caller.Out(); * } * else * { * * Clients.Group(user1.ConnId).UserOut("Пользователь отключился."); * Clients.Caller.Out(); * Clients.All.NotifyAboutDisc(user1.ConnId); * Groups.Remove(user1.ConnId, user1.ConnId); * * db.LiveUsers.Remove(user1); * db.SaveChanges(); * } * } * }*/ public override Task OnDisconnected(bool stopCalled) { if (!stopCalled) { } else { using (ApplicationDbContext db = new ApplicationDbContext()) { var user = db.LiveUsers.SingleOrDefault(x => x.IsAdmin); var user1 = db.LiveUsers.SingleOrDefault(x => x.ConnId == Context.ConnectionId); if (Context.User.IsInRole("admin")) { foreach (var item in db.LiveUsers.Where(x => !x.IsAdmin)) { db.LiveUsers.Remove(item); } user.IsOnline = false; user.GroupId = ""; db.SaveChanges(); Groups.Remove(user.ConnId, user1.GroupId); Clients.All.AdminOut("Консультант отключился."); AdminOff(); } else { var newQuestions = db.LiveUsers.Where(x => x.LiveMessages.Any(y => !y.Visited)).Count() - 1; var isInGroup = user.GroupId == Context.ConnectionId; Clients.Client(user.ConnId).UserOut(Context.ConnectionId, "Пользователь " + user1.UserName + " отключился ", newQuestions, isInGroup); Groups.Remove(user1.ConnId, user1.ConnId); db.LiveUsers.Remove(user1); db.SaveChanges(); Clients.Client(ConsultantController.ConsultConnId()).NotifyAboutConnection( ConsultantController.OnlineUsersCount()); } } } return(base.OnDisconnected(stopCalled)); }
public async Task TestGetNoResults() { // Arrange var models = new List <ConsultantDTO>(); var mockService = new Mock <IConsultantService>(); mockService .Setup(x => x.GetAllAsDTOAsync()) .ReturnsAsync(models); var controller = new ConsultantController(mockService.Object); // Act var result = await controller.Get(); // Assert var actionResult = Assert.IsAssignableFrom <OkObjectResult>(result.Result); var modelResult = Assert.IsAssignableFrom <IEnumerable <ConsultantDTO> >(actionResult.Value); Assert.Empty(modelResult); }
public void NotifyAboutConnect(string name) { Clients.Client(ConsultantController.ConsultConnId()).NotifyAboutConnection(ConsultantController.OnlineUsersCount(), name, DateTime.Now.ToShortTimeString()); }
// // POST: /Account/LogOff public ActionResult LogOff() { AuthenticationManager.SignOut(); ConsultantController.SetConsultOffline(); return(Redirect("/")); }