三个文件夹,第一个是放置前端部分,第二个是各种支持的类文件,第三个是单元测试文件。

 

Core文件类库


放置的是与数据库做交互的文件,以及一些第三方类库,还有与数据库连接的文件

1.Lasy.Validator是一个基于Attribute验证器,我觉得这种验证方式在挺便捷的,具体可以在这里查看到http://www.cnblogs.com/over140/archive/2009/07/04/1515892.html
2.ToJson是一个将数据转换成json格式的字符串的一个类库,很便捷
3.NPinyin是一个将中文转换成拼音的一个类别

app.config是一个连接数据库的配置文件,两个数据库一个是测试用的,一个是调试用的

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="QuyouCore.Properties.Settings.ClubConnectionString"
            connectionString="Data Source=192.168.1.214;Initial Catalog=Club;User ID=sa;Password=123456"
            providerName="System.Data.SqlClient" />
        <add name="QuyouCore.Properties.Settings.ClubTestConnectionString"
            connectionString="Data Source=192.168.1.214;Initial Catalog=Club_Test;User ID=sa;Password=123456" />
    </connectionStrings>
</configuration>

点击core文件夹进入数据库操作

1.DataAccess

DataAccess中主要就是一些数据库的增删改查操作了

Connection.cs是连接数据的文件,主要根据前端文件夹下面的bin文件中的XML文件来操作是连接哪个数据库,用XML就可以很方便的不重新编译直接换数据库

<?xml version="1.0" encoding="utf-8" ?>
<connectionStringToUse>
  <!-- this value can be Local (pc), Production (server), or Test (test)-->
  <environment>Production</environment>
</connectionStringToUse>
 1 using System;
 2 using System.Web;
 3 using System.Xml;
 4 using QuyouCore.Core.Domain;
 5 using QuyouCore.Properties;
 6 
 7 namespace QuyouCore.Core.DataAccess.Impl
 8 {
 9     public class Connection
10     {
11         public Connection()
12         {
13             ConnString = GetCurrentConnectionString();
14         }
15         public ClubDataContext GetClubContext()
16         {
17             var vcd = new ClubDataContext(ConnString);
18             //vcd.Log = new DebuggerWriter();
19             return vcd;
20         }
21         public string GetCurrentConnectionString()
22         {
23             var connString = string.Empty;
24             try
25             {
26                 var doc = new XmlDocument();
27                 doc.Load(HttpContext.Current.Request.PhysicalApplicationPath + "bin/ConnectionStringToUse.xml");
28                 var xnl = doc.GetElementsByTagName("environment");
29                 var xe = (XmlElement)xnl[0];
30                 switch (xe.InnerText.ToLower())
31                 {
32                     case "local":
33                         connString = Settings.Default.ClubConnectionString;
34                         break;
35                     case "production":
36                         connString = Settings.Default.ClubServerConnectionString;
37                         break;
38                     case "test":
39                         connString = Settings.Default.ClubTestConnectionString;
40                         break;
41                 }
42             }
43             catch (Exception e)
44             {
45                 connString = Settings.Default.ClubTestConnectionString;
46             }
47             return connString;
48         }
49 
50         public string ConnString
51         {
52             get;
53             set;
54         }
55     }
56 }

BaseRepository.cs文件是做一些通用的Linq查询语句,还有就是写Log操作,将各个查询语句记录下来,便于调试,这里用到的Log工具是log4net

using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using QuyouCore.Core.Domain;
using QuyouCore.Core.Enum;
using QuyouCore.Core.Util;
using System;
using System.Linq.Expressions;
namespace QuyouCore.Core.DataAccess.Impl
{
    public class BaseRepository
    {
        protected BaseRepository()
        {
            Conn = new Connection();
            DataContext = new RepositoryContext(Conn.ConnString);
        }
        #region Properties
        /// <summary>
        /// Gets or sets the data context.
        /// </summary>
        /// <value>The data context.</value>
        private RepositoryContext DataContext { get; set; }
        protected Connection Conn { get; set; }
        #endregion

