예제 #1
0
        public bool ValidateUser(string SessionGUID)
        {
            IUserRepository _IUserRepository;
            _IUserRepository = new UserRepository(new WorkersInMotionDB());
            return (_IUserRepository.ValidateUser(SessionGUID));

        }
예제 #2
0
        public LoginResponse Login(LoginRequest pLoginRequest)
        {
            LoginResponse loginResponse = new LoginResponse();
            IUserRepository _IUserRepository;
            _IUserRepository = new UserRepository(new WorkersInMotionDB());

            //UserRepository lUserRepository = new UserRepository();


            // MasterLogin lMasterLogin = _IUserRepository.UserLogin(pLoginRequest.UserName, pLoginRequest.Password, pLoginRequest.IpAddress, pLoginRequest.Phone, pLoginRequest.DeviceID);
            //if (lMasterLogin != null && lMasterLogin.UserGUID != null && lMasterLogin.UserGUID != Guid.Empty)
            //{
            //    loginResponse.MasterLogin = lMasterLogin;
            //}
            return loginResponse;
        }
예제 #3
0
        private int CreateMasterLogin(MasterLogin pMasterLogin, ref string UpdatedSessionID)
        {
            int lResult;
            IUserRepository _IUserRepository = new UserRepository(new WorkersInMotionDB());
            MasterLogin lMasterLogin = new MasterLogin();
            lMasterLogin.LoginGUID = Guid.NewGuid();
            lMasterLogin.LoginType = pMasterLogin.LoginType;
            lMasterLogin.UserGUID = pMasterLogin.UserGUID;
            lMasterLogin.IsActive = true;
            lMasterLogin.SessionID = Guid.NewGuid().ToString();
            UpdatedSessionID = lMasterLogin.SessionID.ToString();
            lMasterLogin.ExpiryTime = pMasterLogin.ExpiryTime;
            lMasterLogin.SessionTimeOut = 60;
            lMasterLogin.IsLoggedIn = true;
            lMasterLogin.Phone = "";
            lMasterLogin.CreateDate = DateTime.UtcNow;
            lMasterLogin.CreateBy = pMasterLogin.UserGUID;
            lMasterLogin.LastModifiedDate = DateTime.UtcNow;
            lMasterLogin.LastModifiedBy = pMasterLogin.UserGUID;
            //_IUserRepository.InsertMasterLogin(lMasterLogin);
            if (_IUserRepository.InsertMasterLogin(lMasterLogin) > 0)
            {
                lResult = 1;
            }
            else
            {
                lResult = 0;

            }
            return lResult;
        }
예제 #4
0
 public Guid GetOrganizationGUID(string SessionGUID)
 {
     IUserRepository _IUserRepository;
     _IUserRepository = new UserRepository(new WorkersInMotionDB());
     return (_IUserRepository.GetOrganizationGUID(SessionGUID));
 }
예제 #5
0
 public System.Guid GetUserGUID(string SessionGUID)
 {
     IUserRepository _IUserRepository;
     _IUserRepository = new UserRepository(new WorkersInMotionDB());
     return (_IUserRepository.GetUserGUID(SessionGUID));
 }
예제 #6
0
        public DownloadUsers DownloadUsers(string SessionID, Nullable<System.Guid> UserGUID = null)
        {
            DownloadUsers lresponse = new DownloadUsers();
            IUserRepository _IUserRepository;
            _IUserRepository = new UserRepository(new WorkersInMotionDB());

            lresponse.UserRecords = _IUserRepository.DownloadUsers(SessionID, UserGUID);
            return lresponse;
        }
예제 #7
0
        public LoginResponse Login(LoginRequest pLoginRequest)
        {
            LoginResponse loginResponse = new LoginResponse();
            IUserRepository _IUserRepository;
            _IUserRepository = new UserRepository(new WorkersInMotionDB());
            string UpdatedSessionID = string.Empty;
            Logger.Debug("Inside UserLogin");
            LoginResponse lResponse = new LoginResponse();
            try
            {
                MasterLogin masterlogin = new MasterLogin();
                var aspuser = _IUserRepository.UserLogin(pLoginRequest.UserName, _IUserRepository.EncodeTo64(pLoginRequest.Password));
                if (aspuser != null)
                {
                    Logger.Debug("Inside Role");
                    AspNetRole asprole = _IUserRepository.GetRole(aspuser.Role_Id);
                    switch (asprole.UserType)
                    {
                        case "WIM_A":
                        case "ENT_A":
                        case "ENT_OM":
                        case "ENT_U_RM":
                        case "ENT_U_TM":
                            lResponse.Role = 1;
                            break;
                        case "ENT_U":
                            lResponse.Role = 2;
                            break;
                        case "IND_C":
                            lResponse.Role = 3;
                            break;
                        default:
                            break;
                    }

                    UserDevice userDevice = new UserDevice();
                    List<MasterLogin> masterlogins = new List<MasterLogin>();
                    MasterLogin lMasterLogin = new MasterLogin();
                    lMasterLogin.UserGUID = aspuser.UserGUID;
                    lMasterLogin.LoginType = (short)pLoginRequest.LoginType;
                    masterlogins = _IUserRepository.GetMasterLogin(lMasterLogin);
                    if (masterlogins != null && masterlogins.Count > 0)
                    {
                        #region masterlogins record available
                        masterlogin = masterlogins[0]; // Alok need to be fixed
                        // Update the Master Login
                        masterlogin.ExpiryTime = DateTime.UtcNow.AddYears(10);
                        Logger.Debug("Updating MasterLogin Record");
                        UpdatedSessionID = _IUserRepository.UpdateMasterLogin(masterlogin);
                        if (!string.IsNullOrEmpty(UpdatedSessionID))
                        {
                            #region UpdatedSessionID is not null

                            Logger.Debug("Updated Session ID: " + UpdatedSessionID);
                            lResponse.SessionID = UpdatedSessionID;
                            lResponse.UserGUID = aspuser.UserGUID.ToString();

                            Logger.Debug("Inside MasterLogin");
                            userDevice.LoginGUID = masterlogin.LoginGUID;
                            userDevice.DeviceID = pLoginRequest.DeviceInfo.deviceid;
                            List<UserDevice> lUserDevices = _IUserRepository.GetUserDevice(userDevice);
                            if (lUserDevices != null && lUserDevices.Count > 0)
                            {
                                // Delete the user device record
                                userDevice = lUserDevices[0]; // Need to modify Alok
                                int deviceresult = _IUserRepository.DeleteUserDevices(userDevice.UserDevicesGUID);
                                //int deviceresult = _IUserRepository.Save();
                                if (deviceresult <= 0)
                                {
                                    lResponse = null;
                                    return lResponse;
                                }
                            }
                            // Insert the User Device info
                            if (CreateUserDevice(masterlogin, pLoginRequest) > 0)
                            {
                                if (!string.IsNullOrEmpty(lResponse.SessionID) && !string.IsNullOrEmpty(lResponse.UserGUID))
                                {
                                    DownloadUsers lDownloadUsers = DownloadUsers(lResponse.SessionID, new Guid(lResponse.UserGUID));
                                    if (lDownloadUsers != null && lDownloadUsers.UserRecords.Count > 0)
                                        lResponse.UserRecord = lDownloadUsers.UserRecords[0];
                                    else
                                        lResponse.UserRecord = null;
                                }
                                Logger.Debug("UserDevice record created for updated Session ID: " + UpdatedSessionID);

                            }
                            #endregion
                        }
                        else
                        {
                            #region UpdatedSessionID is NULL
                            Logger.Error("Unable to generate Session ID");
                            lResponse = null;
                            return lResponse;
                            #endregion
                        }
                        #endregion
                    }
                    else
                    {
                        #region masterlogins record not available
                        Logger.Debug("Creating MasterLogin Record");
                        lMasterLogin.ExpiryTime = DateTime.UtcNow.AddYears(10);
                        if (CreateMasterLogin(lMasterLogin) > 0)
                        {
                            Logger.Debug("New Session ID: " + lMasterLogin.SessionID);
                            lResponse.SessionID = lMasterLogin.SessionID;
                            lResponse.UserGUID = lMasterLogin.UserGUID.ToString();
                            Logger.Debug("Inside UserDevice create");

                            if (CreateUserDevice(masterlogin, pLoginRequest) > 0)
                            {
                                if (!string.IsNullOrEmpty(lResponse.SessionID) && !string.IsNullOrEmpty(lResponse.UserGUID))
                                {
                                    DownloadUsers lDownloadUsers = DownloadUsers(lResponse.SessionID, new Guid(lResponse.UserGUID));
                                    if (lDownloadUsers != null && lDownloadUsers.UserRecords.Count > 0)
                                        lResponse.UserRecord = lDownloadUsers.UserRecords[0];
                                    else
                                        lResponse.UserRecord = null;
                                }
                                Logger.Debug("UserDevice record created for new Session ID: " + lMasterLogin.SessionID);
                            }
                            else
                            {
                                Logger.Error("Unable to craete UserDevice record for new Session ID: " + lMasterLogin.SessionID);
                                lResponse = null;
                            }
                        }
                        else
                        {
                            Logger.Error("Unable to craete MasterLogin record");
                            lResponse = null;
                        }
                        #endregion
                    }
                }
                else
                {
                    Logger.Error("Unable to find user record in  AspUser");
                    lResponse = null;
                }
                return lResponse;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                lResponse = null;
                //lResponse.SessionID = new WorkersInMotionDB().Database.Connection.ConnectionString + " Exception: " + ex.Message;
                return lResponse;
            }

        }
