示例#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());
                }
            }
        }
示例#2
0
 public static List <CampaignViewModel> GetCampaigns(HttpCookie cookie)
 {
     using (var db = new CrmSystemEntities())
     {
         try
         {
             var companyId  = SessionHelper.GetCompanyId();
             int languageId = (int)GeneralEnums.LanguageEnum.Arabic;
             if (cookie != null)
             {
                 var languageName = CultureHelper.GetCultureName(cookie);
                 languageId = CultureHelper.MapLanguage(languageName);
             }
             var campaigns = db.Campaigns.Where(r => r.CompanyId == companyId).ToList().Select(x => new CampaignViewModel()
             {
                 Id   = x.Id,
                 Name = x.Name
             }).ToList();
             return(campaigns);
         }
         catch (Exception ex)
         {
             LogHelper.LogException("", ex, "Error While Getting Campaigns");
             return(new List <CampaignViewModel>());
         }
     }
 }
示例#3
0
        public static List <MenuViewModel> GetDefaultParentMenus()
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var menus = db.Menus.Where(r => r.ParentId == null &&
                                               r.MenuTranslations.Any(x => x.IsDefault) &&
                                               r.Status == (int)GeneralEnums.StatusEnum.Active)
                                .SelectMany(r => r.MenuTranslations).Select(x => new MenuViewModel()
                    {
                        Id          = x.MenuId,
                        Title       = x.Title,
                        Description = x.Description
                    }).ToList();

                    return(menus);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting Default Parent Menus");
                    return(new List <MenuViewModel>());
                }
            }
        }
示例#4
0
        public static List <DepartmentViewModel> GetDefaultDepartments()
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var lookups = db.Departments.Where(r =>
                                                       r.DepartmentTranslations.Any(x => x.IsDefault) &&
                                                       r.Status == (int)GeneralEnums.StatusEnum.Active)
                                  .SelectMany(r => r.DepartmentTranslations).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();

                    return(lookups);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting Default Departments");
                    return(new List <DepartmentViewModel>());
                }
            }
        }
示例#5
0
        public static List <RoleViewModel> GetUserRoles(IPrincipal User)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    if (User != null && User.Identity.Name.IsNotNullOrEmpty())
                    {
                        var aspUser = db.AspNetUsers.FirstOrDefault(r => r.UserName == User.Identity.Name);

                        var userRoles = aspUser?.AspNetUserRoles.ToList().Select(r => new RoleViewModel
                        {
                            RoleId = r.RoleId,
                            Name   = r.AspNetRole.Name
                        }).ToList();
                        return(userRoles);
                    }
                    return(new List <RoleViewModel>());
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting User Roles");
                    return(new List <RoleViewModel>());
                }
            }
        }
示例#6
0
        public static string GetUserName(IPrincipal user, int langId)
        {
            using (var db = new CrmSystemEntities())
            {
                var userProf = db.UserProfiles.FirstOrDefault(r => r.Username == user.Identity.Name);
                if (userProf != null && userProf.UserProfileTranslations.Any())
                {
                    var trans = userProf.UserProfileTranslations.FirstOrDefault(r => r.LanguageId == langId);
                    if (trans != null)
                    {
                        return(trans.FullName);
                    }
                    else
                    {
                        trans = userProf.UserProfileTranslations.FirstOrDefault();
                        if (trans != null)
                        {
                            return(trans.FullName);
                        }
                    }
                }

                return(user.Identity.Name);
            }
        }
示例#7
0
        public static ProfileViewModel GetUserInfo(IPrincipal user, int langId)
        {
            using (var db = new CrmSystemEntities())
            {
                var userProf = db.UserProfiles.FirstOrDefault(r => r.Username == user.Identity.Name);
                if (userProf != null && userProf.UserProfileTranslations.Any())
                {
                    var trans = userProf.UserProfileTranslations.FirstOrDefault(r => r.LanguageId == langId);
                    if (trans != null)
                    {
                        return(new ProfileViewModel {
                            FullName = trans.FullName, ProfilePath = trans.UserProfile.ProfilePhoto
                        });
                    }
                    else
                    {
                        trans = userProf.UserProfileTranslations.FirstOrDefault();
                        if (trans != null)
                        {
                            return(new ProfileViewModel {
                                FullName = trans.FullName, ProfilePath = trans.UserProfile.ProfilePhoto
                            });
                        }
                    }
                }

                return(new ProfileViewModel {
                    FullName = user.Identity.Name, ProfilePath = ""
                });
            }
        }