        #region Entity and metadata functions
        /// <summary>
        /// 分页
        /// </summary>
        protected DataPageList<TEntity> GetEntitiesByPage<TEntity>(IQueryable query, int page, int size, DataContext context)
        {
            context.Log = FileLog.Out;
            var data = DataPageList<TEntity>.Create<TEntity>(query, page, size);
            WriteLog(FileLog.FileInfo.ToString());
            return data;
        }
        /// <summary>
        /// 根据条件获取一条数据
        /// </summary>
        protected TEntity GetEntity<TEntity>(Expression<Func<TEntity, bool>> queryFunc) where TEntity : class //Entity
        {
            DataContext.Log = FileLog.Out;
            var results = from entity in DataContext.GetTable<TEntity>()
                          select entity;
            results = results.Where(queryFunc);
            var result = results.FirstOrDefault();
            WriteLog(FileLog.FileInfo.ToString());
            return result;
        }
        /// <summary>
        /// 根据条件获取数据信息列
        /// </summary>
        protected List<TEntity> GetEntities<TEntity>(Expression<Func<TEntity, bool>> queryFunc) where TEntity : class //Entity 
        {
            DataContext.Log = FileLog.Out;
            var query = from entity in DataContext.GetTable<TEntity>()
                          select entity;
            query = query.Where(queryFunc);
            var results = query.ToList();
            WriteLog(FileLog.FileInfo.ToString());
            return results;
        }
        protected List<TEntity> GetEntities<TEntity>(IQueryable<TEntity> query) where TEntity : class //Entity 
        {
            DataContext.Log = FileLog.Out;
            var results = query.ToList();
            WriteLog(FileLog.FileInfo.ToString());
            return results;
        }
        protected IQueryable<TEntity> GetQueryEntities<TEntity>(Expression<Func<TEntity, bool>> queryFunc) where TEntity : class //Entity 
        {
            var query = from entity in DataContext.GetTable<TEntity>()
                        select entity;
            return query.Where(queryFunc);
        }
        /// <summary>
        /// 获取所有数据
        /// </summary>
        protected List<TEntity> GetEntities<TEntity>() where TEntity : class //Entity 
        {
            DataContext.Log = FileLog.Out;
            var query = from entity in DataContext.GetTable<TEntity>()
                          select entity;
            var results = query.ToList();
            WriteLog(FileLog.FileInfo.ToString());
            return results;
        }
        #endregion


        protected void WriteLog(string log)
        {
            WriteLog(log, EnumLog.Level.Info);
        }
        protected void WriteLog(string log, EnumLog.Level level)
        {
            switch (level)
            {
                case EnumLog.Level.Debug: 
                    LogHelper.GetInstance().Debug(log);
                    break;
                case EnumLog.Level.Error:
                    LogHelper.GetInstance().Error(log);
                    break;
                case EnumLog.Level.Warn:
                    LogHelper.GetInstance().Warn(log);
                    break;
                case EnumLog.Level.Fatal:
                    LogHelper.GetInstance().Fatal(log);
                    break;
                case EnumLog.Level.Info:
                    LogHelper.GetInstance().Info(log);
                    break;
                default:
                    LogHelper.GetInstance().Info(log);
                    break;
            }
            //LogHelper.GetInstance().Logger.Repository.Shutdown();
        }
    }
}

下面的代码是一些简单的增删改查,但是一些比较难的SQL语句,有时候比较棘手,你可以使用一个翻译工具,将SQL转换成,叫做Linqer,使用操作也很简单,操作界面如图。

using System.Collections.Generic;
using System.Linq;
using QuyouCore.Core.Domain;

namespace QuyouCore.Core.DataAccess.Impl
{
    public class KeywordRepository : BaseRepository, IKeywordRepository
    {
        public int Insert(tb_Keyword data)
        {
            using (var cd = Conn.GetClubContext())
            {
                cd.tb_Keyword.InsertOnSubmit(data);
                cd.SubmitChanges();
                return data.KeywordTypeId;
            }
        }

