Exemplo n.º 1
0
        //Get all user log details
        public JsonResult GetAllLoggedInSessions(string userId)
        {
            FormsAuthenticationTicket ticket = null;

            try
            {
                _UserSessionLogBusinessLogic = new UserSessionLogBusinessLogic();
                _EncryptionModule            = new EncryptionModule();

                HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

                int decryptedUserId = userId == "0" ? 0 : Convert.ToInt32(_EncryptionModule.Decrypt(userId));

                if (authCookie != null)
                {
                    ticket = FormsAuthentication.Decrypt(authCookie.Value);



                    var userLogDetails = _UserSessionLogBusinessLogic.GetAllLoggedInSessions(decryptedUserId);

                    var userLogDetailsEncrypted = userLogDetails
                                                  .Select(ul => new
                    {
                        UserSessionLogId   = _EncryptionModule.Encrypt(ul.UserSessionLogId.ToString()),
                        UserId             = _EncryptionModule.Encrypt(ul.UserId.ToString()),
                        ProfilePicURL      = ul.ProfilePicURL,
                        Username           = ul.Username,
                        UserGroupName      = ul.UserGroupName,
                        UserFullName       = ul.UserFullName,
                        UserCallingName    = ul.UserCallingName,
                        IPAddress          = ul.IPAddress,
                        CountryCode        = ul.CountryCode,
                        Country            = ul.Country,
                        City               = ul.City,
                        Region             = ul.Region,
                        LoggedInTimestamp  = ul.LoggedInTimestamp,
                        LoggedOffTimestamp = ul.LoggedOffTimestamp
                    }).ToList();



                    return(Json(userLogDetailsEncrypted));
                }
                else
                {
                    return(Json(null));
                }
            }
            catch (Exception ex)
            {
                currentFile = this.ControllerContext.RouteData.Values["controller"].ToString(); // System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
                StackTrace st = new StackTrace();
                StackFrame sf = st.GetFrame(0);
                methodName = sf.GetMethod().Name;
                ErrorLogHelper.UpdatingErrorLog(currentFile + "-" + methodName, ticket == null ? "N/A" : ticket.Name, ex);
                return(Json(null));
            }
        }
        //Get all system users
        public JsonResult GetAllUsers()
        {
            FormsAuthenticationTicket ticket = null;

            try
            {
                _SystemUserDirectoryBusinessLogic = new SystemUserDirectoryBusinessLogic();

                HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

                if (authCookie != null)
                {
                    ticket = FormsAuthentication.Decrypt(authCookie.Value);

                    _EncryptionModule = new EncryptionModule();

                    var userDetails = _SystemUserDirectoryBusinessLogic.GetAllUsers();

                    var userDetailsEncrypted = userDetails
                                               .Select(u => new
                    {
                        UserId         = _EncryptionModule.Encrypt(u.UserId.ToString()),
                        UserGroupId    = u.UserGroupId,
                        ProfilePicURL  = u.ProfilePicURL,
                        Username       = u.Username,
                        UserGroupName  = u.UserGroupName,
                        FullName       = u.FullName,
                        CallingName    = u.CallingName,
                        Email          = u.Email,
                        IsActive       = u.IsActive,
                        IsLoggedIn     = u.IsLoggedIn,
                        LastLogInTime  = u.LastLogInTime,
                        LastLogOffTime = u.LastLogOffTime,
                    }).OrderBy(a => a.Username).ThenBy(a => a.FullName).ToList();



                    return(Json(userDetailsEncrypted));
                }
                else
                {
                    return(Json(null));
                }
            }
            catch (Exception ex)
            {
                currentFile = this.ControllerContext.RouteData.Values["controller"].ToString(); // System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
                StackTrace st = new StackTrace();
                StackFrame sf = st.GetFrame(0);
                methodName = sf.GetMethod().Name;
                ErrorLogHelper.UpdatingErrorLog(currentFile + "-" + methodName, ticket == null ? "N/A" : ticket.Name, ex);
                return(Json(null));
            }
        }