好幾天沒時間寫了。今天有寫時間在學一點。
今天狀態也不是很好,暈暈沉沉的寫吧。
序
一、用戶
二、用戶組
三、欄目
3.1添加欄目
首先添加【CategoryController】控制器,
那么我想我的視圖里,首先顯示的應該是欄目類型,這里應該是一個下拉框,用戶可以選擇“一般欄目”,“單頁欄目”,“外部鏈接”。那么首先應該在【CategoryController】添加一個屬性,用來返回欄目類型列表。
#region Attribute public List<SelectListItem> TypeSelectList { get { List<SelectListItem> _items = new List<SelectListItem>(); _items.Add(new SelectListItem { Text = CategoryType.一般欄目.ToString(), Value = ((int)CategoryType.一般欄目).ToString() }); _items.Add(new SelectListItem { Text = CategoryType.單頁欄目.ToString(), Value = ((int)CategoryType.單頁欄目).ToString() }); _items.Add(new SelectListItem { Text = CategoryType.外部鏈接.ToString(), Value = ((int)CategoryType.外部鏈接).ToString() }); return _items; } } #endregion
其次,用戶應該可以選擇內容模型,內容模型是什么?
內容模型就是這個欄目下可以添加內容的模型名稱?這個模型名稱對應的就是Models中間的模型類。為了更好的表述在系統中添加模塊“Module ”的概念。模塊用來指系統中用來實現相應功能的塊,想新聞模塊,文章模塊,留言模塊,圖片模塊,產品模塊,服務模塊等等,每個模塊對應相應的模型和控制器,用來實現設想中的功能。系統中預置的模塊用戶應該可以設置啟用還是關閉。
第一應該添加內容模型類
using System.ComponentModel.DataAnnotations;namespace Ninesky.Models{ /// <summary> /// 內容模塊 /// </summary> public class Module { [Key] public int ModuleId { get; set; } /// <summary> /// 模塊名稱 /// </summary> [Required(ErrorMessage="×")] [Display(Name="模塊名稱")] public string Name { get; set; } /// <summary> /// 模塊模型 /// </summary> [Required(ErrorMessage = "×")] [Display(Name = "模塊模型")] public string Model { get; set; } /// <summary> /// 啟用模塊 /// </summary> [Required(ErrorMessage = "×")] [Display(Name = "啟用模塊")] public bool Enable { get; set; } /// <summary> /// 說明 /// </summary> [Required(ErrorMessage = "×")] [Display(Name = "說明")] public string Description { get; set; } }}
既然有模塊類,就應該有模塊類的數據處理類ModuleRepository,這塊功能暫時留在后面來寫,先最簡單的實現List(bool enable)函數讓其能顯示模塊列表。
using Ninesky.Models;using System.Collections.Generic;using System.Linq;namespace Ninesky.Repository{ public class ModuleRepository { public IQueryable<Module> List(bool enable) { List<Module> _module = new List<Module>(); _module.Add(new Module { Name = "新聞模塊", Model = "News", Enable = true, Description = "新聞模塊" }); _module.Add(new Module { Name = "文章模塊", Model = "Article", Enable = true, Description = "文章模塊" }); return _module.AsQueryable(); } }}
新聞熱點
疑難解答
圖片精選