Exemplo n.º 1
0
 //
 #region 专辑添加-编辑
 public ActionResult AlbumAdd(VideoAlbumModel model, string ReturnUrl, int ClassId = 0, Nullable <int> myid = 0)
 {
     model.ClassId = ClassId;
     #region 获取来路路径
     if (System.Web.HttpContext.Current.Request.UrlReferrer != null)
     {
         ViewBag.ReturnUrl = System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery;
     }
     #endregion
     ViewBag.Headline    = "专辑添加";                                         //栏目主题
     ViewBag.ButtonValue = "添加";                                           //按钮名称
     using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities()) //数据库操作
     {
         if ((myid > 0) && (model.Operate == null))
         {
             int mySelfId = 0;
             int.TryParse(myid.ToString(), out mySelfId);
             ViewBag.Headline    = "看一看专辑编辑";
             ViewBag.ButtonValue = "修改";
             model.Operate       = "edit";
             //
             #region 取出数据
             Child_Video_Album editRecord = myOperating.Child_Video_Album.FirstOrDefault(p => p.AlbumId == mySelfId);
             if (editRecord != null)
             {
                 model.ClassId      = editRecord.ClassId;
                 model.AlbumId      = editRecord.AlbumId;
                 model.AlbumTitle   = editRecord.AlbumTitle;
                 model.AlbumImage   = editRecord.AlbumImage;
                 model.AlbumDescrib = editRecord.AlbumDescrib;
                 model.OrderBy      = editRecord.OrderBy;
             }
             #endregion
         }
         else if (model.Operate == "add")
         {
             #region 保存添加
             if (ModelState.IsValid)
             {
                 Child_Video_Album addRecord = new Child_Video_Album();
                 addRecord.ClassId      = model.ClassId;
                 addRecord.AlbumTitle   = model.AlbumTitle;
                 addRecord.AlbumImage   = model.AlbumImage;
                 addRecord.AlbumDescrib = model.AlbumDescrib;
                 addRecord.AddDate      = DateTime.Now;
                 addRecord.VideoCount   = 0;
                 addRecord.PlayTimes    = 0;
                 addRecord.OrderBy      = model.OrderBy;
                 addRecord.Status       = 200;
                 //
                 myOperating.Child_Video_Album.Add(addRecord);
                 myOperating.SaveChanges();
                 model = null;
                 //
                 return(RedirectToLocal(ReturnUrl));
             }
             else
             {
                 ModelState.AddModelError("", "输入错误");
             }
             #endregion
         }
         else if (model.Operate == "edit")
         {
             #region 保存编辑
             if (ModelState.IsValid)
             {
                 Child_Video_Album editSaveRecord = myOperating.Child_Video_Album.FirstOrDefault(p => p.AlbumId == model.AlbumId);
                 if (editSaveRecord != null)
                 {
                     editSaveRecord.ClassId      = model.ClassId;
                     editSaveRecord.AlbumTitle   = model.AlbumTitle;
                     editSaveRecord.AlbumImage   = model.AlbumImage;
                     editSaveRecord.AlbumDescrib = model.AlbumDescrib;
                     editSaveRecord.OrderBy      = model.OrderBy;
                     //
                     myOperating.SaveChanges();
                     //
                     return(RedirectToLocal(ReturnUrl));
                 }
             }
             else
             {
                 ModelState.AddModelError("", "输入错误");
             }
             #endregion
         }
         else
         {
             model.Operate = "add";
             model.OrderBy = 1;
         }
         //
         List <Child_Video_Class> BookTable = myOperating.Child_Video_Class.ToList();
         //
         ViewBag.DataList = BookTable;
     }
     //
     return(View(model));
 }
Exemplo n.º 2
0
        //-------------------------
        #region 专辑列表
        public ActionResult AlbumList(string currentpage, int ClassId = 0, long del = 0)
        {
            #region 翻页定义
            ViewBag.CurrentPage = 0;  //当前页
            ViewBag.PPage       = 0;  //上一页
            ViewBag.NPage       = 0;  //下一页
            ViewBag.PageCount   = 0;  //总页数
            ViewBag.RecordCount = 0;  //记录总数
            ViewBag.IsFirstPage = ""; //第一条记录,禁用首页和上一页
            ViewBag.IsEndPage   = ""; //最后条记录,禁用首页和下一页
            #endregion
            //
            ViewBag.Headline = "专辑管理";//栏目主题
            //
            ViewBag.DataList   = null;
            ViewBag.RecordItem = null;
            ViewBag.Operate    = "add";                                           //add添加;edit编辑取出数据;editsave编辑保存
            //
            StatusData myStatusData = new StatusData();                           //返回状态
            //
            using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities()) //数据库操作
            {
                #region  除
                if (del > 0)
                {
                    Child_Video_Album myDelRecord = myOperating.Child_Video_Album.FirstOrDefault(p => p.AlbumId == del);
                    if (myDelRecord != null)
                    {
                        FunctionClass.delFile(myDelRecord.AlbumImage);
                        myOperating.Child_Video_Album.Remove(myDelRecord);
                        myOperating.SaveChanges();
                    }
                }
                #endregion
                //
                #region 翻页属性
                int    recordCount  = 0;
                int    pageCount    = 0;
                string orderbyfiled = "OrderBy";
                //
                //当前页
                int sqlCurrentpage = 1;
                if (!String.IsNullOrWhiteSpace(currentpage))
                {
                    bool isOk = int.TryParse(currentpage, out sqlCurrentpage);
                    if (!isOk)
                    {
                        sqlCurrentpage = 1;
                    }
                }
                //页大小
                int sqlPagesize = 10;
                #endregion
                //
                #region 取出内容
                IQueryable <Child_Video_Album> myIQueryable = null;
                if (ClassId > 0)
                {
                    myIQueryable = myOperating.Child_Video_Album.Where(p => p.ClassId == ClassId);
                }
                else
                {
                    myIQueryable = myOperating.Child_Video_Album.Where(p => p.Status == 200);
                }

                //
                if (myIQueryable != null)
                {
                    List <Child_Video_Album> BookTable = QueryableExtensions.OrderBy(myIQueryable, orderbyfiled, out recordCount, out pageCount, ref sqlCurrentpage, sqlPagesize, true).ToList();
                    //
                    ViewBag.DataList = BookTable;
                    #region 页数取值
                    ViewBag.CurrentPage = sqlCurrentpage;
                    ViewBag.PageCount   = pageCount;
                    ViewBag.RecordCount = recordCount;
                    if (sqlCurrentpage > 1)
                    {
                        ViewBag.PPage = sqlCurrentpage - 1;
                    }
                    else
                    {
                        ViewBag.IsFirstPage = "disabled";
                        ViewBag.PPage       = 1;
                    }
                    if (sqlCurrentpage < pageCount)
                    {
                        ViewBag.NPage = sqlCurrentpage + 1;
                    }
                    else
                    {
                        ViewBag.NPage     = sqlCurrentpage;
                        ViewBag.IsEndPage = "disabled";
                    }
                    #endregion
                }
                #endregion

                ViewBag.ClassId = ClassId;//当前类别
                List <Child_Video_Class> ClassTable = myOperating.Child_Video_Class.ToList();
                //
                ViewBag.DataListClass = ClassTable;
            }
            return(View());
        }