예제 #8
0
        public LocationResponse GetUserLocation(Guid WorkerID)
        {
            LocationResponse lresponse = new LocationResponse();
            IUserRepository _IUserRepository;
            _IUserRepository = new UserRepository(new WorkersInMotionDB());
            UserHeartBeat UserHeartBeatList = _IUserRepository.GetUserLocation(WorkerID);

            if (UserHeartBeatList != null)
            {
                lresponse.Latitude = Convert.ToDouble(UserHeartBeatList.Latitude);
                lresponse.Longitude = Convert.ToDouble(UserHeartBeatList.Longitude);
                lresponse.Time = convertdate(Convert.ToDateTime(UserHeartBeatList.HeartBeatTime));// Convert.ToDateTime(item.HeartBeatTime);
                lresponse.UserGUID = UserHeartBeatList.UserGUID;

            }
            return lresponse;
        }
예제 #9
0
        public int PostHeartBeat(HeartBeatRequest HeartBeatRequest, Guid UserGUID)
        {
            try
            {
                int result = 0;
                IUserRepository _IUserRepository;
                _IUserRepository = new UserRepository(new WorkersInMotionDB());
                UserHeartBeat _userHeartBeat = new UserHeartBeat();
                _userHeartBeat.HeartBeatGUID = Guid.NewGuid();
                _userHeartBeat.UserGUID = UserGUID;
                _userHeartBeat.Latitude = HeartBeatRequest.latitude;
                _userHeartBeat.Longitude = HeartBeatRequest.longitude;
                _userHeartBeat.HeartBeatTime = HeartBeatRequest.time;
                _userHeartBeat.CreateDate = DateTime.UtcNow;
                _userHeartBeat.CreateBy = UserGUID;
                result = _IUserRepository.InsertUserHeartBeat(_userHeartBeat);
                //result = _IUserRepository.Save();
                return result;
            }
            catch (Exception ex)
            {
                return 0;
            }

        }