        /// <summary>
        /// 根据主键更新表内容
        /// </summary>
        public void Update(tb_Keyword data)
        {
            using (var cd = Conn.GetClubContext())
            {
                var update = cd.tb_Keyword.Single(t => t.KeywordId == data.KeywordId);
                update.KeywordTypeId = data.KeywordTypeId;
                update.Name = data.Name;
                update.Pinyin = data.Pinyin;
                cd.SubmitChanges();
            }
        }

        /// <summary>
        /// 根据编号将信息更新为删除状态
        /// </summary>
        public void Delete(int id)
        {
            using (var cd = Conn.GetClubContext())
            {
                var update = cd.tb_Keyword.Single(t => t.KeywordId == id);
                update.Active = false;
                cd.SubmitChanges();
            }
        }

        public List<tb_Keyword> GetKeywordsByTypeId(tb_Keyword data)
        {
            return GetEntities<tb_Keyword>(
                t => t.Active == data.Active &&
                     t.KeywordTypeId == data.KeywordTypeId
                );
        }
    }
}

 

2.Domain

Domain文件里面的Club.dml内容是自动生成的

在这里面还放了一些,数据库表格的扩展字段以及一个分页类DataPageList.cs

namespace QuyouCore.Core.Domain
{
    public partial class tb_Keyword
    {
        //public static readonly string TableName = "tb_Keyword";
        //public static readonly string ColumnKeywordId = "KeywordId";
        //public static readonly string ColumnKeywordTypeId = "KeywordTypeId";
        //public static readonly string ColumnName = "Name";
        //public static readonly string ColumnAddTime = "AddTime";
    }
}
  1 using System.Collections;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 
  5 namespace QuyouCore.Core.Domain
  6 {
  7     /// <summary>
  8     /// 数据列表
  9     /// </summary>
 10     /// <typeparam name="T">类型</typeparam>
 11     public class DataPageList<T> : IEnumerable
 12     {
 13         #region 成员变量
 14 
 15         private System.Linq.IQueryable<T> query;
 16         private int allRecordCount;
 17         private int thisPageRecordCount;
 18         private int pageSize;
 19         private int pageCount;
 20         private int indexPage;
 21         private bool canFirstPage;
 22         private bool canPrevPage;
 23         private bool canNextPage;
 24         private bool canLastpage;
 25         private List<T> listValue;
 26 
 27         #endregion
 28 
 29 
 30         #region 构造函数
 31 
 32         //私有构造函数,只能通过内部构造
 33         private DataPageList(System.Linq.IQueryable<T> Query, int IndexPage, int PageSize)
 34         {
 35             query = Query;
 36             indexPage = IndexPage;
 37             pageSize = PageSize;
 38             PageAttrList = new List<PageAttr>();
 39             Update();
 40         }
 41 
 42         private DataPageList(System.Linq.IQueryable<T> Query)
 43             : this(Query, 1, 0)
 44         {
 45         }
 46 
 47         #endregion
 48 
 49 
 50         #region 属性
 51 
 52         public int AllRecordCount
 53         {
 54             get { return allRecordCount; }
 55         }
 56 
 57         public int ThisPageRecordCount
 58         {
 59             get { return thisPageRecordCount; }
 60         }
 61 
 62         public int PageSize
 63         {
 64             get { return pageSize; }
 65             set { pageSize = value; }
 66         }
 67 
 68         public int PageCount
 69         {
 70             get { return pageCount; }
 71         }
 72 
 73         public int IndexPage
 74         {
 75             get { return indexPage; }
 76             set { indexPage = value; }
 77         }
 78 
 79         public bool CanFirstPage
 80         {
 81             get { return canFirstPage; }
 82         }
 83 
 84         public bool CanPrevPage
 85         {
 86             get { return canPrevPage; }
 87         }
 88 
 89         public bool CanNextPage
 90         {
 91             get { return canNextPage; }
 92         }
 93 
 94         public bool CanLastPage
 95         {
 96             get { return canLastpage; }
 97         }
 98 
 99         public List<T> Value
100         {
101             get { return listValue; }
102         }
103 
104         public class PageAttr
105         {
106             public int Page { get; set; }
107         }
108 
109         public List<PageAttr> PageAttrList
110         {
111             get; set;
112         }
113         #endregion
114 
115         #region 索引器
116 
117         public T this[int index]
118         {
119             get { return listValue[index]; }
120             set { listValue[index] = value; }
121         }
122 
123         #endregion
124 
125         #region 公开方法
126 
127         /**/
128 
129         /// <summary>
130         /// 创建自身实例
131         /// </summary>
132         /// <typeparam name="N">类型,如果此处为匿名类型,请用var 定义实体,且类后的T为object(其实什么也不重要,只是用于可以调用当前类的静态方法)</typeparam>
133         /// <param name="Query">Linq查询语句</param>
134         /// <param name="type">元素类型</param>
135         /// <param name="IndexPage">开始页</param>
136         /// <param name="PageSize">每页大小</param>
137         /// <returns></returns>
138         public static DataPageList<N> Create<N>(System.Linq.IQueryable Query, int IndexPage, int PageSize)
139         {
140             System.Linq.IQueryable<N> query = (System.Linq.IQueryable<N>) Query;
141             return new DataPageList<N>(query, IndexPage, PageSize);
142         }
143 
144         //public static DataPageList<N> Create<N>(System.Linq.IQueryable Query, int IndexPage, int PageSize)
145         //{
146         //    return Create<N>(Query, IndexPage, PageSize);
147         //}
148 
149         /**/
150 
151         /// <summary>
152         /// 更新数据
153         /// </summary>
154         public virtual void Update()
155         {
156             allRecordCount = query.Count();
157             PageAttrList.Clear();
158             if (pageSize > 0)
159             {
160                 query = query.Skip((indexPage - 1) * pageSize).Take(pageSize);
161                 thisPageRecordCount = query.Count();
162                 //计算分页结果
163                 pageCount = (allRecordCount%pageSize == 0) ? (allRecordCount/pageSize) : allRecordCount/pageSize + 1;
164                 if (indexPage > 1) canFirstPage = true;
165                 canPrevPage = true;
166                 if (indexPage < pageCount) canNextPage = true;
167                 canLastpage = true;
168             }
169             else
170             {
171                 thisPageRecordCount = allRecordCount;
172                 pageCount = indexPage = 1;
173                 canFirstPage = canPrevPage = canNextPage = canLastpage = false;
174             }
175             for (var cur = 1; cur <= pageCount; cur++)
176             {
177                 PageAttrList.Add(new PageAttr {Page = cur});
178             }
179             listValue = query.ToList();
180         }
181 
182         /**/
183 
184         /// <summary>
185         /// 实现枚举接口,不过返回的是object
186         /// </summary>
187         /// <returns></returns>
188         public IEnumerator GetEnumerator()
189         {
190             return listValue.GetEnumerator();
191         }
192 
193         #endregion
194     }
195 }

 

