using MC.ORM;
using NIU.Core;
using NIU.Forum.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace CP.Model
{
///
/// 彩种推荐链接表
///
[TableName("notice"), PrimaryKey("id")]
public class Notice
{
///
/// 自动编号
///
public int id { get; set; }
///
/// 标题
///
[Display(Name = "标题")]
public string title { get; set; }
///
/// 内容
///
[Display(Name = "内容")]
public string content { get; set; }
///
/// 用户
///
[Display(Name = "用户")]
public int userid { get; set; }
///
/// 用户
///
[Ignore]
[Display(Name = "用户名")]
public string username { get; set; }
///
/// 添加时间
///
[Display(Name = "添加时间")]
public DateTime addtime { get; set; }
///
/// 删除字段
///
[Display(Name = "删除字段")]
public bool isdelete { get; set; } = false;
}
public class NoticeData : DataConnect
{
///
/// 获取所有
///
///
public static List GetList()
{
DataConnect dc = new DataConnect();
var list = dc.db.Fetch($" ORDER BY id desc");
//foreach (var noticeitem in list)
//{
// noticeitem.username = GetUser(noticeitem.userid).name;
//}
return list;
}
///
/// 添加 更新
///
///
public static void AddOrUpdate(Notice model)
{
if (model == null)
throw new OperationExceptionFacade("未接收到参数");
DataConnect dc = new DataConnect();
if (model.id == 0)
{
model.addtime = DateTime.Now;
dc.db.Insert(model);
}
else
{
var entity = dc.db.SingleOrDefault(model.id);
if (entity == null)
throw new OperationExceptionFacade("数据不存在,请刷新");
entity.title = model.title;
entity.content = model.content;
entity.userid = model.userid;
entity.addtime = DateTime.Now;
dc.db.Update(entity);
}
}
///
/// 根据Id获取
///
///
public static Notice GetById(long id)
{
DataConnect dc = new DataConnect();
return dc.db.SingleOrDefault(id);
}
///
/// 删除
///
///
///
public static void Delete(long id)
{
var entity = GetById(id);
if (entity == null)
{
throw new OperationExceptionFacade("数据不存在,请刷新");
}
DataConnect dc = new DataConnect();
dc.db.Delete(id);
}
}
}