示例#8
0
        public static List <CategoryViewModel> GetDefaultCategories()
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var cats = db.Categories.Where(r =>
                                                   r.CategoryTranslations.Any(x => x.IsDefault) &&
                                                   r.Status == (int)GeneralEnums.StatusEnum.Active)
                               .SelectMany(r => r.CategoryTranslations).Select(x => new CategoryViewModel()
                    {
                        Id          = x.CategoryId,
                        Title       = x.Title,
                        Description = x.Description,
                        LanguageId  = x.LanguageId,
                        CreatedBy   = x.Category.CreatedBy,
                        CreatedOn   = x.Category.CreatedOn
                    }).ToList();

                    return(cats);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting Default Categories");
                    return(new List <CategoryViewModel>());
                }
            }
        }
示例#9
0
        public static MenuViewModel GetMenu(int id, int languageId)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var category = db.MenuTranslations.Where(r => r.MenuId == id && r.Menu.Status != (int)GeneralEnums.StatusEnum.Deleted && r.LanguageId == languageId)
                                   .ToList().Select(x => new MenuViewModel()
                    {
                        Id          = x.MenuId,
                        Title       = x.Title,
                        Status      = x.Menu.Status,
                        ParentId    = x.Menu.ParentId,
                        Description = x.Description,
                        CreatedOn   = x.Menu.CreatedOn,
                        DeletedOn   = x.Menu.DeletedOn,
                        LanguageId  = x.LanguageId,
                        CreatedBy   = x.Menu.CreatedBy,
                        SortOrder   = x.Menu.SortOrder,
                        PageId      = x.Menu.PageId,
                        PageUrl     = x.Menu.PageUrl,
                        Icon        = x.Menu.Icon,
                        PageName    = string.Empty,  // TODO: set it to the correct name
                        ParentName  = x.Menu.ParentId != null ? GetMenu((int)x.Menu.ParentId, languageId)?.Title : string.Empty,
                    }).FirstOrDefault();

                    if (category == null)
                    {
                        category = db.Menus.Where(r => r.MenuTranslations.Any(x => x.IsDefault) &&
                                                  r.Id == id && r.Status == (int)GeneralEnums.StatusEnum.Active).ToList()
                                   .SelectMany(r => r.MenuTranslations).Select(x => new MenuViewModel()
                        {
                            Id          = x.MenuId,
                            Title       = x.Title,
                            Status      = x.Menu.Status,
                            ParentId    = x.Menu.ParentId,
                            Description = x.Description,
                            CreatedOn   = x.Menu.CreatedOn,
                            DeletedOn   = x.Menu.DeletedOn,
                            LanguageId  = x.LanguageId,
                            CreatedBy   = x.Menu.CreatedBy,
                            SortOrder   = x.Menu.SortOrder,
                            PageId      = x.Menu.PageId,
                            PageUrl     = x.Menu.PageUrl,
                            Icon        = x.Menu.Icon,
                            PageName    = string.Empty,  // TODO: set it to the correct name
                            ParentName  = x.Menu.ParentId != null ? GetMenu((int)x.Menu.ParentId, languageId)?.Title : string.Empty,
                        }).FirstOrDefault();
                    }

                    return(category);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting Menu");
                    return(new MenuViewModel());
                }
            }
        }
示例#10
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>());
                }
            }
        }
示例#11
0
 public static void AddSystemLog(SystemLog log)
 {
     using (var db = new CrmSystemEntities())
     {
         try
         {
             db.SystemLogs.Add(log);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             //TODO: Send Email incase of the failure of adding appliaction log
         }
     }
 }