3.Entity

这里面打算放的是一些额外的数据字段,例如一些方法的参数集合、公共的JSON返回格式等

Prompt.cs就是返回JSON格式的

 1 using System.Collections.Generic;
 2 using LitJson;
 3 namespace QuyouCore.Core.Entity
 4 {
 5     public class Prompt
 6     {
 7         public int Number
 8         {
 9             get; set;
10         }
11 
12         public string Msg
13         {
14             get;
15             set;
16         }
17 
18         public static string ToJson(int number, string msg)
19         {
20             var prompt = new Prompt {Number = number, Msg = msg};
21             return JsonMapper.ToJson(prompt);
22         }
23 
24         public static string ToJson<T>(int number, string msg, List<T> data)
25         {
26             var prompt = new PromptTemplate<T> { Number = number, Msg = msg, DataList = data };
27             return JsonMapper.ToJson(prompt);
28         }
29     }
30 }

 

4.Enum

这里放的是一些数据字典

namespace QuyouCore.Core.Enum
{
    public class EnumLog
    {
        public enum Level
        {
            Fatal = 1,
            Error = 2,
            Warn = 3,
            Debug = 4,
            Info = 5
        }
    }
}

 

5.Service

这里面放了一些业务逻辑,比如根据条件查询等,因为打算在API、Web、Wap上面共用代码,所以就想把一些通用的逻辑整合在一起,这里用到了一种单例模式,使用的工具是StructureMap

 1 using System.Collections.Generic;
 2 using Lasy.Validator;
 3 using QuyouCore.Core.Entity;
 4 using QuyouCore.Core.Enum;
 5 using StructureMap;
 6 
 7 namespace QuyouCore.Core.Service.Impl
 8 {
 9     public abstract class BaseService
10     {
11         protected abstract IContainer ConfigureDependencies();//单例配置化
12         
13         protected string PromptToJson(int prompt)
14         {
15             return Prompt.ToJson(prompt, EnumCommon.GetPrompt()[prompt]);
16         }
17 
18         protected string PromptToJson<T>(int prompt, List<T> dataList)
19         {
20             return Prompt.ToJson(prompt, EnumCommon.GetPrompt()[prompt], dataList);
21         }
22 
23         /// <summary>
24         /// 用Attribute做字段验证
25         /// </summary>
26         /// <typeparam name="T"></typeparam>
27         /// <param name="dict"></param>
28         /// <returns></returns>
29         protected string ValidateParameters<T>(Dictionary<string, object> dict)
30         {
31             var validator = new Validator(typeof(T));
32             if (!validator.Validate(dict).BoolResult)
33             {
34                 return validator.Validate(dict).ErrorStringWithoutFormat;
35             }
36             return string.Empty;
37         }
38     }
39 }
 1 using System.Collections.Generic;
 2 using QuyouCore.Core.DataAccess;
 3 using QuyouCore.Core.DataAccess.Impl;
 4 using QuyouCore.Core.Domain;
 5 using StructureMap;
 6 using QuyouCore.Core.Util;
 7 namespace QuyouCore.Core.Service.Impl
 8 {
 9     public class KeywordService : BaseService, IKeywordService
10     {
11         protected override IContainer ConfigureDependencies()
12         {
13             return new Container(x =>
14             {
15                 x.For<IKeywordTypeRepository>().Use<KeywordTypeRepository>();
16                 x.For<IKeywordRepository>().Use<KeywordRepository>();
17             });
18         }
19         private IKeywordTypeRepository InitKeywordTypeRepository()
20         {
21             var container = ConfigureDependencies();
22             return container.GetInstance<IKeywordTypeRepository>();
23         }
24         private IKeywordRepository InitKeywordRepository()
25         {
26             var container = ConfigureDependencies();
27             return container.GetInstance<IKeywordRepository>();
28         }
29 
30         public string Insert(tb_Keyword data)
31         {
32             var keywordRepository = InitKeywordRepository();
33             var result = keywordRepository.Insert(data);
34             return PromptToJson(result > 0 ? Const.PromptSuccess : Const.PromptFailure);
35         }
36 
37         public string Update(tb_Keyword data)
38         {
39             var keywordRepository = InitKeywordRepository();
40             keywordRepository.Update(data);
41             return PromptToJson(Const.PromptSuccess);
42         }
43 
44         public string Delete(int id)
45         {
46             var keywordRepository = InitKeywordRepository();
47             keywordRepository.Delete(id);
48             return PromptToJson(Const.PromptSuccess);
49         }
50 
51         public string GetSelectedKeywords(tb_KeywordType data)
52         {
53             var typeRepository = InitKeywordTypeRepository();
54             var keywordRepository = InitKeywordRepository();
55 
56             data.Active = true;
57             data.ParentTypeId = 0;
58             //根据线路类型 版块 类别查询出关键字类别
59             var allTypes = new List<tb_KeywordType>(); //一级 二级的关键字类别 现在只分到二级 TODO
60             var types = typeRepository.GetSelectedTypesByParentId(data);
61             foreach (var tbKeywordType in types)
62             {
63                 allTypes.Add(tbKeywordType);
64                 data.ParentTypeId = tbKeywordType.KeywordTypeId;
65                 var children = typeRepository.GetSelectedTypesByParentId(data);
66                 if (children.Count <= 0) continue;
67                 allTypes.AddRange(children);
68             }
69 
70             //查询关键字内容
71             //var allKeywords = new List<tb_Keyword>();
72             var allKeywords = new List<tb_KeywordType>();
73             var condition = new tb_Keyword {Active = true};
74             foreach (var tbKeywordType in allTypes)
75             {
76                 //allKeywords.Add(new tb_Keyword
77                 //{
78                 //    KeywordTypeName = tbKeywordType.Name,
79                 //    IsKeywordType = true,
80                 //    Pinyin = string.Empty,
81                 //    Name = string.Empty
82                 //});
83                 condition.KeywordTypeId = tbKeywordType.KeywordTypeId;
84                 var keywords = keywordRepository.GetKeywordsByTypeId(condition);
85                 if (keywords.Count <= 0)
86                 {
87                     allKeywords.Add(tbKeywordType);
88                     continue;
89                 }
90                 tbKeywordType.Keywords = keywords;
91                 allKeywords.Add(tbKeywordType);
92             }
93             return PromptToJson(Const.PromptSuccess, allKeywords);
94         }
95     }
96 }

 

