public IHttpActionResult UpdateUsersStatus([FromBody] TimeSpan isNowOfflineTimeLimit) { s_log.LogInfo($@"{nameof(UpdateUsersStatus)}({isNowOfflineTimeLimit}) is called"); Console.WriteLine($@"{nameof(UpdateUsersStatus)}({isNowOfflineTimeLimit}) is called"); var timeLimitToExceed = DateTimeOffset.Now - isNowOfflineTimeLimit; var notOfflineUsers = _userDataProvider.GetAllNotOfflineUsers(); if (notOfflineUsers == null || notOfflineUsers.Count == 0) { return(Ok(false)); } foreach (var user in notOfflineUsers) { if (user.LastActiveDate < timeLimitToExceed) { var result = _userDataProvider.UpdateUserStatus(user.Id, 0); if (result == 0) { return(Ok(false)); } } } return(Ok(true)); }
private static void UpdateUserStatus() { var timeLimitToExceed = DateTimeOffset.Now - s_isNowOfflineTimeLimit; foreach (var user in s_userDataProvider.GetAllNotOfflineUsers()) { if (user.LastActiveDate < timeLimitToExceed) { s_userDataProvider.UpdateUserStatus(user.Id, 0); } } }
public IHttpActionResult UpdateActivityStatus([FromBody] CActivityStatusDto currentStatus) { s_log.LogInfo($"{System.Reflection.MethodBase.GetCurrentMethod()}({currentStatus}) is called"); if (currentStatus == null) { s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({(CActivityStatusDto)null})", new ArgumentNullException(nameof(currentStatus), "Incoming data is null")); ModelState.AddModelError($"{nameof(currentStatus)}", "Incoming data is null"); return(BadRequest(ModelState)); } Int32 result = _userDataProvider.UpdateUserStatus(currentStatus.UserId, currentStatus.ActivityStatus); if (result == 0) { s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({currentStatus})", new Exception("Failed to update user status")); return(NotFound()); } return(Ok(true)); }