public async Task <IActionResult> Login([FromBody] UserDTO user) { if (await _redisHandler.IsCached("Userlist:Users")) { var data = JsonConvert.DeserializeObject <List <User> >(await _redisHandler.GetFromCache("Userlist:Users")); var login = data.FirstOrDefault(x => x.Username == user.Username && x.Password == user.Password); if (login != null) { return(await Task.FromResult(Ok(new { Username = login.Username }))); } } else { var users = await _userRepository.GetAll(); await _redisHandler.AddToCache("Userlist:Users", TimeSpan.FromMinutes(2), JsonConvert.SerializeObject(users)); var data = users.FirstOrDefault(x => x.Username == user.Username && x.Password == user.Password); if (data != null) { return(await Task.FromResult(Ok(new { Username = data.Username }))); } } return(await Task.FromResult(NotFound())); }
public override async Task OnConnectedAsync() { await Clients.Client(Context.ConnectionId).SendAsync("SetConnectionId", Context.ConnectionId); IEnumerable <Room> data = new List <Room>(); if (await _redisHandler.IsCached("Room:Rooms")) { data = JsonConvert.DeserializeObject <List <Room> >(await _redisHandler.GetFromCache("Room:Rooms")); } else { data = await _roomRepository.GetAll(); } await Clients.All.SendAsync("Notify", data); await base.OnConnectedAsync(); }
public async Task <IActionResult> Insert([FromBody] Room room) { room.Id = Guid.NewGuid(); List <Room> rooms = new List <Room>(); if (await _redisHandler.IsCached("Room:Rooms")) { rooms = JsonConvert.DeserializeObject <List <Room> >(await _redisHandler.GetFromCache("Room:Rooms")); } rooms.Add(room); await _redisHandler.RemoveFromCache("Room:Rooms"); await _redisHandler.AddToCache("Room:Rooms", TimeSpan.FromMinutes(2), JsonConvert.SerializeObject(rooms)); await _hubContext.Clients.All.SendAsync("Notify", rooms); return(await Task.FromResult(Ok(room))); }