Ejemplo n.º 1
0
        public static String CheckUserFrofile(String LoginID, String PWD, Int32 userID = 0)
        {
            String result = "Invalid Login ID or Password ";

            var userInfo = (from U in db.USP_Login(LoginID, PWD, true)
                            select new
            {
                UserID = U.user_id,
                IsActive = U.is_active,
                CompanyActive = U.CompanyActive,
                FullName = U.user_name,
                LoginID = U.email_id,
                Email = U.email_id,
                gender = U.gender,
                Mobile = U.mobile,
                RoleBit = U.role_bit,
                RoleName = U.role_name,
                RoleID = U.role_id,
                CompanyID = U.company_id,
                CompanyName = U.business_name,
                CompanyFolderName = U.company_folder_name,
                company_logo = U.company_logo,

                time_zone = U.time_zone,
                currency_id = (int)U.currency_id,
                currency_name = U.currency_name,
                currency_symbol = U.currency_symbol,
                date_format_id = (int)U.date_format_id,
                date_format_name = U.date_format_name,
                date_format_code_csharp = U.date_format_code_csharp,
                date_format_code_js = U.date_format_code_js,
                time_format_id = (int)U.time_format_id,
                time_format_name = U.time_format_name,
                time_format_code_csharp = U.time_format_code_csharp,
                time_format_code_js = U.time_format_code_js,

                Photo = U.user_photo,

                last_login_date = U.last_login_date,
                password_failed_attempt = U.password_failed_attempt,
                is_account_locked = U.is_account_locked,

                system_company_folder = U.system_company_folder,
                company_doc_file_name = U.company_doc_file_name,

                create_work_order_access_id = U.create_work_order_access_id,
                view_work_order_access_id = U.view_work_order_access_id,
                is_change_requester = U.is_change_requester,
                is_service_provider = U.is_service_provider,

                theme_color = U.theme_color,
            }).FirstOrDefault();

            #region AutoLogin By UserID


            if (userID > 0)
            {
                userInfo = (from U in db.users.AsEnumerable()
                            join C in db.companies.AsEnumerable() on U.company_id equals C.company_id
                            join R in db.roles.AsEnumerable() on U.role_bit equals R.role_bit
                            join CU in db.currencies.AsEnumerable() on C.currency_id equals CU.currency_id into curr
                            from CU in curr.DefaultIfEmpty()
                            join DF in db.date_format.AsEnumerable() on C.date_format_id equals DF.date_format_id into DateFo
                            from DF in DateFo.DefaultIfEmpty()
                            join TF in db.time_format.AsEnumerable() on C.time_format_id equals TF.time_format_id into TimeFo
                            from TF in TimeFo.DefaultIfEmpty()
                            where U.user_id == userID
                            select new
                {
                    UserID = U.user_id,
                    IsActive = U.is_active,
                    CompanyActive = C.is_active,
                    FullName = U.user_name,
                    LoginID = U.email_id,
                    Email = U.email_id,
                    gender = U.gender,
                    Mobile = U.mobile,
                    RoleBit = U.role_bit,
                    RoleName = R.role_name,
                    RoleID = R.role_id,

                    CompanyID = U.company_id,
                    CompanyName = C.business_name,
                    CompanyFolderName = C.company_folder_name,
                    company_logo = C.company_logo,

                    time_zone = C.time_zone,
                    currency_id = CU != null ? CU.currency_id : 0,
                    currency_name = CU != null ? CU.currency_name : "",
                    currency_symbol = CU != null ? CU.currency_symbol : "",

                    date_format_id = DF != null ? DF.date_format_id : 0,
                    date_format_name = DF != null ? DF.date_format_name : "",
                    date_format_code_csharp = DF != null ? DF.date_format_code_csharp : "",
                    date_format_code_js = DF != null ? DF.date_format_code_js : "",

                    time_format_id = TF != null ? TF.time_format_id : 0,
                    time_format_name = TF != null ? TF.time_format_name : "",
                    time_format_code_csharp = TF != null ? TF.time_format_code_csharp : "",
                    time_format_code_js = TF != null ? TF.time_format_code_js : "",

                    Photo = U.user_photo,

                    last_login_date = U.last_login_date,
                    password_failed_attempt = U.password_failed_attempt,
                    is_account_locked = U.is_account_locked,

                    system_company_folder = C.system_company_folder,
                    company_doc_file_name = C.company_doc_file_name,

                    create_work_order_access_id = U.create_work_order_access_id,
                    view_work_order_access_id = U.view_work_order_access_id,
                    is_change_requester = U.is_change_requester,
                    is_service_provider = U.is_service_provider,

                    theme_color = U.theme_color_id == null ? C.theme_color.theme_css : U.theme_color.theme_css,
                }).FirstOrDefault();
            }
            #endregion
            if (userInfo == null)
            {
                var userRecord = (from U in db.users
                                  join C in db.companies on U.company_id equals C.company_id
                                  where (U.login_id == LoginID)
                                  select U).FirstOrDefault();
                if (userRecord != null)
                {
                    result = STUtil.UserLoginPolicy(userRecord.user_id, true);
                }
            }
            try
            {
                if (userInfo != null)
                {
                    if (userInfo.is_account_locked)
                    {
                        result = "Your acount has been locked. Due to multiple invalid password ! Please contact to Admin";
                    }
                    else
                    {
                        if (userInfo.IsActive)
                        {
                            STUtil.SetSessionValue(UserInfo.UserID.ToString(), Convert.ToString(userInfo.UserID));
                            STUtil.SetSessionValue(UserInfo.FullName.ToString(), Convert.ToString(userInfo.FullName));

                            STUtil.SetSessionValue(UserInfo.LoginID.ToString(), Convert.ToString(userInfo.LoginID));
                            STUtil.SetSessionValue(UserInfo.EmailID.ToString(), Convert.ToString(userInfo.Email));
                            STUtil.SetSessionValue(UserInfo.Mobile.ToString(), Convert.ToString(userInfo.Mobile));
                            STUtil.SetSessionValue(UserInfo.RoleBit.ToString(), Convert.ToString(userInfo.RoleBit));
                            STUtil.SetSessionValue(UserInfo.RoleID.ToString(), Convert.ToString(userInfo.RoleID));
                            STUtil.SetSessionValue(UserInfo.RoleName.ToString(), Convert.ToString(userInfo.RoleName));
                            STUtil.SetSessionValue(UserInfo.CompanyID.ToString(), Convert.ToString(userInfo.CompanyID));

                            STUtil.SetSessionValue(UserInfo.CompanyName.ToString(), Convert.ToString(userInfo.CompanyName));
                            STUtil.SetSessionValue(UserInfo.CompanyFolderName.ToString(), Convert.ToString(userInfo.CompanyFolderName));
                            STUtil.SetSessionValue(UserInfo.CompanyLogo.ToString(), Convert.ToString(userInfo.company_logo));

                            STUtil.SetSessionValue(UserInfo.UserPhoto.ToString(), Convert.ToString(userInfo.Photo));
                            STUtil.SetSessionValue(UserInfo.Gender.ToString(), Convert.ToString(userInfo.gender.ToUpper()));

                            STUtil.SetSessionValue(UserInfo.time_zone.ToString(), Convert.ToString(userInfo.time_zone));

                            STUtil.SetSessionValue(UserInfo.currency_id.ToString(), Convert.ToString(userInfo.currency_id));
                            STUtil.SetSessionValue(UserInfo.currency_name.ToString(), Convert.ToString(userInfo.currency_name));
                            STUtil.SetSessionValue(UserInfo.currency_symbol.ToString(), Convert.ToString(userInfo.currency_symbol));

                            STUtil.SetSessionValue(UserInfo.date_format_id.ToString(), Convert.ToString(userInfo.date_format_id));
                            STUtil.SetSessionValue(UserInfo.date_format_name.ToString(), Convert.ToString(userInfo.date_format_name));
                            STUtil.SetSessionValue(UserInfo.date_format_code_csharp.ToString(), Convert.ToString(userInfo.date_format_code_csharp));
                            STUtil.SetSessionValue(UserInfo.date_format_code_js.ToString(), Convert.ToString(userInfo.date_format_code_js));

                            STUtil.SetSessionValue(UserInfo.time_format_id.ToString(), Convert.ToString(userInfo.time_format_id));
                            STUtil.SetSessionValue(UserInfo.time_format_name.ToString(), Convert.ToString(userInfo.time_format_name));
                            STUtil.SetSessionValue(UserInfo.time_format_code_csharp.ToString(), Convert.ToString(userInfo.time_format_code_csharp));
                            STUtil.SetSessionValue(UserInfo.time_format_code_js.ToString(), Convert.ToString(userInfo.time_format_code_js));

                            STUtil.SetSessionValue(UserInfo.system_company_folder.ToString(), Convert.ToString(userInfo.system_company_folder));

                            STUtil.SetSessionValue(UserInfo.company_doc_file_name.ToString(), Convert.ToString(userInfo.company_doc_file_name));

                            STUtil.SetSessionValue(UserInfo.create_work_order_access_id.ToString(), Convert.ToString(userInfo.create_work_order_access_id));
                            STUtil.SetSessionValue(UserInfo.view_work_order_access_id.ToString(), Convert.ToString(userInfo.view_work_order_access_id));
                            STUtil.SetSessionValue(UserInfo.is_change_requester.ToString(), Convert.ToString(userInfo.is_change_requester));
                            STUtil.SetSessionValue(UserInfo.is_service_provider.ToString(), Convert.ToString(userInfo.is_service_provider));

                            STUtil.SetSessionValue(UserInfo.theme_color.ToString(), Convert.ToString(userInfo.theme_color));

                            STUtil.SetSessionValue(UserInfo.SERVER_TIME_ZONE.ToString(), STUtil.GetWebConfigValue("SERVER_TIME_ZONE"));

                            STUtil.SetSessionValue(UserInfo.SuperAdmin.ToString(), Convert.ToString(RoleUtil.IsInRole(Role.SuperAdmin, userInfo.RoleBit)));

                            STUtil.SetSessionValue(UserInfo.IsCompanySetup.ToString(), "1");
                            //STUtil.SetSessionValue(UserInfo.IsCompanySetup.ToString(), string.IsNullOrEmpty(userInfo.time_zone) ? "0" : "1");
                            //STUtil.SetSessionValue(UserInfo.IsCompanySetup.ToString(), string.IsNullOrEmpty(userInfo.currency_name) ? "0" : "1");
                            //STUtil.SetSessionValue(UserInfo.IsCompanySetup.ToString(), string.IsNullOrEmpty(userInfo.time_format_name) ? "0" : "1");
                            //STUtil.SetSessionValue(UserInfo.IsCompanySetup.ToString(), string.IsNullOrEmpty(userInfo.date_format_name) ? "0" : "1");
                            //STUtil.SetSessionValue(UserInfo.IsCompanySetup.ToString(), string.IsNullOrEmpty(userInfo.system_company_folder) ? "0" : "1");
                            //STUtil.SetSessionValue(UserInfo.IsCompanySetup.ToString(), userInfo.default_contact_id == null ? "0" : "1");

                            STUtil.SetSessionValue(UserInfo.IsCompanyAddUpdate.ToString(), "1");

                            //STUtil.SetSessionValue(UserInfo.Admin.ToString(), Convert.ToString(RoleUtil.IsInRole(Role.Admin, userInfo.RoleBit)));
                            //STUtil.SetSessionValue(UserInfo.CRMExecutive.ToString(), Convert.ToString(RoleUtil.IsInRole(Role.CRMExecutive, userInfo.RoleBit)));
                            //STUtil.SetSessionValue(UserInfo.Account.ToString(), Convert.ToString(RoleUtil.IsInRole(Role.Account, userInfo.RoleBit)));
                            //STUtil.SetSessionValue(UserInfo.Manager.ToString(), Convert.ToString(RoleUtil.IsInRole(Role.Manager, userInfo.RoleBit)));
                            //STUtil.SetSessionValue(UserInfo.Agent.ToString(), Convert.ToString(RoleUtil.IsInRole(Role.Agent, userInfo.RoleBit)));


                            STUtil.UserLoginPolicy(userInfo.UserID, false);
                            result = "PASS";
                        }
                        else
                        {
                            result = !userInfo.IsActive ? "Your are Inactive! Please contact to Admin" : String.Empty;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
                //// ExceptionLogging.SendErrorToText(ex);
            }

            return(result);
        }