6.Util

主要放些小工具类,比如Log写工具、cookie操作、图片压缩类等

 

Tests文件类库

健壮的代码是需要有单元测试来做保障的,所以单元测试必不可少。用到的工具是NUnit,测试的点可以发挥大家的想象力。怎么测都行。

 

 1 using System;
 2 using NUnit.Framework;
 3 using QuyouCore.Core.DataAccess;
 4 using QuyouCore.Core.DataAccess.Impl;
 5 using QuyouCore.Core.Domain;
 6 using StructureMap;
 7 
 8 namespace QuyouTests.core.DataAccess
 9 {
10     [TestFixture]
11     public class KeywordRepositoryTest
12     {
13         private IKeywordRepository _keywordModel;
14 
15         [TestFixtureSetUp]
16         public void Init()
17         {
18             var container = new Container(x => x.For<IKeywordRepository>().Use<KeywordRepository>());
19             _keywordModel = container.GetInstance<IKeywordRepository>();
20         }
21 
22         [Test]
23         public void TestInsert()
24         {
25             var data = new tb_Keyword
26             {
27                 KeywordTypeId = 1,
28                 Name = "塔里木",
29                 AddTime = DateTime.Now,
30                 Pinyin = "talimu",
31                 Active = true
32             };
33             var result = _keywordModel.Insert(data);
34             Assert.Greater(result, 0);
35         }
36 
37         [Test]
38         public void TestUpdate()
39         {
40             var data = new tb_Keyword
41             {
42                 KeywordId = 1,
43                 KeywordTypeId = 2,
44                 Name = "莫干山",
45                 Pinyin = "moganshan"
46             };
47             _keywordModel.Update(data);
48         }
49 
50         [Test]
51         public void TestDelete()
52         {
53             _keywordModel.Delete(1);
54         }
55     }
56 }

 

