public async Task <ObjectResult <LoginResult> > LoginAsync(LoginContract user) { ObjectResult <LoginResult> result = new ObjectResult <LoginResult>(); try { string _password = HelperMethod.encrypt(user.Password); var query = userRepository.GetTable.Where(d => d.Username.Equals(user.Username) && d.Password.Equals(_password)).AsQueryable(); var data = await userRepository.GetDataAsync(query); if (data != null) { ServiceResult loginResult = new ServiceResult(); loginResult.OK(); var loginQuery = userLoginRepository.GetTable.Where(d => d.UserName.Equals(user.Username) && d.DeviceID.Equals(user.DeviceID)).AsQueryable(); if (await userLoginRepository.GetCountAsync(loginQuery) == 0) { tUserLogin _loginData = new tUserLogin { UserLoginID = HelperMethod.GenerateID(), UserName = user.Username, DeviceID = user.DeviceID, Token = HelperMethod.GenerateID().ToString() }; var saveLogin = await userLoginRepository.AddAsync(_loginData); loginResult = saveLogin.status; } if (loginResult.succeeded) { var loginData = await userLoginRepository.GetDataAsync(loginQuery); result.obj = GetLoginResult(loginData); result.status.OK(); } else { result.status = loginResult; } } else { result.status.NotFound("Data Not Found"); } } catch (Exception ex) { result.status.Error("Error", ex.Message); } return(result); }