首页 > Windows开发 > 详细

真-API.DALBLL.AJAS

时间:2020-06-26 20:45:46      阅读:70      评论:0      收藏:0      [点我收藏+]

 

--------BLL

GoodDal dal = new GoodDal();
/// <summary>
/// 添加
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int Add(Good model)
{
return dal.Add(model);
}
/// <summary>
/// 绑定分类
/// </summary>
/// <returns></returns>
public List<GoodType> BandType()
{
return dal.BandType();
}
/// <summary>
/// 绑定供应商
/// </summary>
/// <returns></returns>
public List<Supplier> BandSupplier()
{
return dal.BandSupplier();
}
/// <summary>
/// 显示,查询
/// </summary>
/// <returns></returns>
public List<Good> Show(string GoodName, int TypeId, int SupplierId)
{
return dal.Show(GoodName, TypeId, SupplierId);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public int Delete(string id)
{
if (string.IsNullOrEmpty(id))
{
return 0;
}
else
{
return dal.Delete(id);
}
}

#region 修改
/// <summary>
/// 反填
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Good FanTian(int id)
{
return dal.FanTian(id);
}

/// <summary>
/// 修改
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int Update(Good model)
{
return dal.Update(model);
}

 

------------DAL

GoodContext db = new GoodContext();
#region 添加
/// <summary>
/// 添加
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int Add(Good model)
{
try
{
db.Good.Add(model);
return db.SaveChanges();
}
catch (Exception)
{
throw;
}
}
#endregion

#region 绑定下拉
/// <summary>
/// 绑定分类
/// </summary>
/// <returns></returns>
public List<GoodType> BandType()
{
return db.GoodType.ToList();
}
/// <summary>
/// 绑定供应商
/// </summary>
/// <returns></returns>
public List<Supplier> BandSupplier()
{
return db.Supplier.ToList();
}
#endregion

#region 显示
/// <summary>
/// 显示,查询
/// </summary>
/// <returns></returns>
public List<Good> Show(string GoodName, int TypeId, int SupplierId)
{
List<Good> list = db.Good.Include("GoodType").Include("Supplier").ToList();
if (!string.IsNullOrEmpty(GoodName))//根据商品名称查询
{
list = list.Where(s => s.GName.Contains(GoodName)).ToList();
}
if (TypeId != 0)//根据类别查询
{
list = list.Where(s => s.TypeId == TypeId).ToList();
}
if (SupplierId != 0)//根据供应商查询
{
list = list.Where(s => s.SupplierId == SupplierId).ToList();
}
return list;
}
#endregion

#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public int Delete(string id)
{
string[] str = id.Split(‘,‘);
for (int i = 0; i < str.Length; i++)
{
int gid = int.Parse(str[i]);
//找到要删除的数据
Good model = db.Good.Where(s => s.Id == gid).ToList().First();
//删除
db.Good.Remove(model);
}
return db.SaveChanges();
}
#endregion

#region 修改
/// <summary>
/// 反填
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Good FanTian(int id)
{
//找到要修改的数据
Good model = db.Good.Where(s => s.Id == id).ToList().First();
return model;
}
/// <summary>
/// 修改
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int Update(Good model)
{
try
{
db.Good.Attach(model);
db.Entry(model).State = EntityState.Modified;
return db.SaveChanges();
}
catch (Exception)
{
throw;
}
}

 

----------DAL里对应异常

public GoodContext() : base("Good") {

}
public DbSet<Good> Good { get; set; }
public DbSet<GoodType> GoodType { get; set; }
public DbSet<Supplier> Supplier { get; set; }

真-API.DALBLL.AJAS

原文:https://www.cnblogs.com/gc1229/p/13196135.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!