예제 #10
0
 public CreateAccountResponse CreateAccount(LoginRequest pLoginRequest)
 {
     CreateAccountResponse CreateAccountResponse = new CreateAccountResponse();
     IUserRepository _IUserRepository;
     _IUserRepository = new UserRepository(new WorkersInMotionDB());
     IGlobalUserRepository _IGlobalUserRepository;
     _IGlobalUserRepository = new GlobalUserRepository(new WorkersInMotionDB());
     IUserProfileRepository _IUserProfileRepository;
     _IUserProfileRepository = new UserProfileRepository(new WorkersInMotionDB());
     int lRetVal = _IUserRepository.CheckUserName(pLoginRequest.UserName);
     if (lRetVal == 0)
     {
         GlobalUser _globalUser = new GlobalUser();
         _globalUser.UserGUID = Guid.NewGuid();
         _globalUser.UserName = pLoginRequest.UserName;
         _globalUser.Password = pLoginRequest.Password;
         _globalUser.Role_Id = _IGlobalUserRepository.GetRoleID("IND_C");
         _globalUser.IsActive = true;
         _globalUser.IsDelete = false;
         _globalUser.CreateDate = DateTime.UtcNow;
         _globalUser.CreateBy = _globalUser.UserGUID;
         _globalUser.LastModifiedDate = DateTime.UtcNow;
         _globalUser.LastModifiedBy = _globalUser.UserGUID;
         int result = _IGlobalUserRepository.InsertGlobalUser(_globalUser);
         //int result = _IGlobalUserRepository.Save();
         if (result > 0)
         {
             UserProfile _userProfile = new UserProfile();
             _userProfile.ProfileGUID = Guid.NewGuid();
             _userProfile.UserGUID = _globalUser.UserGUID;
             _userProfile.FirstName = _globalUser.UserName;
             _userProfile.LastModifiedDate = DateTime.UtcNow;
             _userProfile.LastModifiedBy = _globalUser.UserGUID;
             int resprofileInsert = _IUserProfileRepository.InsertUserProfile(_userProfile);
             //int resprofileInsert = _IUserProfileRepository.Save();
             if (resprofileInsert > 0)
             {
                 CreateAccountResponse.Role = 2;
                 CreateAccountResponse.UserGUID = _userProfile.UserGUID.ToString();
             }
             else
             {
                 _IGlobalUserRepository.DeleteGlobalUser(_globalUser.UserGUID);
                 //_IGlobalUserRepository.Save();
                 CreateAccountResponse = null;
             }
         }
         else
         {
             CreateAccountResponse = null;
         }
         return CreateAccountResponse;
     }
     else
     {
         return null;
     }
 }
예제 #11
0
        private int CreateUserDevice(MasterLogin pMasterLogin, LoginRequest pLoginRequest)
        {
            int lResult;
            IUserRepository _IUserRepository = new UserRepository(new WorkersInMotionDB());
            UserDevice lUserDevice = new UserDevice();
            lUserDevice.UserDevicesGUID = Guid.NewGuid();
            lUserDevice.LoginGUID = pMasterLogin.LoginGUID;
            lUserDevice.UserGUID = pMasterLogin.UserGUID;
            lUserDevice.IPAddress = pLoginRequest.DeviceInfo.deviceipaddress;
            lUserDevice.DeviceID = pLoginRequest.DeviceInfo.deviceid;
            lUserDevice.DeviceInfo = new JavaScriptSerializer().Serialize(pLoginRequest.DeviceInfo);
            lUserDevice.DeviceType = pLoginRequest.DeviceInfo.devicetype;
            lUserDevice.PUSHID = pLoginRequest.PushID;
            lUserDevice.Phone = pMasterLogin.Phone;
            lUserDevice.IsActive = true;
            lUserDevice.TimeZone = pLoginRequest.DeviceInfo.TimeZone;
            lUserDevice.CreateDate = DateTime.UtcNow;
            lUserDevice.CreateBy = pMasterLogin.UserGUID;
            lUserDevice.LastModifiedDate = DateTime.UtcNow;
            lUserDevice.LastModifiedBy = pMasterLogin.UserGUID;
            // _IUserRepository.InsertUserDevice(lUserDevice);
            if (_IUserRepository.InsertUserDevice(lUserDevice) > 0)
            {
                lResult = 1;
            }
            else
            {
                lResult = 0;

            }
            return lResult;
        }