public async Task <IActionResult> CheckIn([FromBody] CheckInOrOutModel model) { var result = new Result <string>(); try { var Org = _ablemusicContext.Org.FirstOrDefault(s => Math.Sqrt(Convert.ToDouble((s.LocaltionX - model.LocaltionX) * (s.LocaltionX - model.LocaltionX) + (s.LocaltionY - model.LocaltionY) * (s.LocaltionY - model.LocaltionY))) <= 0.003 ); if (Org == null) { throw new Exception("Check in failed. 你必须在校区列表里随便一个校区的300米内"); } var newLogLog = new LoginLog { UserId = model.UserId, LogType = 1, CreatedAt = DateTime.UtcNow.AddHours(12), OrgId = Org.OrgId }; _ablemusicContext.Add(newLogLog); await _ablemusicContext.SaveChangesAsync(); result.Data = "Check in successfully."; return(Ok(result)); } catch (Exception ex) { result.IsSuccess = false; result.ErrorMessage = ex.Message; return(BadRequest(result)); } }
public async Task <IActionResult> CheckOut(CheckInOrOutModel model) { var result = new Result <string>(); try { var checkInDetail = _ablemusicContext.LoginLog.Where(s => s.CreatedAt.Value.Day == DateTime.UtcNow.AddHours(12).Day&& s.CreatedAt.Value.Month == DateTime.UtcNow.AddHours(12).Month&& s.CreatedAt.Value.Year == DateTime.UtcNow.AddHours(12).Year&& s.LogType == 1).Include(s => s.Org); if (checkInDetail.IsNullOrEmpty()) { throw new Exception("你今天没打卡 不存在登出"); } var Org = checkInDetail.FirstOrDefault(s => Math.Sqrt(Convert.ToDouble((s.Org.LocaltionX - model.LocaltionX) * (s.Org.LocaltionX - model.LocaltionX) + (s.Org.LocaltionY - model.LocaltionY) * (s.Org.LocaltionY - model.LocaltionY))) <= 0.003 ); if (Org == null) { throw new Exception("你不在今天打卡的地方里登出"); } var newLogLog = new LoginLog { UserId = model.UserId, LogType = 0, CreatedAt = DateTime.UtcNow.AddHours(12), OrgId = Org.OrgId }; _ablemusicContext.Add(newLogLog); await _ablemusicContext.SaveChangesAsync(); result.Data = "Check out successfully."; return(Ok(result)); } catch (Exception ex) { result.IsSuccess = false; result.ErrorMessage = ex.Message; return(BadRequest(result)); } }