示例#12
0
 public static void AddEmailLog(CommunicationLog log)
 {
     using (var db = new CrmSystemEntities())
     {
         try
         {
             db.CommunicationLogs.Add(log);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             //TODO: Send Email incase of the failure of adding Email log
         }
     }
 }
示例#13
0
        public static DetailsLookupViewModel GetDetailsLookup(int id, int language)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var detailLookup = db.DetailsLookupTranslations.Where(r => r.DetailsLookupId == id && r.LanguageId == language && r.DetailsLookup.Status != (int)GeneralEnums.StatusEnum.Deleted)
                                       .ToList()
                                       .Select(x => new DetailsLookupViewModel()
                    {
                        Id         = x.DetailsLookupId,
                        CreatedBy  = x.DetailsLookup.CreatedBy,
                        CreatedOn  = x.DetailsLookup.CreatedOn,
                        IsDefault  = x.IsDefault,
                        Name       = x.Value,
                        Status     = x.DetailsLookup.Status,
                        LanguageId = x.LanguageId,
                        DeletedOn  = x.DetailsLookup.DeletedOn,
                        MasterId   = x.DetailsLookup.MasterId
                    }).FirstOrDefault();

                    if (detailLookup == null)
                    {
                        detailLookup = db.DetailsLookups.Where(m => m.DetailsLookupTranslations.Any(x => x.IsDefault) && m.Id == id && m.Status == (int)GeneralEnums.StatusEnum.Active)
                                       .ToList()
                                       .SelectMany(m => m.DetailsLookupTranslations)
                                       .Select(x => new DetailsLookupViewModel()
                        {
                            Id         = x.DetailsLookupId,
                            CreatedBy  = x.DetailsLookup.CreatedBy,
                            CreatedOn  = x.DetailsLookup.CreatedOn,
                            IsDefault  = x.IsDefault,
                            Name       = x.Value,
                            Status     = x.DetailsLookup.Status,
                            LanguageId = x.LanguageId,
                            DeletedOn  = x.DetailsLookup.DeletedOn,
                            MasterId   = x.DetailsLookup.MasterId
                        }).FirstOrDefault();
                    }
                    return(detailLookup);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting Details Lookup");
                    return(null);
                }
            }
        }
示例#14
0
        public static List <SMSTemplateViewModel> GetBothLanguageSMSTemplate(int id)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var smsTemplate = db.SMSTemplateTranslations.Where(r => r.SMSTemplateId == id &&
                                                                       r.SMSTemplate.Status != (int)GeneralEnums.StatusEnum.Deleted)
                                      .ToList().Select(x => new SMSTemplateViewModel()
                    {
                        Id                      = x.SMSTemplateId,
                        Name                    = x.Name,
                        Status                  = x.SMSTemplate.Status,
                        Description             = x.Description,
                        CreatedOn               = x.SMSTemplate.CreatedOn,
                        DeletedOn               = x.SMSTemplate.DeletedOn,
                        LanguageId              = x.LanguageId,
                        DefaultTemplateLanguage = x.SMSTemplate.DefaultLanguage,
                        CreatedBy               = x.SMSTemplate.CreatedBy,
                    }).ToList();

                    if (smsTemplate.Count == 0)
                    {
                        smsTemplate = db.SMSTemplates.Where(r => r.SMSTemplateTranslations.Any(x => x.IsDefault) &&
                                                            r.Id == id && r.Status == (int)GeneralEnums.StatusEnum.Active).ToList()
                                      .SelectMany(r => r.SMSTemplateTranslations).Select(x => new SMSTemplateViewModel()
                        {
                            Id                      = x.SMSTemplateId,
                            Name                    = x.Name,
                            Status                  = x.SMSTemplate.Status,
                            Description             = x.Description,
                            CreatedOn               = x.SMSTemplate.CreatedOn,
                            DeletedOn               = x.SMSTemplate.DeletedOn,
                            LanguageId              = x.LanguageId,
                            DefaultTemplateLanguage = x.SMSTemplate.DefaultLanguage,
                            CreatedBy               = x.SMSTemplate.CreatedBy
                        }).ToList();
                    }

                    return(smsTemplate);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting SMS Template");
                    return(new List <SMSTemplateViewModel>());
                }
            }
        }
