Esempio n. 1
0
        //分布视图
        public ActionResult Slide()
        {
            List <blog_Table> list = new List <blog_Table>();

            int[]    ID = new int[100];
            double[] star = new double[100];
            int      sum = 0, flag = 0;
            personal_blogEntities3 db = new personal_blogEntities3();
            var find = db.blog_Table;

            foreach (var read in find)
            {
                ID[sum]     = read.BlogID;
                star[sum++] = read.Star;
            }

            //冒泡排序 使用两个数组分别保存对象的ID和Star属性 对Star属性进行降序排序
            for (int i = 0; i < sum; i++)
            {
                for (int j = 0; j < sum - i - 1; j++)
                {
                    if (star[j] < star[j + 1])
                    {
                        int temp1; double temp2;
                        temp1 = ID[j]; ID[j] = ID[j + 1]; ID[j + 1] = temp1;
                        temp2 = star[j]; star[j] = star[j + 1]; star[j + 1] = temp2;
                        flag  = 1;
                    }
                }
                //如果标志为0 说明数组已经是降序排列 提前结束排序
                if (flag == 0)
                {
                    break;
                }
            }
            for (int i = 0; i < sum; i++)
            {
                blog_Table blog = new blog_Table();
                int        id   = ID[i];
                blog = new blog_function().Find(p => p.BlogID == id);
                list.Add(blog);
            }
            return(View(list));
        }
 public ActionResult Index(blog_Table movie)
 {
     movie.DateTime = DateTime.Now;
     new blog_function().Add(movie);
     return(RedirectToAction("Index", "BlogManage"));
 }