コード例 #1
0
        public T[] GetItems <T>() where T : class
        {
            Type                requestType = typeof(T);
            List <T>            items       = new List <T>();
            List <MobileEntity> mobEntities = new List <MobileEntity>();


            if (requestType == typeof(Event))
            {
                List <MobileEvent> mobileItems = this.sqliteConnection.GetAllWithChildren <MobileEvent>(null, true);
                if (mobileItems != null)
                {
                    foreach (var mobileItem in mobileItems)
                    {
                        Entity entity = converterService.Convert((mobileItem as MobileEntity));
                        items.Add(entity as T);
                    }
                }
            }
            else if (requestType == typeof(SettingsContainer))
            {
                List <MobileUser> mobileUsers = this.sqliteConnection.GetAllWithChildren <MobileUser>(null, true);

                if (mobileUsers != null && mobileUsers.Count > 0)
                {
                    if (mobileUsers.Count > 1)
                    {
                        throw new InvalidOperationException("More than one user in local database");
                    }

                    //ToDo Use AutoMapper

                    Setting setting = new Setting();

                    int tmpGuid;
                    if (int.TryParse(mobileUsers[0].Guid, out tmpGuid))
                    {
                        setting.Id             = tmpGuid;
                        setting.MaxDistance    = mobileUsers[0].MaxDistance;
                        setting.EventDateRange = Models.SettingsContainer.Convert(mobileUsers[0].EventDateRange);
                    }
                    //setting.ExcludedCategories = mobileUsers[0].ExcludedCategories;

                    SettingsContainer settingContainer = new SettingsContainer(null, null);
                    settingContainer.SetSetting(setting);


                    items.Add(settingContainer as T);
                }
            }
            else
            {
                throw new InvalidOperationException();
            }

            return(items.ToArray());
        }