private UserOverview ParseHtml2(string htmlResult) { var document = new HtmlDocument(); document.LoadHtml(htmlResult); var user = new UserOverview(); HtmlNode mainTable = document.DocumentNode.SelectSingleNode("//*[@valign=\"top\"]"); try { var tableData = mainTable.Descendants("tr").Select(n => n.Elements("td").Select(e => e.InnerHtml).ToArray()); var userInfoData = tableData as string[][] ?? tableData.ToArray(); var badgenummer = userInfoData[0][3]; var stamnummer = userInfoData[1][1]; var name = userInfoData[2][1]; var firma = userInfoData[3][1]; user.Firma = GetValueAttribute(firma); user.Name = GetValueAttribute(name); user.Badge = GetValueAttribute(badgenummer); user.Id = int.Parse(GetValueAttribute(stamnummer)); } catch (Exception) { //throw; } return(user); }
/* Get information ABOUT USER include some detail like their reservation and how many time that they reserved*/ public UserOverview GetUserOverview(string id_account) { try { //find account var user = _dbContext.accounts.FirstOrDefault(x => x.Id_account == id_account); // ID,Name,point //if there is no account if (user == null) { return(null); } //if there is an account int usingCount = _dbContext.reservations.Count(x => x.Id_account == id_account && x.Status.ToLower() == "use"); //Using count //TimeUp+Expire count int timeUpCount = _dbContext.reservations.Count(x => x.Id_account == id_account && x.Status.ToLower() == "timeup") + _dbContext.reservations.Count(x => x.Id_account == id_account && x.Status.ToLower() == "expire"); //all reservation var reserve = _dbContext.reservations.Where(x => x.Id_account == id_account).OrderByDescending(x => x.DateModified); //create form for returning to administrator List <WebForm> tmp = new List <WebForm>(); foreach (var run in reserve) { string mac_address = _dbContext.vacancies.FirstOrDefault(x => x.Id_vacancy == run.Id_vacancy).Mac_address; string location = _dbContext.lockerMetadatas.FirstOrDefault(x => x.Mac_address == mac_address).Location; WebForm newby = new WebForm() { Status = run.Status, Id_booking = run.Id_reserve, Id_user = run.Id_account, Location = location, DateModified = run.DateModified }; tmp.Add(newby); } UserOverview overview = new UserOverview() { UserID = user.Id_account, Name = user.Name, Using = usingCount, TimeUp = timeUpCount, Point = user.Point, BookingList = tmp }; return(overview); } catch (Exception) { //error return(null); } }
public JsonResult GetUserOverview(string id_account) { TimeZoneInfo zone = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time"); DateTime dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, zone); UserOverview user = _accountRepo.GetUserOverview(id_account); //if there is user account return to this function if (user != null) { Log.Information("Get user overview from web {name}.", _dbContext.accounts.FirstOrDefault(x => x.Id_account == id_account).Name); return(Json(user)); } //if there is no user account return to this function else { Log.Information("Get user overview from web {id}.", id_account); return(Json(null)); } }
public ActionResult <UserOverview> GetUserOverview() { var overview = new UserOverview(); var user = _service.GetById(GetUserID()); if (user == null) { return(StatusCode(500, "User not found.")); } overview.Username = user.Name; var mostRecentWorkout = _executedWorkoutService.GetRecent(1); if (mostRecentWorkout.Any()) { overview.LastWorkoutDateTime = mostRecentWorkout.First().StartDateTime; } overview.PlannedWorkoutCount = _executedWorkoutService.GetPlannedCount(GetUserID()); return(Ok(overview)); }