示例#15
0
 public static int GetAssignedUser(int fromState, int toState, int categoryId)
 {
     using (var db = new CrmSystemEntities())
     {
         var transition = db.StateTransitionsConfigurations.FirstOrDefault(r =>
                                                                           r.CategoryId == categoryId && r.StateFrom == fromState && r.StateTo == toState &&
                                                                           r.Status == (int)GeneralEnums.StatusEnum.Active);
         if (transition != null)
         {
             return(transition.AssigneeId ?? 0);
         }
         else
         {
             return(0);
         }
     }
 }
示例#16
0
        public static DepartmentViewModel GetDepartment(int id, int languageId)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var department = db.DepartmentTranslations.Where(r => r.DepartmentId == id && r.Department.Status != (int)GeneralEnums.StatusEnum.Deleted && r.LanguageId == languageId)
                                     .ToList().Select(x => new DepartmentViewModel()
                    {
                        Id          = x.DepartmentId,
                        Name        = x.Name,
                        Status      = x.Department.Status,
                        Description = x.Description,
                        CreatedOn   = x.Department.CreatedOn,
                        DeletedOn   = x.Department.DeletedOn,
                        LanguageId  = x.LanguageId,
                        CreatedBy   = x.Department.CreatedBy,
                    }).FirstOrDefault();

                    if (department == null)
                    {
                        department = db.Departments.Where(r => r.DepartmentTranslations.Any(x => x.IsDefault) &&
                                                          r.Id == id && r.Status == (int)GeneralEnums.StatusEnum.Active).ToList()
                                     .SelectMany(r => r.DepartmentTranslations).Select(x => new DepartmentViewModel()
                        {
                            Id          = x.DepartmentId,
                            Name        = x.Name,
                            Status      = x.Department.Status,
                            Description = x.Description,
                            CreatedOn   = x.Department.CreatedOn,
                            DeletedOn   = x.Department.DeletedOn,
                            LanguageId  = x.LanguageId,
                            CreatedBy   = x.Department.CreatedBy
                        }).FirstOrDefault();
                    }

                    return(department);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting Department");
                    return(new DepartmentViewModel());
                }
            }
        }
示例#17
0
        public static List <string> GetUserControlPanelPages(IPrincipal User)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    if (User != null)
                    {
                        var pages = new List <string>
                        {
                            "Users",
                            "Sla",
                            "StateTransitions",
                            "StateHistory",
                            "Roles",
                            "RolesPermissions",
                            "Settings",
                            "MasterLookups",
                            "Departments",
                            "SMSTemplate",
                            "Category", "Article",
                            "Reports", "FullCaseReport", "CasesDaysByCategory", "CasesSlaByCategory",
                            "ClosedCasesReport", "PercentageOfResolvedCase",
                            "ContactUs",
                            "CasesSentAsEmail"
                        };

                        var aspUser = db.AspNetUsers.FirstOrDefault(r => r.UserName == User.Identity.Name);

                        var userRoles = aspUser?.AspNetUserRoles.ToList().Select(r => r.RoleId).ToList();

                        var pagesPermissions = db.Permissions.Where(t => t.PermissionKey == "View" && pages.Contains(t.PageName) &&
                                                                    t.RolePermissions.Select(a => a.RoleId).Any(a => userRoles.Contains(a))).Select(t => t.PageName).ToList();

                        return(pagesPermissions);
                    }
                    return(new List <string>());
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting User Control Panel Pages");
                    return(new List <string>());
                }
            }
        }
