public async Task <TimestampResponseModel> ClockOutAsync(TimestampModel model) { var response = new TimestampResponseModel(); var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { response.Succeeded = false; response.Message = "No User Found"; return(response); } // Find an active timestamp var timestamp = user.Timestamps.Single(timestamp => timestamp.IsActive); if (timestamp == null) { response.Succeeded = false; response.Message = "No Active Timestamp"; return(response); } timestamp.IsActive = false; timestamp.Out = model.ClockTime; timestamp.OutWhileOnPremises = IsEmployeeOnPremises(model.ClockLocation); _context.Update(user); _context.SaveChanges(); // Generate a response for the user response.Succeeded = true; response.Message = "Clocked out successfully"; return(response); }
public async Task <TimestampResponseModel> ClockInAsync(TimestampModel model) { var response = new TimestampResponseModel(); // Use the email to get the user object from the database var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { response.Succeeded = false; response.Message = "User Not Found"; return(response); } // Create a timestamp object and add it to the list associated with the user's var timestamp = new Timestamp { In = model.ClockTime, InWhileOnPremises = IsEmployeeOnPremises(model.ClockLocation), IsActive = true }; user.Timestamps.Add(timestamp); _context.Update(user); _context.SaveChanges(); // Generate a response for the user response.Succeeded = true; response.Message = "Clocked in successfully"; return(response); }
public async Task <IActionResult> ClockOutAsync(TimestampModel model) { var result = await _userService.ClockOutAsync(model); return(Ok(result)); }