示例#1
0
        public override DTO.UserMng.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.UserMng.SearchFormData data = new DTO.UserMng.SearchFormData();
            data.Data = new List <DTO.UserMng.UserProfileSearchResult>();
            totalRows = 0;

            //try to get data
            try
            {
                using (UserMngEntities context = CreateContext())
                {
                    string UserName    = null;
                    string UserUD      = null;
                    string FullName    = null;
                    int?   UserGroupID = null;
                    string PhoneNumber = null;
                    string Email       = null;
                    string SkypeID     = null;
                    int?   OfficeID    = null;
                    bool?  IsActivated = null;

                    if (filters.ContainsKey("UserName") && !string.IsNullOrEmpty(filters["UserName"].ToString()))
                    {
                        UserName = filters["UserName"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("UserUD") && !string.IsNullOrEmpty(filters["UserUD"].ToString()))
                    {
                        UserUD = filters["UserUD"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("FullName") && !string.IsNullOrEmpty(filters["FullName"].ToString()))
                    {
                        FullName = filters["FullName"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("PhoneNumber") && !string.IsNullOrEmpty(filters["PhoneNumber"].ToString()))
                    {
                        PhoneNumber = filters["PhoneNumber"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("Email") && !string.IsNullOrEmpty(filters["Email"].ToString()))
                    {
                        Email = filters["Email"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("PhoneNumber") && !string.IsNullOrEmpty(filters["PhoneNumber"].ToString()))
                    {
                        PhoneNumber = filters["PhoneNumber"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("SkypeID") && !string.IsNullOrEmpty(filters["SkypeID"].ToString()))
                    {
                        SkypeID = filters["SkypeID"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("UserGroupID") && !string.IsNullOrEmpty(filters["UserGroupID"].ToString()))
                    {
                        UserGroupID = Convert.ToInt32(filters["UserGroupID"].ToString());
                    }
                    if (filters.ContainsKey("OfficeID") && !string.IsNullOrEmpty(filters["OfficeID"].ToString()))
                    {
                        OfficeID = Convert.ToInt32(filters["OfficeID"].ToString());
                    }
                    if (filters.ContainsKey("IsActivated") && filters["IsActivated"] != null && !string.IsNullOrEmpty(filters["IsActivated"].ToString()))
                    {
                        IsActivated = (filters["IsActivated"].ToString() == "true") ? true : false;
                    }

                    totalRows = context.UserMng_function_SearchUserProfile(UserName, UserUD, FullName, UserGroupID, PhoneNumber, Email, SkypeID, OfficeID, IsActivated, orderBy, orderDirection).Count();
                    var result = context.UserMng_function_SearchUserProfile(UserName, UserUD, FullName, UserGroupID, PhoneNumber, Email, SkypeID, OfficeID, IsActivated, orderBy, orderDirection);

                    data.Data = converter.DB2DTO_UserProfileSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }