public ActionResult register([FromBody] LoginDataItem loginData) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } UserItem user = _userDB.getUserByEmail(loginData.Email); if (user == null) { return(NotFound($"No UserItem found for Email: {loginData.Email}")); } UserDeviceItem device = _userDeviceDB.getDeviceByNameAndUser(user.UserID, loginData.DeviceName); if (device == null) { device = createNewUserDevice(loginData, user); } SessionItem session = _sessionDB.findExistingSession(user.UserID, device.DeviceID); if (session == null) { session = createNewSession(user, device); //Send mail _sendMailService.setUser(user); Thread thread = new Thread(() => _sendMailService.sendRegistrationMail(session)); thread.Start(); //mailHandler.sendRegistrationMail(session); return(Created("", session)); } return(Ok(session)); }