📄 abstractservice.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using ExaminationSystem.BLL.DataInterface;
using ExaminationSystem.BLL.Domain;
namespace ExaminationSystem.BLL.Service
{
public class AbstractService<DomainType,DaoType>
{
protected static IDao<DomainType, long> Dao = (IDao<DomainType, long>)DaoManager.GetDao(typeof(DaoType));
public DomainType GetById(long id)
{
return Dao.GetById(id, false);
}
public virtual void DeleteById(long id)
{
DomainType obj = Dao.GetById(id, true);
Dao.Delete(obj);
Dao.CommitChanges();
}
public virtual void Update(DomainType obj)
{
Dao.SaveOrUpdate(obj);
}
public IList<DomainType> GetAll()
{
return Dao.GetAll();
}
public IList<DomainType> GetByExample(DomainType obj, params string[] propertiesToExclude)
{
return Dao.GetByExample(obj, propertiesToExclude);
}
public DomainType GetUniqueByExample(DomainType obj, params string[] propertiesToExclude)
{
return Dao.GetUniqueByExample(obj, propertiesToExclude);
}
public virtual void Save(DomainType obj)
{
Dao.Save(obj);
}
public void CommitChanges()
{
Dao.CommitChanges();
}
}
//**************************************************************
public class ChapterService : AbstractService<Chapter, IChapterDao>{}
public class DanXuanContentService : AbstractService<DanXuanContent, IDanXuanContentDao>{}
public class DuoXuanContentService : AbstractService<DuoXuanContent, IDuoXuanContentDao> {}
public class PanDuanContentService : AbstractService<PanDuanContent, IPanDuoContentDao> { }
public class TianKongContentService : AbstractService<TianKongContent, ITianKongContentDao> { }
public class JianDaContentService : AbstractService<JianDaContent, IJianDaContentDao> { }
public class PaperStrategyService : AbstractService<PaperStrategy, IPaperStrategyDao> { }
public class StrategyContainerService : AbstractService<StrategyContainer, IStrategyContainerDao> { }
public class StrategyItemService : AbstractService<StrategyItem, IStrategyItemDao> { }
public class PaperService : AbstractService<Paper, IPaperDao> { }
public class TeacherService : AbstractService<Teacher, ITeacherDao>
{
public override void Save(Teacher obj)
{
Teacher exmple = new Teacher();
exmple.LoginName = obj.LoginName;
if (Dao.GetUniqueByExample(exmple) != null)
throw new Exception("教师登陆用户名重复!");
base.Save(obj);
}
}
public class AdminService : AbstractService<Admin, IAdminDao>
{
public override void Save(Admin obj)
{
Admin exmple = new Admin();
exmple.LoginName = obj.LoginName;
if (Dao.GetUniqueByExample(exmple) != null)
throw new Exception("管理员登陆用户名重复!");
base.Save(obj);
}
}
public class StudentService : AbstractService<Student, IStudentDao>
{
public override void Save(Student obj)
{
Student exmple = new Student();
exmple.StudentID = obj.StudentID;
if (Dao.GetUniqueByExample(exmple) != null)
throw new Exception("学生学号不能重复!");
base.Save(obj);
}
}
//*************************************************************
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -