Exemplo n.º 1
0
        public static DetailsLookupViewModel GetLookupDetailsById(int lookupId, 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 lookups = db.DetailsLookups.Where(r =>
                                                          r.DetailsLookupTranslations.Any(x => x.LanguageId == languageId) &&
                                                          r.Id == lookupId && r.Status == (int)GeneralEnums.StatusEnum.Active)
                                  .SelectMany(r => r.DetailsLookupTranslations.Where(x => x.LanguageId == languageId)).Select(x => new DetailsLookupViewModel()
                    {
                        MasterId = x.DetailsLookup.MasterId,
                        Id       = x.DetailsLookupId,
                        Name     = x.Value
                    }).FirstOrDefault() ?? LanguageFallbackHelper.GetDefaultLookupDetailsById(lookupId);

                    return(lookups);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, $"Error While Getting Lookup Details By lookup Id {lookupId}");
                    return(new DetailsLookupViewModel());
                }
            }
        }
Exemplo n.º 2
0
        public static List <ProfileViewModel> GetCitizens(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 employees = db.AspNetUserRoles.Where(r => r.AspNetRole.Name == Constants.Roles.Citizen)
                                    .Select(r => r.AspNetUser.UserName).ToList();

                    var profiles = db.UserProfiles.Where(r => employees.Contains(r.Username) &&
                                                         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.GetDefaultEmployeeProfiles();
                    }
                    return(profiles);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting citizens profiles");
                    return(new List <ProfileViewModel>());
                }
            }
        }
Exemplo n.º 3
0
        public static List <ProfileViewModel> GetDefaultUserProfiles()
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var lookups = db.UserProfiles.Where(r =>
                                                        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 User profiles");
                    return(new List <ProfileViewModel>());
                }
            }
        }
Exemplo n.º 4
0
        public static List <string> GetFormWinnersNames(string formId, int langId, int winnerStatus)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var formWinnersNames = db.SystemCases.Where(t => t.FormId == formId).ToList().Select(t => new
                    {
                        fullName = t.StateHistories.LastOrDefault() != null ?
                                   (t.StateHistories.LastOrDefault().CurrentState == winnerStatus) ?
                                   LanguageFallbackHelper.GetUserProfileByUsername(t.CreatedBy, langId).FullName : string.Empty : string.Empty
                    }).ToList();

                    return(formWinnersNames.Where(t => t.fullName.IsNotNullOrEmpty()).Select(t => t.fullName).ToList());
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting Form Winners Names");
                    return(new List <string>());
                }
            }
        }
Exemplo n.º 5
0
        public static List <DepartmentViewModel> GetDepartments(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 departments = db.Departments.Where(r =>
                                                           r.DepartmentTranslations.Any(x => x.LanguageId == languageId) &&
                                                           r.Status == (int)GeneralEnums.StatusEnum.Active)
                                      .SelectMany(r => r.DepartmentTranslations.Where(x => x.LanguageId == languageId)).Select(x => new DepartmentViewModel()
                    {
                        Id          = x.DepartmentId,
                        Name        = x.Name,
                        Description = x.Description,
                        LanguageId  = x.LanguageId,
                        CreatedBy   = x.Department.CreatedBy,
                        CreatedOn   = x.Department.CreatedOn
                    }).ToList();

                    if (!departments.Any())
                    {
                        departments = LanguageFallbackHelper.GetDefaultDepartments();
                    }
                    return(departments);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting departments");
                    return(new List <DepartmentViewModel>());
                }
            }
        }
Exemplo n.º 6
0
        public static List <MenuViewModel> GetMenus(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 lookups = db.Menus.Where(r =>
                                                 r.MenuTranslations.Any(x => x.LanguageId == languageId) &&
                                                 r.Status == (int)GeneralEnums.StatusEnum.Active).OrderBy(r => r.SortOrder)
                                  .SelectMany(r => r.MenuTranslations.Where(l => l.LanguageId == languageId)).Select(x => new MenuViewModel()
                    {
                        Id          = x.MenuId,
                        Title       = x.Title,
                        Description = x.Description
                    }).ToList();

                    if (!lookups.Any())
                    {
                        lookups = LanguageFallbackHelper.GetDefaultMenus();
                    }
                    return(lookups);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting Parent Menus");
                    return(new List <MenuViewModel>());
                }
            }
        }
Exemplo n.º 7
0
        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());
                }
            }
        }