示例#18
0
        public static CategoryViewModel GetCategory(int id, int languageId)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var smsTemplate = db.CategoryTranslations.Where(r => r.CategoryId == id && r.Category.Status != (int)GeneralEnums.StatusEnum.Deleted && r.LanguageId == languageId)
                                      .ToList().Select(x => new CategoryViewModel()
                    {
                        Id          = x.CategoryId,
                        Title       = x.Title,
                        Status      = x.Category.Status,
                        Description = x.Description,
                        CreatedOn   = x.Category.CreatedOn,
                        DeletedOn   = x.Category.DeletedOn,
                        LanguageId  = x.LanguageId,
                        CreatedBy   = x.Category.CreatedBy,
                    }).FirstOrDefault();

                    if (smsTemplate == null)
                    {
                        smsTemplate = db.Categories.Where(r => r.CategoryTranslations.Any(x => x.IsDefault) &&
                                                          r.Id == id && r.Status == (int)GeneralEnums.StatusEnum.Active).ToList()
                                      .SelectMany(r => r.CategoryTranslations).Select(x => new CategoryViewModel()
                        {
                            Id          = x.CategoryId,
                            Title       = x.Title,
                            Status      = x.Category.Status,
                            Description = x.Description,
                            CreatedOn   = x.Category.CreatedOn,
                            DeletedOn   = x.Category.DeletedOn,
                            LanguageId  = x.LanguageId,
                            CreatedBy   = x.Category.CreatedBy
                        }).FirstOrDefault();
                    }
                    return(smsTemplate);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting Category");
                    return(new CategoryViewModel());
                }
            }
        }
示例#19
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>());
                }
            }
        }
示例#20
0
 public static SettingViewModel GetSystemSetting(int id, int language)
 {
     using (var db = new CrmSystemEntities())
     {
         try
         {
             var systemSetting = db.SystemSettingTranslations.Where(r => r.SettingId == id && r.LanguageId == language && r.SystemSetting.Status != (int)GeneralEnums.StatusEnum.Deleted).ToList()
                                 .Select(x => new SettingViewModel()
             {
                 Id         = x.SettingId,
                 CreatedBy  = x.SystemSetting.CreatedBy,
                 CreatedOn  = x.SystemSetting.CreatedOn,
                 DeletedOn  = x.SystemSetting.DeletedOn,
                 LanguageId = x.LanguageId,
                 Name       = x.Name,
                 Status     = x.SystemSetting.Status,
                 Value      = x.Value
             }).FirstOrDefault();
             if (systemSetting == null)
             {
                 systemSetting = db.SystemSettings.Where(x => x.SystemSettingTranslations.Any(r => r.IsDefault) && x.Id == id && x.Status == (int)GeneralEnums.StatusEnum.Active)
                                 .ToList()
                                 .SelectMany(x => x.SystemSettingTranslations)
                                 .Select(x => new SettingViewModel()
                 {
                     Id         = x.SettingId,
                     CreatedBy  = x.SystemSetting.CreatedBy,
                     CreatedOn  = x.SystemSetting.CreatedOn,
                     DeletedOn  = x.SystemSetting.DeletedOn,
                     LanguageId = x.LanguageId,
                     Name       = x.Name,
                     Status     = x.SystemSetting.Status,
                     Value      = x.Value
                 }).FirstOrDefault();
             }
             return(systemSetting);
         }
         catch (Exception ex)
         {
             LogHelper.LogException("", ex, "Error While Getting System Setting ");
             return(null);
         }
     }
 }
