public static ProfileViewModel GetUserProfileByUsername(string username, int languageId) { using (var db = new CrmSystemEntities()) { try { var userProfile = db.UserProfileTranslations.Where(r => r.UserProfile.Username == username && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted && r.LanguageId == languageId) .ToList().Select(x => new ProfileViewModel() { Id = x.UserProfileId, LanguageId = x.LanguageId, IdNumber = x.UserProfile.IdNumber, PhoneNumber = x.UserProfile.PhoneNumber, GenderLookupId = x.UserProfile.GenderLookupId, MartialStatusLookupId = x.UserProfile.MartialStatusLookupId, FullName = x.FullName, Address = x.Address, Mobile = x.UserProfile.Mobile, Email = x.UserProfile.Username, Fax = x.UserProfile.Fax, BirthDay = x.UserProfile.Birthday, Status = x.UserProfile.Status, CityId = x.UserProfile.CityId, ProfilePath = x.UserProfile.ProfilePhoto, ProvinceId = x.UserProfile.ProvinceId, RegionId = x.UserProfile.RegionId, LastLogin = x.UserProfile.LastLogin, ManagerId = x.UserProfile.ManagerId, Username = x.UserProfile.Username, Department = x.UserProfile.DepartmentId, DepartmentName = x.UserProfile?.DepartmentId != null ? LanguageFallbackHelper.GetDepartment((int)x.UserProfile.DepartmentId, languageId)?.Name : string.Empty, PrefferdLanguage = x.UserProfile.PreferedLanguageId }).FirstOrDefault(); if (userProfile == null) { userProfile = db.UserProfiles.Where(r => r.UserProfileTranslations.Any(x => x.IsDefault) && r.Username == username && r.Status == (int)GeneralEnums.StatusEnum.Active).ToList() .SelectMany(r => r.UserProfileTranslations).Select(x => new ProfileViewModel() { Id = x.UserProfileId, LanguageId = x.LanguageId, IdNumber = x.UserProfile.IdNumber, PhoneNumber = x.UserProfile.PhoneNumber, GenderLookupId = x.UserProfile.GenderLookupId, MartialStatusLookupId = x.UserProfile.MartialStatusLookupId, FullName = x.FullName, ProfilePath = x.UserProfile.ProfilePhoto, Address = x.Address, Mobile = x.UserProfile.Mobile, Email = x.UserProfile.Username, Fax = x.UserProfile.Fax, BirthDay = x.UserProfile.Birthday, Status = x.UserProfile.Status, CityId = x.UserProfile.CityId, ProvinceId = x.UserProfile.ProvinceId, RegionId = x.UserProfile.RegionId, LastLogin = x.UserProfile.LastLogin, ManagerId = x.UserProfile.ManagerId, Department = x.UserProfile.DepartmentId, DepartmentName = x.UserProfile?.DepartmentId != null ? LanguageFallbackHelper.GetDepartment((int)x.UserProfile.DepartmentId, languageId)?.Name : string.Empty, PrefferdLanguage = x.UserProfile.PreferedLanguageId }).FirstOrDefault(); } return(userProfile); } catch (Exception ex) { LogHelper.LogException("", ex, "Error While Getting UserProfile by username"); return(new ProfileViewModel()); } } }
public static List <ProfileViewModel> GetEmployees(HttpCookie cookie) { using (var db = new CrmSystemEntities()) { try { int languageId = (int)GeneralEnums.LanguageEnum.Arabic; if (cookie != null) { var languageName = CultureHelper.GetCultureName(cookie); languageId = CultureHelper.MapLanguage(languageName); } var companyId = SessionHelper.GetCompanyId(); var employees = db.AspNetUserRoles.Where(r => r.AspNetRole.Name != Constants.Roles.Citizen) .Select(r => r.AspNetUser.UserName).ToList(); var profilesForcurrentLan = db.UserProfileTranslations .Where(r => (r.LanguageId == languageId) && employees.Contains(r.UserProfile.Username) && r.UserProfile.CompanyId == companyId && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted).Select(c => c.UserProfileId); var profiles = db.UserProfileTranslations .Where(r => (r.IsDefault) && employees.Contains(r.UserProfile.Username) && r.UserProfile.CompanyId == companyId && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted && !profilesForcurrentLan.Contains(r.UserProfileId)) .Union( db.UserProfileTranslations .Where(r => r.LanguageId == languageId && r.UserProfile.CompanyId == companyId && employees.Contains(r.UserProfile.Username) && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted && profilesForcurrentLan.Contains(r.UserProfileId))) .ToList().Select(x => new ProfileViewModel() { Id = x.UserProfileId, LanguageId = x.LanguageId, IdNumber = x.UserProfile.IdNumber, PhoneNumber = x.UserProfile.PhoneNumber, GenderLookupId = x.UserProfile.GenderLookupId, MartialStatusLookupId = x.UserProfile.MartialStatusLookupId, FullName = x.FullName, Address = x.Address, Mobile = x.UserProfile.Mobile, Email = x.UserProfile.Username, Fax = x.UserProfile.Fax, BirthDay = x.UserProfile.Birthday, Status = x.UserProfile.Status, CityId = x.UserProfile.CityId, ProvinceId = x.UserProfile.ProvinceId, RegionId = x.UserProfile.RegionId, LastLogin = x.UserProfile.LastLogin, ManagerId = x.UserProfile.ManagerId, ManagerName = x.UserProfile?.ManagerId != null ? LanguageFallbackHelper.GetUserProfile((int)x.UserProfile.ManagerId, languageId)?.FullName : string.Empty, Department = x.UserProfile.DepartmentId, DepartmentName = x.UserProfile?.DepartmentId != null ? LanguageFallbackHelper.GetDepartment((int)x.UserProfile.DepartmentId, languageId)?.Name : string.Empty, PrefferdLanguage = x.UserProfile.PreferedLanguageId }).ToList(); if (!profiles.Any()) { profiles = LanguageFallbackHelper.GetDefaultEmployeeProfiles(); } return(profiles); } catch (Exception ex) { LogHelper.LogException("", ex, "Error While Getting employee profiles"); return(new List <ProfileViewModel>()); } } }
public static List <ProfileViewModel> GetDefaultEmployeeProfiles() { using (var db = new CrmSystemEntities()) { try { var employees = db.AspNetUserRoles.Where(r => r.AspNetRole.Name != Constants.Roles.Citizen) .Select(r => r.AspNetUser.UserName).ToList(); var lookups = db.UserProfiles.Where(r => employees.Contains(r.Username) && r.UserProfileTranslations.Any(x => x.IsDefault) && r.Status == (int)GeneralEnums.StatusEnum.Active) .SelectMany(r => r.UserProfileTranslations).ToList().Select(x => new ProfileViewModel() { Id = x.UserProfileId, LanguageId = x.LanguageId, IdNumber = x.UserProfile.IdNumber, PhoneNumber = x.UserProfile.PhoneNumber, GenderLookupId = x.UserProfile.GenderLookupId, MartialStatusLookupId = x.UserProfile.MartialStatusLookupId, FullName = x.FullName, Address = x.Address, Mobile = x.UserProfile.Mobile, Email = x.UserProfile.Username, Fax = x.UserProfile.Fax, BirthDay = x.UserProfile.Birthday, Status = x.UserProfile.Status, CityId = x.UserProfile.CityId, ProvinceId = x.UserProfile.ProvinceId, RegionId = x.UserProfile.RegionId, LastLogin = x.UserProfile.LastLogin, ManagerId = x.UserProfile.ManagerId, ManagerName = x.UserProfile?.ManagerId != null ? LanguageFallbackHelper.GetUserProfile((int)x.UserProfile.ManagerId, CultureHelper.GetDefaultLanguageId())?.FullName : string.Empty, Department = x.UserProfile.DepartmentId, DepartmentName = x.UserProfile?.DepartmentId != null ? LanguageFallbackHelper.GetDepartment((int)x.UserProfile.DepartmentId, CultureHelper.GetDefaultLanguageId())?.Name : string.Empty, PrefferdLanguage = x.UserProfile.PreferedLanguageId }).ToList(); return(lookups); } catch (Exception ex) { LogHelper.LogException("", ex, "Error While Getting Default Employee profiles"); return(new List <ProfileViewModel>()); } } }
public static List <ProfileViewModel> GetUserProfiles(HttpCookie cookie) { using (var db = new CrmSystemEntities()) { try { int languageId = (int)GeneralEnums.LanguageEnum.Arabic; if (cookie != null) { var languageName = CultureHelper.GetCultureName(cookie); languageId = CultureHelper.MapLanguage(languageName); } var profiles = db.UserProfiles.Where(r => r.UserProfileTranslations.Any(x => x.LanguageId == languageId) && r.Status == (int)GeneralEnums.StatusEnum.Active) .SelectMany(r => r.UserProfileTranslations.Where(x => x.LanguageId == languageId)).ToList().Select(x => new ProfileViewModel() { Id = x.UserProfileId, LanguageId = x.LanguageId, IdNumber = x.UserProfile.IdNumber, PhoneNumber = x.UserProfile.PhoneNumber, GenderLookupId = x.UserProfile.GenderLookupId, MartialStatusLookupId = x.UserProfile.MartialStatusLookupId, FullName = x.FullName, Address = x.Address, Mobile = x.UserProfile.Mobile, Email = x.UserProfile.Username, Fax = x.UserProfile.Fax, BirthDay = x.UserProfile.Birthday, Status = x.UserProfile.Status, CityId = x.UserProfile.CityId, ProvinceId = x.UserProfile.ProvinceId, RegionId = x.UserProfile.RegionId, LastLogin = x.UserProfile.LastLogin, ManagerId = x.UserProfile.ManagerId, ManagerName = x.UserProfile?.ManagerId != null ? LanguageFallbackHelper.GetUserProfile((int)x.UserProfile.ManagerId, languageId)?.FullName : string.Empty, Department = x.UserProfile.DepartmentId, DepartmentName = x.UserProfile?.DepartmentId != null ? LanguageFallbackHelper.GetDepartment((int)x.UserProfile.DepartmentId, languageId)?.Name : string.Empty, PrefferdLanguage = x.UserProfile.PreferedLanguageId }).ToList(); if (!profiles.Any()) { profiles = LanguageFallbackHelper.GetDefaultUserProfiles(); } return(profiles); } catch (Exception ex) { LogHelper.LogException("", ex, "Error While Getting user profiles"); return(new List <ProfileViewModel>()); } } }