public async Task <IActionResult> InTime(TimeTrackerModel timeTrackerModel) { string user = User.FindFirst("Index").Value; var Currentuser = await _taskRepository.GetCurrentUser(user); ViewBag.photo = Currentuser.PhotoURL; timeTrackerModel.EmpId = Currentuser.EmpId; bool existOne = _timeTrackRepo.CheckIn(timeTrackerModel.EmpId); if (existOne) { return(RedirectToAction(nameof(Portal))); } else { JSONToViewModel model = new JSONToViewModel(); GeoHelper geoHelper = new GeoHelper(); var result = await geoHelper.GetGeoInfo(); model = JsonConvert.DeserializeObject <JSONToViewModel>(result); timeTrackerModel.Inlocation = model.City; timeTrackerModel.Inlatitude = model.Latitude; timeTrackerModel.InLongitude = model.Longitude; int id = await _timeTrackRepo.InTimeMark(timeTrackerModel); if (id > 0) { return(RedirectToAction(nameof(Portal))); } } return(View()); }
public async Task <IActionResult> OutTime(int id) { if (id == 0) { return(RedirectToAction(nameof(Portal), new { isFail = true })); } else { TimeTrackerModel timeTrackerModel = new TimeTrackerModel(); var track = await _context.TimeTracker.FindAsync(id); if (track.Status != "Break") { TimeSpan differ = (TimeSpan)(DateTime.Now - track.InTime); timeTrackerModel.TotalHours = differ.TotalHours; timeTrackerModel.TrackId = id; timeTrackerModel.WorkingHours = differ.TotalHours - track.BreakingHours; JSONToViewModel model = new JSONToViewModel(); GeoHelper geoHelper = new GeoHelper(); var result = await geoHelper.GetGeoInfo(); model = JsonConvert.DeserializeObject <JSONToViewModel>(result); timeTrackerModel.Outlocation = model.City; timeTrackerModel.Outlatitude = model.Latitude; timeTrackerModel.OutLongitude = model.Longitude; bool success = await _timeTrackRepo.UpdateTrack(timeTrackerModel); if (success == true) { return(RedirectToAction(nameof(Portal))); } } else { return(RedirectToAction(nameof(Portal), new { isEnd = true })); } } return(View()); }