Quyou文件夹

这里就是与页面操作的代码,脚本、CSS等都在里面

Presenter文件夹里面的类是用于操作界面逻辑,以及过滤传过来的数据

  1 using System;
  2 using NPinyin;
  3 using Quyou.admin.Interface;
  4 using QuyouCore.Core.Domain;
  5 using QuyouCore.Core.Entity;
  6 using QuyouCore.Core.Service;
  7 using QuyouCore.Core.Service.Impl;
  8 using QuyouCore.Core.Util;
  9 using StructureMap;
 10 using System.Collections.Generic;
 11 
 12 namespace Quyou.admin.Presenter
 13 {
 14     public class KeywordAjaxPresenter : BasePresenter, IKeywordAjaxPresenter
 15     {
 16         protected override IContainer ConfigureDependencies()
 17         {
 18             return new Container(x =>
 19             {
 20                 x.For<IKeywordTypeService>().Use<KeywordTypeService>();
 21                 x.For<IKeywordService>().Use<KeywordService>();
 22             });
 23         }
 24 
 25         private IKeywordTypeService InitKeywordTypeService()
 26         {
 27             var container = ConfigureDependencies();
 28             return container.GetInstance<IKeywordTypeService>();
 29         }
 30 
 31         private IKeywordService InitKeywordService()
 32         {
 33             var container = ConfigureDependencies();
 34             return container.GetInstance<IKeywordService>();
 35         }
 36 
 37         private string ValidInsertOrUpdate(KeywordTypetData input)
 38         {
 39             input.PlayClass = FilterParamters(input.PlayClass);
 40             input.PlayModel = FilterParamters(input.PlayModel);
 41             input.PlayType = FilterParamters(input.PlayType);
 42             input.Name = FilterParamters(input.Name);
 43             input.Sort = FilterParamters(input.Sort);
 44             input.ParentTypeId = FilterParamters(input.ParentTypeId);
 45             var dict = new Dictionary<string, object>
 46             {
 47                 {"PlayClass", input.PlayClass},
 48                 {"PlayModel", input.PlayModel},
 49                 {"PlayType", input.PlayType},
 50                 {"Name", input.Name},
 51                 {"Sort", input.Sort},
 52                 {"ParentTypeId", input.ParentTypeId}
 53             };
 54             if (!string.IsNullOrEmpty(input.KeywordTypeId))
 55             {
 56                 input.KeywordTypeId = FilterParamters(input.KeywordTypeId);
 57                 dict.Add("KeywordTypeId", input.KeywordTypeId);
 58             }
 59             return ValidateParameters<KeywordTypetData>(dict);
 60         }
 61         public string InsertKeywordType(KeywordTypetData input)
 62         {
 63             var valid = ValidInsertOrUpdate(input);
 64             if (valid.Length > 0)
 65                 return valid;
 66 
 67             var keywordType = new tb_KeywordType
 68             {
 69                 PlayClass = int.Parse(input.PlayClass),
 70                 PlayModel = int.Parse(input.PlayModel),
 71                 PlayType = int.Parse(input.PlayType),
 72                 Name = input.Name,
 73                 AddTime = DateTime.Now,
 74                 Sort = int.Parse(input.Sort),
 75                 ParentTypeId = int.Parse(input.ParentTypeId),
 76                 Active = true
 77             };
 78             
 79             var keywordTypeService = InitKeywordTypeService();
 80             return keywordTypeService.Insert(keywordType);
 81         }
 82 
 83         /// <summary>
 84         /// 修改关键字类别
 85         /// </summary>
 86         /// <param name="input"></param>
 87         /// <returns></returns>
 88         public string EditKeywordType(KeywordTypetData input)
 89         {
 90             var valid = ValidInsertOrUpdate(input);
 91             if (valid.Length > 0)
 92                 return valid;
 93 
 94             var keywordType = new tb_KeywordType
 95             {
 96                 KeywordTypeId = int.Parse(input.KeywordTypeId),
 97                 PlayClass = int.Parse(input.PlayClass),
 98                 PlayModel = int.Parse(input.PlayModel),
 99                 PlayType = int.Parse(input.PlayType),
100                 Name = input.Name,
101                 Sort = int.Parse(input.Sort),
102                 ParentTypeId = int.Parse(input.ParentTypeId)
103             };
104 
105             var keywordTypeService = InitKeywordTypeService();
106             return keywordTypeService.Update(keywordType);
107         }
108 
109         /// <summary>
110         /// 删除关键字类别
111         /// </summary>
112         /// <param name="input"></param>
113         /// <returns></returns>
114         public string DelKeywordType(KeywordTypetData input)
115         {
116             input.KeywordTypeId = FilterParamters(input.KeywordTypeId);
117             var dict = new Dictionary<string, object>
118             {
119                 {"KeywordTypeId", input.KeywordTypeId}
120             };
121             var valid = ValidateParameters<KeywordTypetData>(dict);
122             if (valid.Length > 0)
123                 return valid;
124             var keywordTypeService = InitKeywordTypeService();
125             return keywordTypeService.Delete(int.Parse(input.KeywordTypeId));
126         }
127 
128         /// <summary>
129         /// 添加关键字
130         /// </summary>
131         /// <param name="input"></param>
132         /// <returns></returns>
133         public string InsertKeyword(KeywordtData input)
134         {
135             input.KeywordTypeId = FilterParamters(input.KeywordTypeId);
136             input.Name = FilterParamters(input.Name);
137 
138             var dict = new Dictionary<string, object>
139             {
140                 {"KeywordTypeId", input.KeywordTypeId},
141                 {"Name", input.Name}
142             };
143             var valid = ValidateParameters<KeywordtData>(dict);
144             if (valid.Length > 0)
145                 return valid;
146 
147             var keyword = new tb_Keyword
148             {
149                 KeywordTypeId = int.Parse(input.KeywordTypeId),
150                 Name = input.Name,
151                 AddTime = DateTime.Now,
152                 Pinyin = Pinyin.GetPinyin(input.Name),
153                 Active = true
154             };
155 
156             var keywordService = InitKeywordService();
157             return keywordService.Insert(keyword);
158         }
159 
160         /// <summary>
161         /// 修改关键字
162         /// </summary>
163         /// <param name="input"></param>
164         /// <returns></returns>
165         public string EditKeyword(KeywordtData input)
166         {
167             input.KeywordId = FilterParamters(input.KeywordId);
168             input.KeywordTypeId = FilterParamters(input.KeywordTypeId);
169             input.Name = FilterParamters(input.Name);
170 
171             var dict = new Dictionary<string, object>
172             {
173                 {"KeywordTypeId", input.KeywordTypeId},
174                 {"Name", input.Name},
175                 {"KeywordId", input.KeywordId}
176             };
177             var valid = ValidateParameters<KeywordtData>(dict);
178             if (valid.Length > 0)
179                 return valid;
180 
181             var keyword = new tb_Keyword
182             {
183                 KeywordId = int.Parse(input.KeywordId),
184                 KeywordTypeId = int.Parse(input.KeywordTypeId),
185                 Name = input.Name,
186                 Pinyin = Pinyin.GetPinyin(input.Name),
187             };
188 
189             var keywordService = InitKeywordService();
190             return keywordService.Update(keyword);
191         }
192 
193         /// <summary>
194         /// 删除关键字
195         /// </summary>
196         /// <param name="input"></param>
197         /// <returns></returns>
198         public string DelKeyword(KeywordtData input)
199         {
200             input.KeywordId = FilterParamters(input.KeywordId);
201             var dict = new Dictionary<string, object>
202             {
203                 {"KeywordId", input.KeywordId}
204             };
205             var valid = ValidateParameters<KeywordtData>(dict);
206             if (valid.Length > 0)
207                 return valid;
208             var keywordService = InitKeywordService();
209             return keywordService.Delete(int.Parse(input.KeywordId));
210         }
211 
212         /// <summary>
213         /// 获取关键字列表
214         /// </summary>
215         /// <param name="input"></param>
216         /// <returns></returns>
217         public string GetKeywords(KeywordTypetData input)
218         {
219             int playClass, playModel, playType;
220             int.TryParse(input.PlayClass, out playClass);
221             int.TryParse(input.PlayModel, out playModel);
222             int.TryParse(input.PlayType, out playType);
223             var keywordType = new tb_KeywordType
224             {
225                 PlayClass = playClass,
226                 PlayModel = playModel,
227                 PlayType = playType
228             };
229             var keywordService = InitKeywordService();
230             return keywordService.GetSelectedKeywords(keywordType);
231         }
232 
233         /// <summary>
234         /// 显示错误信息的JSON提示
235         /// </summary>
236         /// <returns></returns>
237         public string ShowErrorJson()
238         {
239             return PromptToJson(Const.PromptFailure);
240         }
241     }
242 }

 

 

 

Linqer下载:

Linqer.rar

结构可以在这里下载,代码都是不能运行的,主要就是展示下结构

演示结构.rar

 posted on 2014-06-22 11:48  咖啡机(K.F.J)  阅读(1116)  评论(3编辑  收藏  举报