示例#21
0
        /// <summary>
        /// Constructor for the Complaint class
        /// </summary>
        public Complaint(SystemCas sysCse, UserProfile userProfile)
        {
            _sysCse      = sysCse;
            _userProfile = userProfile;

            using (var db = new CrmSystemEntities())
            {
                var assignee = db.UserProfiles.Find(_sysCse.AssigneeId);
                if (assignee != null)
                {
                    _departmentEmails = new List <string>()
                    {
                        assignee.Email
                    };
                }
            }

            // Instantiate a new state machine in the Open state
            _machine = new StateMachine <State, Trigger>(State.New);

            // Instantiate a new trigger with a parameter.
            _assignTrigger = _machine.SetTriggerParameters <string>(Trigger.New);

            // Configure the Open state
            _machine.Configure(State.New)
            .Permit(Trigger.New, State.InProgress);

            // Configure the Assigned state
            _machine.Configure(State.InProgress)
            .SubstateOf(State.InProgress)
            //.OnEntryFrom(_assignTrigger, InPorgress)  // This is where the TriggerWithParameters is used. Note that the TriggerWithParameters object is used, not something from the enum
            .PermitReentry(Trigger.InProgress)
            .Permit(Trigger.Close, State.Closed)
            .Permit(Trigger.Reject, State.Rejected)
            .Permit(Trigger.Resolve, State.Resolved)
            .Permit(Trigger.Duplicate, State.Duplicated)
            .OnExit(OnDeassigned);

            // Configure the Rejected state
            _machine.Configure(State.Rejected)
            .OnEntry(() => _assignee = null)
            .Permit(Trigger.InProgress, State.Closed);
        }
示例#22
0
        public static CampaignViewModel GetCampaigns(int id, int languageId)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var camp = db.Campaigns.Where(r => r.Id == id).ToList().Select(x => new CampaignViewModel()
                    {
                        Id   = x.Id,
                        Name = x.Name
                    }).FirstOrDefault();

                    return(camp);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, "Error While Getting Campaings");
                    return(new CampaignViewModel());
                }
            }
        }
示例#23
0
        public static List <RoleViewModel> GetRoles(HttpCookie cookie)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var roles = db.AspNetRoles.ToList().Select(x =>
                                                               new RoleViewModel()
                    {
                        RoleId = x.Id,
                        Name   = x.Name,
                    });

                    return(roles.ToList());
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, $"Error While Getting Roles");
                    return(new List <RoleViewModel>());
                }
            }
        }
示例#24
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>());
                }
            }
        }
示例#25
0
        public static DetailsLookupViewModel GetLookupDetailsByCode(string code)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var lookups = db.DetailsLookups.Where(r => r.Code == code && r.Status == (int)GeneralEnums.StatusEnum.Active).ToList()
                                  .Select(x => new DetailsLookupViewModel()
                    {
                        Id   = x.Id,
                        Name = x.DetailsLookupTranslations.FirstOrDefault(g => g.IsDefault).Value,
                    }).FirstOrDefault();

                    return(lookups);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, $"Error While Getting Lookup Details By lookup code {code}");
                    return(null);
                }
            }
        }
示例#26
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>());
                }
            }
        }
示例#27
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>());
                }
            }
        }
示例#28
0
        public static DetailsLookupViewModel GetDefaultLookupDetailsById(int lookupId)
        {
            using (var db = new CrmSystemEntities())
            {
                try
                {
                    var lookups = db.DetailsLookups.Where(r =>
                                                          r.DetailsLookupTranslations.Any(x => x.IsDefault) &&
                                                          r.Id == lookupId && r.Status == (int)GeneralEnums.StatusEnum.Active)
                                  .SelectMany(r => r.DetailsLookupTranslations).Select(x => new DetailsLookupViewModel()
                    {
                        Id   = x.DetailsLookupId,
                        Name = x.Value
                    }).FirstOrDefault();

                    return(lookups);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException("", ex, $"Error While Getting Default Lookup Details By lookup Id {lookupId}");
                    return(new DetailsLookupViewModel());
                }
            }
        }
示例#29
0
 private static void AddEmailToCommunicationLog(int typeId, string LogText, IPrincipal User = null)
 {
     using (var db = new CrmSystemEntities())
     {
         var username = User != null ? User.Identity.Name : Constants.Users.Service;
         try
         {
             var data = new CommunicationLog()
             {
                 TypeId    = typeId,
                 LogText   = LogText,
                 CreatedBy = username,
                 CreatedOn = DateTime.Now,
                 Status    = (int)GeneralEnums.StatusEnum.Active,
             };
             db.CommunicationLogs.Add(data);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             //TODO QASEM LogHelper.LogException(username, ex, $"Error while saving communication log for sms template as email for msg {LogText}");
         }
     }
 }
示例#30
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());
                }
            }
        }