public async Task <UserLogin> Login(string username, string password) { var employeecode = await _context.Employee.Where(c => c.EmployeeCode == username).Select(c => c.Id).FirstOrDefaultAsync(); // var login = await _context.UserLogin.FirstOrDefaultAsync(x => x.UserId == Int32.Parse(username)); var login = await _context.UserLogin.FirstOrDefaultAsync(x => x.UserId == employeecode); if (login == null) { return(null); } if (!VerifyPasswordHash(password, login.PasswordHash, login.PasswordSalt)) { return(null); } login.LastLogin = DateTime.UtcNow; _context.Update(login); await _context.SaveChangesAsync(); //auth sukses return(login); }
public async Task<IActionResult> getStore(String storeCode, String deviceId) { if (deviceId != null) { bool deviceaidi = _context.DeviceTable.Any(x => x.DeviceId == deviceId); if (!deviceaidi) { DeviceTable dtnew = new DeviceTable(); var check = _context.DeviceTable.LastOrDefault(); if (check == null) { dtnew.InitialId = "AAA"; } else { string ddv = check.InitialId; ddv = getGet(ddv); dtnew.InitialId = ddv; } dtnew.FirstLogin = DateTime.Now.ToString(); dtnew.TypeDevice = "POS"; dtnew.DeviceId = deviceId; _context.DeviceTable.Add(dtnew); _context.SaveChanges(); } else { DeviceTable tab = _context.DeviceTable.Where(x => x.DeviceId == deviceId).First(); tab.LastLogin = DateTime.Now.ToString(); _context.Update(tab); _context.SaveChanges(); } } StoreData storeData = new StoreData(); if (_context.Store.Any(c => c.Code == storeCode)) { // if (employee == null) // { // return NotFound(); // } try { Store store = _context.Store.Where(c => c.Code == storeCode).First(); try { storeData.deviceCode = _context.DeviceTable.Where(x => x.DeviceId == deviceId).First().InitialId; } catch { storeData.deviceCode = ""; } try { storeData.store = masterStore(store.Id); } catch { } try { storeData.warehouse = masterWarehose(_context.Store.Where(c => c.Id == store.Id).First().Code); } catch { } try { storeData.banks = masterBanks(store.Id); } catch { } try { storeData.employees = masterEmployee(store.Id); } catch (Exception) { } try { storeData.currency = masterCurrency("IDR"); } catch (Exception) { } try { storeData.budgetStore = this.budgetStore(storeCode); } catch { } } catch (Exception ex) { return Ok(ex.ToString()); } } return Ok(storeData); }