Exemplo n.º 8
0
        public static string GenerateSystemVerticalMenu(int userId, HttpCookie cultureCookie)
        {
            string menuHtml = string.Empty;

            using (var db = new CrmSystemEntities())
            {
                var menus = db.Menus.Where(r => r.Status == (int)GeneralEnums.StatusEnum.Active && r.ParentId == null).OrderBy(r => r.SortOrder).ToList();
                int count = 1;
                foreach (var menu in menus)
                {
                    var mainMenufilePath = HttpContext.Current.Server.MapPath(Constants.TempaltesPathes.Menu.MainMenu);
                    var mainMenuStream   = new StreamReader(mainMenufilePath);
                    var mainMenuHtml     = mainMenuStream.ReadToEnd();

                    var subMenufilePath = HttpContext.Current.Server.MapPath(Constants.TempaltesPathes.Menu.SubMenu);
                    var subMenuStream   = new StreamReader(subMenufilePath);
                    var subMenuHtml     = subMenuStream.ReadToEnd();

                    mainMenuHtml = mainMenuHtml.Replace("{tabHeadId}", count.ToString());
                    mainMenuHtml = mainMenuHtml.Replace("{tabCollapseId}", count.ToString());
                    mainMenuHtml = mainMenuHtml.Replace("{parentMenuIcon}", menu.Icon);
                    var langId = CultureHelper.GetCurrentLanguageId(cultureCookie);
                    mainMenuHtml = mainMenuHtml.Replace("{parentMenuTitle}", LanguageFallbackHelper.GetMenu(menu.Id, langId)?.Title);

                    //var page = db.Pages.FirstOrDefault(m => m.Menus.Any(c => c.Id == menu.Id));

                    //var pageId = HttpContext.Current.Request.QueryString["pageId"];
                    //if (menu.Menu1.Any(c => c.PageId == (!string.IsNullOrWhiteSpace(pageId) ? int.Parse(pageId) : 0)))
                    //{
                    //    mainMenuHtml = mainMenuHtml.Replace("{CollapseString}", "in");
                    //}
                    //else if (db.Menus.Where(r =>
                    //    r.ParentId == menu.Id && r.Status == (int)GeneralEnums.StatusEnum.Active).OrderBy(x => x.SortOrder).ToList()
                    //    .Any(i => i.Page != null && i.Page.PageUrl != null && (i.Page.PageUrl == (HttpContext.Current.Request.Path) || i.Page.PageUrl == (HttpContext.Current.Request.Url.AbsoluteUri))))
                    //{
                    //    mainMenuHtml = mainMenuHtml.Replace("{CollapseString}", "in");
                    //}
                    //else
                    //{
                    //    mainMenuHtml = mainMenuHtml.Replace("{CollapseString}", "");
                    //}

                    var subMenus = db.Menus.Where(r =>
                                                  r.ParentId == menu.Id && r.Status == (int)GeneralEnums.StatusEnum.Active).OrderBy(x => x.SortOrder).ToList();
                    var finalSubMenuHtml = string.Empty;
                    foreach (var subMenu in subMenus)
                    {
                        var tempSubMenuHtml = subMenuHtml;
                        //if (!string.IsNullOrWhiteSpace(subMenu?.Page?.PageUrl))
                        //{

                        //    tempSubMenuHtml = tempSubMenuHtml.Replace("{SubMenuLink}", subMenu.Page.PageUrl);

                        //}
                        //else
                        //{
                        //    if ((subMenu?.Page?.PublishDate != null && subMenu?.Page?.PublishDate < DateTime.Now) && (subMenu?.Page?.EndDate == null || subMenu?.Page?.EndDate > DateTime.Now))
                        //    {
                        //        tempSubMenuHtml = tempSubMenuHtml.Replace("{SubMenuLink}", subMenu.PageId == null ? "#" : $"/CmsPage/Page?pageId={subMenu.PageId}");
                        //    }
                        //    else
                        //    {
                        //        tempSubMenuHtml = "";
                        //    }
                        //}
                        //if (!(HttpContext.Current.User.IsInRole(Constants.Roles.Administrator) || HttpContext.Current.User.IsInRole(Constants.Roles.ContentAdmin)))
                        //{

                        //    if (!string.IsNullOrWhiteSpace(subMenu?.Page?.PageUrl))
                        //    {

                        //        tempSubMenuHtml = tempSubMenuHtml.Replace("{SubMenuLink}", subMenu.Page.PageUrl);

                        //    }
                        //    else
                        //    {
                        //        if ((subMenu?.Page?.PublishDate != null && subMenu?.Page?.PublishDate < DateTime.Now) && (subMenu?.Page?.EndDate == null || subMenu?.Page?.EndDate > DateTime.Now))
                        //        {
                        //            tempSubMenuHtml = tempSubMenuHtml.Replace("{SubMenuLink}", subMenu.PageId == null ? "#" : $"/CmsPage/Page?pageId={subMenu.PageId}");
                        //        }
                        //        else
                        //        {
                        //            tempSubMenuHtml = "";
                        //        }
                        //    }
                        //}

                        //else
                        //{
                        //    if (!string.IsNullOrWhiteSpace(subMenu?.Page?.PageUrl))
                        //    {
                        //        tempSubMenuHtml = tempSubMenuHtml.Replace("{SubMenuLink}", subMenu.Page.PageUrl);
                        //    }
                        //    else
                        //    {
                        //        tempSubMenuHtml = tempSubMenuHtml.Replace("{SubMenuLink}", subMenu.PageId == null ? "#" : $"/CmsPage/Page?pageId={subMenu.PageId}");
                        //    }
                        //}
                        tempSubMenuHtml   = tempSubMenuHtml.Replace("{SubMenuTitle}", LanguageFallbackHelper.GetMenu(subMenu.Id, langId)?.Title);
                        finalSubMenuHtml += tempSubMenuHtml;
                    }
                    mainMenuHtml = mainMenuHtml.Replace("{subMenuHtml}", finalSubMenuHtml);
                    menuHtml    += mainMenuHtml;
                    count++;
                }
            }

            return(menuHtml);
        }