public async Task <ResponseViewModel <SystemFunctionViewModel> > GetUserPermission(int userID) { ResponseViewModel <SystemFunctionViewModel> response = new ResponseViewModel <SystemFunctionViewModel>(); Dictionary <string, SystemFunctionViewModel> systemFunctionViewModels = new Dictionary <string, SystemFunctionViewModel>(); var user = await _userRepository.GetAsync(us => us.ID == userID, QueryIncludes.USERFULLINCLUDES); if (user == null) { return(response = ResponseConstructor <SystemFunctionViewModel> .ConstructData(ResponseCode.ERR_USER_NOT_EXSIT, null)); } else { var employee = user.employees.FirstOrDefault(); foreach (var group in employee.groupMaps) { foreach (var function in group.employeeGroup.functionMaps) { try { systemFunctionViewModels.Add(function.systemFunction.Code, Mapper.Map <SystemFunction, SystemFunctionViewModel>(function.systemFunction)); } catch (Exception) { continue; } } } response = ResponseConstructor <SystemFunctionViewModel> .ConstructEnumerableData(ResponseCode.SUCCESS, systemFunctionViewModels.Values.ToList()); } return(response); }
public async Task <ResponseViewModel <GatePassViewModel> > GetGatePassByRFID(string rfidCode) { ResponseViewModel <GatePassViewModel> response; GatePass queryGatePassResult; GatePassViewModel gatePassViewModel; RFIDCard queryRFIDResult; if (_unitOfWork.Exists() == false) { response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_DB_CONNECTION_FAILED, null); } else { // Find RFID ID queryRFIDResult = await _rfidCardRepository.GetAsync(r => r.isDelete == false && r.code == rfidCode); if (queryRFIDResult == null) { // Not found RFID tag on Database response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_SEC_NOT_FOUND_RFID, null); } else { // Query Gatepass by RFID tag queryGatePassResult = await _gatePassRepository.GetAsync( g => g.isDelete == false && g.RFIDCardID == queryRFIDResult.ID, QueryIncludes.SECURITY_GATEPASS_INCLUDES); if (queryGatePassResult == null) { // Not Found Gatepass matched with RFID No response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_SEC_NOT_FOUND_GATEPASS, null); } else { // Found the GatePass gatePassViewModel = Mapper.Map <GatePass, GatePassViewModel>(queryGatePassResult); response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.SUCCESS, gatePassViewModel); } } } return(response); }
public async Task <ResponseViewModel <UserViewModel> > Login(LoginViewModel loginViewModel) { ResponseViewModel <UserViewModel> response = new ResponseViewModel <UserViewModel>(); var user = await _userRepository.GetAsync(u => u.username == loginViewModel.Email && u.isDelete == false, QueryIncludes.USERFULLINCLUDES); if (user == null) { return(response = ResponseConstructor <UserViewModel> .ConstructData(ResponseCode.ERR_USER_NOT_EXSIT, null)); } if (user.password != Crypt.ToSha256(loginViewModel.Password)) { return(response = ResponseConstructor <UserViewModel> .ConstructData(ResponseCode.ERR_INVALID_LOGIN, null)); } var token = this.GenerateToken(user.ID, user.username, user.password, loginViewModel.UserHostAddress, loginViewModel.UserAgent, DateTime.Now.Ticks); UserViewModel viewModel = Mapper.Map <User, UserViewModel>(user); viewModel.token = token; response = ResponseConstructor <UserViewModel> .ConstructData(ResponseCode.SUCCESS, viewModel); return(response); }
public async Task <ResponseViewModel <GatePassViewModel> > ConfirmSecurityCheck(SecurityUpdateStateViewModel updateStateView) { ResponseViewModel <GatePassViewModel> response; GatePass queryGatePassResult; GatePassViewModel gatePassViewModel; State queryStateResult; int tmpResponseCode; if (_unitOfWork.Exists() == false) { // Cound Not Connect to Database response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_DB_CONNECTION_FAILED, null); } else if (updateStateView == null) { // Wrong request format response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_SEC_WRONG_BODY_REQUEST_FORMAT, null); } else { // Get Queue by gatePassCode from database queryGatePassResult = await _gatePassRepository.GetAsync(q => q.isDelete == false && q.code == updateStateView.gatePassCode, QueryIncludes.SECURITY_GATEPASS_INCLUDES); // @TODO: Get permission of confirm RFID // bool isConfirmPermited = true; if (queryGatePassResult == null) { // Not found GatePass response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_SEC_NOT_FOUND_GATEPASS, null); } else if (queryGatePassResult.state == null) { // GatePass lacked "stateID" property response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_SEC_GATEPASS_LACK_STATEID, null); } else { // Found the GatePass and State if (isConfirmPermited == false) { // Not Permit tmpResponseCode = ResponseCode.ERR_SEC_WRONG_CONFIRMED_RFID; } else { // Check requested updated state switch (queryGatePassResult.state.ID) { case GatepassState.STATE_CALLING_1: case GatepassState.STATE_CALLING_2: case GatepassState.STATE_CALLING_3: case GatepassState.STATE_IN_SECURITY_CHECK_IN: // Get state ID of "Finish security check-in" queryStateResult = await _stateRepository.GetAsync(s => s.ID == GatepassState.STATE_FINISH_SECURITY_CHECK_IN); // STATE_SECURITY_CHECK_IN); // Updat gatepass/state queryGatePassResult.stateID = queryStateResult.ID; queryGatePassResult.enterTime = DateTime.Now; tmpResponseCode = ResponseCode.SUCCESS; break; case GatepassState.STATE_FINISH_WEIGHT_OUT: // Get state ID of "Finish security check-out" queryStateResult = await _stateRepository.GetAsync(s => s.ID == GatepassState.STATE_FINISH_SECURITY_CHECK_OUT); // STATE_SECURITY_CHECK_OUT); // Updat gatepass/state queryGatePassResult.stateID = queryStateResult.ID; queryGatePassResult.leaveTime = DateTime.Now; queryGatePassResult.isDelete = true; queryGatePassResult.queueLists.First().isDelete = true; if (queryGatePassResult.orders != null && queryGatePassResult.orders.Count > 0) { foreach (Order order in queryGatePassResult.orders) { order.isDelete = true; } } tmpResponseCode = ResponseCode.SUCCESS; break; default: // NOT SUPPORT STATE tmpResponseCode = ResponseCode.ERR_SEC_NOT_PERMIT_PASS_SECURITY_GATE; break; } } // Save on database _unitOfWork.SaveChanges(); // @TODO: Update state record // Re-query after changing queryGatePassResult = await _gatePassRepository.GetAsync(q => q.code == updateStateView.gatePassCode, QueryIncludes.SECURITY_GATEPASS_INCLUDES); gatePassViewModel = Mapper.Map <GatePass, GatePassViewModel>(queryGatePassResult); // Return gatepass/truck response = ResponseConstructor <GatePassViewModel> .ConstructData(tmpResponseCode, gatePassViewModel); } } return(response); }
public async Task <ResponseViewModel <GatePassViewModel> > RegisterSecurityCheck(string rfidCode) { ResponseViewModel <GatePassViewModel> response; GatePass queryGatePassResult; GatePassViewModel GatePassViewModel; RFIDCard queryRfidResult; int tmpResponseCode; if (_unitOfWork.Exists() == false) { // Cound Not Connect to Database response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_DB_CONNECTION_FAILED, null); } else { // Find RFID queryRfidResult = await _rfidCardRepository.GetAsync(r => r.isDelete == false && r.code == rfidCode); if (queryRfidResult == null) { // Not found RFID card ID response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_SEC_NOT_FOUND_RFID, null); } else { // Find GatePass queryGatePassResult = await _gatePassRepository.GetAsync( g => g.isDelete == false && g.RFIDCardID == queryRfidResult.ID, QueryIncludes.SECURITY_GATEPASS_INCLUDES); if (queryGatePassResult == null) { // Not Found Gatepass matched with RFID No response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_SEC_NOT_FOUND_GATEPASS, null); } else if (queryGatePassResult.state == null) { // GatePass lacked "stateID" property response = ResponseConstructor <GatePassViewModel> .ConstructData(ResponseCode.ERR_SEC_GATEPASS_LACK_STATEID, null); } else { // Check Truck state and Update its switch (queryGatePassResult.state.ID) { case GatepassState.STATE_CALLING_1: case GatepassState.STATE_CALLING_2: case GatepassState.STATE_CALLING_3: tmpResponseCode = ResponseCode.SUCCESS; break; case GatepassState.STATE_FINISH_WEIGHT_OUT: //STATE_WEIGHT_OUT: tmpResponseCode = ResponseCode.SUCCESS; break; default: tmpResponseCode = ResponseCode.ERR_SEC_NOT_PERMITTED_REG; break; } GatePassViewModel = Mapper.Map <GatePass, GatePassViewModel>(queryGatePassResult); // Return gatepass/truck response = ResponseConstructor <GatePassViewModel> .ConstructData(tmpResponseCode, GatePassViewModel); } } } return(response); }