public ActionResult Index()
        {
            var projectRepository = new SimpleRepository <Project>();
            var projects          = projectRepository.All();
            var projectModels     = projects.Select(Mapper.Map <Project, ProjectModel>);

            return(View(projectModels));
        }
        public virtual System.Collections.Generic.IEnumerable <T> FindAll <T>() where T : class, new()
        {
            List <T> items = new List <T>();

            foreach (var item in dataRespository.All <T>())
            {
                items.Add(item);
            }
            return(items.ToArray());
        }
Beispiel #3
0
        public List <Calendar> QueryCalendars(DateTime st, DateTime ed, string useId)
        {
            var list = from n in _rep.All <Calendar>()
                       where n.UPAccount == useId && (
                (n.StartTime >= st && n.StartTime < ed) ||
                (n.EndTime >= st && n.EndTime < ed) ||
                (n.StartTime <st && n.EndTime> ed)
                )
                       orderby n.StartTime
                       select n;

            return(list.ToList());
        }
Beispiel #4
0
        /// <summary>
        /// 标签
        /// </summary>
        protected List <Tag> GetTag()
        {
            List <Tag> list = new List <Tag>();

            if (CacheHelper.Exists("Tag"))
            {
                list = (List <Tag>)CacheHelper.GetCache("Tag");
            }
            else
            {
                list = db.All <Tag>().ToList();
                CacheHelper.Insert("Tag", list);
            }
            return(list);
        }
        public static void Main(string[] args)
        {
            try
            {
                // generate database schema
                Repository.Single <ArticleCategory>(entity => entity.Name == "Schema Update");
                Repository.Single <ArticleComment>(entity => entity.Name == "Schema Update");
                Repository.Single <Article>(entity => entity.Name == "Schema Update");

                var category1 = new ArticleCategory {
                    Name = "ArticleCategory 1"
                };
                var category2 = new ArticleCategory {
                    Name = "ArticleCategory 2"
                };
                var category3 = new ArticleCategory {
                    Name = "ArticleCategory 3"
                };

                // clear/populate the database
                Repository.DeleteMany((ArticleCategory entity) => true);
                var cat1Id = Convert.ToInt32(Repository.Add(category1));
                var cat2Id = Convert.ToInt32(Repository.Add(category2));
                var cat3Id = Convert.ToInt32(Repository.Add(category3));

                Repository.DeleteMany((Article entity) => true);
                var article1 = new Article {
                    Name = "Article 1", ArticleCategoryId = cat1Id
                };
                var article2 = new Article {
                    Name = "Article 2", ArticleCategoryId = cat2Id
                };
                var article3 = new Article {
                    Name = "Article 3", ArticleCategoryId = cat3Id
                };

                var art1Id = Convert.ToInt32(Repository.Add(article1));
                var art2Id = Convert.ToInt32(Repository.Add(article2));
                var art3Id = Convert.ToInt32(Repository.Add(article3));

                Repository.DeleteMany((ArticleComment entity) => true);
                var comment1 = new ArticleComment {
                    Body = "This is comment 1", Name = "Comment1", ArticleId = art1Id
                };
                var comment2 = new ArticleComment {
                    Body = "This is comment 2", Name = "Comment2", ArticleId = art1Id
                };
                var comment3 = new ArticleComment {
                    Body = "This is comment 3", Name = "Comment3", ArticleId = art1Id
                };
                var comment4 = new ArticleComment {
                    Body = "This is comment 4", Name = "Comment4", ArticleId = art2Id
                };
                var comment5 = new ArticleComment {
                    Body = "This is comment 5", Name = "Comment5", ArticleId = art2Id
                };
                var comment6 = new ArticleComment {
                    Body = "This is comment 6", Name = "Comment6", ArticleId = art2Id
                };
                var comment7 = new ArticleComment {
                    Body = "This is comment 7", Name = "Comment7", ArticleId = art3Id
                };
                var comment8 = new ArticleComment {
                    Body = "This is comment 8", Name = "Comment8", ArticleId = art3Id
                };
                var comment9 = new ArticleComment {
                    Body = "This is comment 9", Name = "Comment9", ArticleId = art3Id
                };
                Repository.Add(comment1);
                Repository.Add(comment2);
                Repository.Add(comment3);
                Repository.Add(comment4);
                Repository.Add(comment5);
                Repository.Add(comment6);
                Repository.Add(comment7);
                Repository.Add(comment8);
                Repository.Add(comment9);

                // verify the database generation
                Debug.Assert(Repository.All <Article>().Count() == 3);
                Debug.Assert(Repository.All <ArticleCategory>().Count() == 3);
                Debug.Assert(Repository.All <ArticleComment>().Count() == 9);

                // fetch a master list of articles from the database
                var articles =
                    (from article in Repository.All <Article>()
                     join category in Repository.All <ArticleCategory>()
                     on article.ArticleCategoryId equals category.Id
                     join comment in Repository.All <ArticleComment>()
                     on article.Id equals comment.ArticleId
                     select article)
                    .Distinct()
                    .ToList();

                foreach (var article in articles)
                {
                    Console.WriteLine(article.Name + " ID " + article.Id);
                    Console.WriteLine("\t" + article.Category.Name + " ID " + article.Category.Id);

                    foreach (var articleComment in article.Comments)
                    {
                        Console.WriteLine("\t\t" + articleComment.Name + " ID " + articleComment.Id);
                        Console.WriteLine("\t\t\t" + articleComment.Body);
                    }
                }

                // OUTPUT (ID will vary as autoincrement SQL index

                //Article 1 ID 28
                //        ArticleCategory 1 ID 41
                //                Comment1 ID 100
                //                        This is comment 1
                //                Comment2 ID 101
                //                        This is comment 2
                //                Comment3 ID 102
                //                        This is comment 3
                //Article 2 ID 29
                //        ArticleCategory 2 ID 42
                //                Comment4 ID 103
                //                        This is comment 4
                //                Comment5 ID 104
                //                        This is comment 5
                //                Comment6 ID 105
                //                        This is comment 6
                //Article 3 ID 30
                //        ArticleCategory 3 ID 43
                //                Comment7 ID 106
                //                        This is comment 7
                //                Comment8 ID 107
                //                        This is comment 8
                //                Comment9 ID 108
                //                        This is comment 9

                Console.ReadLine();

                // BETTER WAY (imho)...(joins aren't needed thus freeing up SQL overhead)

                // fetch a master list of articles from the database
                articles = Repository.All <Article>().ToList();

                foreach (var article in articles)
                {
                    Console.WriteLine(article.Name + " ID " + article.Id);
                    Console.WriteLine("\t" + article.Category.Name + " ID " + article.Category.Id);

                    foreach (var articleComment in article.Comments)
                    {
                        Console.WriteLine("\t\t" + articleComment.Name + " ID " + articleComment.Id);
                        Console.WriteLine("\t\t\t" + articleComment.Body);
                    }
                }

                Console.ReadLine();

                // OUTPUT should be identicle
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadLine();
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var loss = 0;

            EGT_OTA.Models.Repository.UpdateDB();
            SimpleRepository db = Repository.GetRepo();

            try
            {
                var CurrDatabase = Tools.SafeString(System.Web.Configuration.WebConfigurationManager.AppSettings["CurrDatabase"]);

                Console.WriteLine("正在运行");

                var music01 = new List <Music01>();
                var music02 = new List <Music02>();
                var music03 = new List <Music03>();
                var music04 = new List <Music04>();
                var music05 = new List <Music05>();
                var music06 = new List <Music06>();
                var music07 = new List <Music07>();
                var music08 = new List <Music08>();
                var music09 = new List <Music09>();
                var music10 = new List <Music10>();
                var music11 = new List <Music11>();
                var music12 = new List <Music12>();
                var music13 = new List <Music13>();

                Console.WriteLine("读取Music01");

                if (CurrDatabase.Contains(",1,"))
                {
                    music01 = db.All <Music01>().ToList();
                    music01.ForEach(x =>
                    {
                        x.DataBaseNumber = 1;
                    });
                }

                Console.WriteLine("读取Music02");

                if (CurrDatabase.Contains(",2,"))
                {
                    music02 = db.All <Music02>().ToList();
                    music02.ForEach(x =>
                    {
                        x.DataBaseNumber = 2;
                    });
                }

                Console.WriteLine("读取Music03");

                if (CurrDatabase.Contains(",3,"))
                {
                    music03 = db.All <Music03>().ToList();
                    music03.ForEach(x =>
                    {
                        x.DataBaseNumber = 3;
                    });
                }

                Console.WriteLine("读取Music04");

                if (CurrDatabase.Contains(",4,"))
                {
                    music04 = db.All <Music04>().ToList();
                    music04.ForEach(x =>
                    {
                        x.DataBaseNumber = 4;
                    });
                }

                Console.WriteLine("读取Music05");

                if (CurrDatabase.Contains(",5,"))
                {
                    music05 = db.All <Music05>().ToList();
                    music05.ForEach(x =>
                    {
                        x.DataBaseNumber = 5;
                    });
                }

                Console.WriteLine("读取Music06");

                if (CurrDatabase.Contains(",6,"))
                {
                    music06 = db.All <Music06>().ToList();
                    music06.ForEach(x =>
                    {
                        x.DataBaseNumber = 6;
                    });
                }

                Console.WriteLine("读取Music07");

                if (CurrDatabase.Contains(",7,"))
                {
                    music07 = db.All <Music07>().ToList();
                    music07.ForEach(x =>
                    {
                        x.DataBaseNumber = 7;
                    });
                }

                Console.WriteLine("读取Music08");

                if (CurrDatabase.Contains(",8,"))
                {
                    music08 = db.All <Music08>().ToList();
                    music08.ForEach(x =>
                    {
                        x.DataBaseNumber = 8;
                    });
                }

                Console.WriteLine("读取Music09");

                if (CurrDatabase.Contains(",9,"))
                {
                    music09 = db.All <Music09>().ToList();
                    music09.ForEach(x =>
                    {
                        x.DataBaseNumber = 9;
                    });
                }

                Console.WriteLine("读取Music10");

                if (CurrDatabase.Contains(",10,"))
                {
                    music10 = db.All <Music10>().ToList();
                    music10.ForEach(x =>
                    {
                        x.DataBaseNumber = 10;
                    });
                }

                Console.WriteLine("读取Music11");

                if (CurrDatabase.Contains(",11,"))
                {
                    music11 = db.All <Music11>().ToList();
                    music11.ForEach(x =>
                    {
                        x.DataBaseNumber = 11;
                    });
                }

                Console.WriteLine("读取Music12");

                if (CurrDatabase.Contains(",12,"))
                {
                    music12 = db.All <Music12>().ToList();
                    music12.ForEach(x =>
                    {
                        x.DataBaseNumber = 12;
                    });
                }

                Console.WriteLine("读取Music13");

                if (CurrDatabase.Contains(",13,"))
                {
                    music13 = db.All <Music13>().ToList();
                    music13.ForEach(x =>
                    {
                        x.DataBaseNumber = 13;
                    });
                }

                var list = new List <Music>();
                list.AddRange(music01);
                list.AddRange(music02);
                list.AddRange(music03);
                list.AddRange(music04);
                list.AddRange(music05);
                list.AddRange(music06);
                list.AddRange(music07);
                list.AddRange(music08);
                list.AddRange(music09);
                list.AddRange(music10);
                list.AddRange(music11);
                list.AddRange(music12);
                list.AddRange(music13);

                var LineCount = Tools.SafeInt(System.Web.Configuration.WebConfigurationManager.AppSettings["LineCount"]);


                for (var i = 0; i < LineCount; i++)
                {
                    Thread thread = new Thread(delegate()
                    {
                        while (list.Count > 0)
                        {
                            lock (locker)
                            {
                                var model  = list[0];
                                var result = CheckFile(model);
                                if (!result)
                                {
                                    switch (model.DataBaseNumber)
                                    {
                                    case 1:
                                        db.Delete <Music01>(model.ID);
                                        break;

                                    case 2:
                                        db.Delete <Music02>(model.ID);
                                        break;

                                    case 3:
                                        db.Delete <Music03>(model.ID);
                                        break;

                                    case 4:
                                        db.Delete <Music04>(model.ID);
                                        break;

                                    case 5:
                                        db.Delete <Music05>(model.ID);
                                        break;

                                    case 6:
                                        db.Delete <Music06>(model.ID);
                                        break;

                                    case 7:
                                        db.Delete <Music07>(model.ID);
                                        break;

                                    case 8:
                                        db.Delete <Music08>(model.ID);
                                        break;

                                    case 9:
                                        db.Delete <Music09>(model.ID);
                                        break;

                                    case 10:
                                        db.Delete <Music10>(model.ID);
                                        break;

                                    case 11:
                                        db.Delete <Music11>(model.ID);
                                        break;

                                    case 12:
                                        db.Delete <Music12>(model.ID);
                                        break;

                                    case 13:
                                        db.Delete <Music13>(model.ID);
                                        break;

                                    default:
                                        break;
                                    }

                                    loss++;
                                }
                                list.RemoveAt(0);
                            }
                            Thread.Sleep(1000);
                        }
                    });
                    thread.IsBackground = true;
                    thread.Name         = "过滤音乐接口线程" + i;
                    thread.Start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }