/// <summary> /// 删除 /// </summary> /// <param name="ids">多个id用,分隔</param> /// <returns></returns> public static bool Delete(string ids) { var arry = ids.Split(',').Select(p => Convert.ToInt32(p)); using (Entities db = new Entities()) { #region 支付过的删除时备份一下 foreach (ht_news item in db.ht_news.Where(p => p.pay_status == 1 && arry.Contains(p.id))) { ht_news_del bk = new ht_news_del() { news_id = item.id, cateid = item.cateid, cate = item.cate, title = item.title, description = item.description, contact_name = item.contact_name, contact_phone = item.contact_phone, validity_num = item.validity_num, validity_unit = item.validity_unit, start_province = item.start_province, start_city = item.start_city, start_district = item.start_district, start_address = item.start_address, stop_province = item.stop_province, stop_city = item.stop_city, stop_district = item.stop_district, stop_address = item.stop_address, tags = item.tags, use_type = item.use_type, use_img = item.use_img, car_length = item.car_length, car_style = item.car_style, goods_type = item.goods_type, goods_weight = item.goods_weight, goods_weight_unit = item.goods_weight_unit, freight = item.freight, use_time = item.use_time, use_mode = item.use_mode, pay_method = item.pay_method, other_remark = item.other_remark, set_top = item.set_top, set_top_money = item.set_top_money, reward_money = item.reward_money, recruit_num = item.recruit_num, imgs = item.imgs, add_userid = item.add_userid, add_nickname = item.add_nickname, add_avatar = item.add_avatar, add_time = item.add_time, update_userid = item.update_userid, update_nickname = item.update_nickname, update_time = item.update_time, audit_userid = item.audit_userid, audit_nickname = item.audit_nickname, audit_time = item.audit_time, status = item.status, pay = item.pay, pay_status = item.pay_status, pay_time = item.pay_time, pay_trade_no = item.pay_trade_no, order_no = item.order_no, view_num = item.view_num, praise_num = item.praise_num, share_num = item.share_num, is_delete = item.is_delete, total = item.total }; db.ht_news_del.Add(bk); } #endregion 支付过的删除时备份一下 db.SaveChanges();//保存备份 int result = db.ht_news.Where(p => arry.Contains(p.id)).Delete(); return(result > 0); } }
/// <summary> /// 删除新闻 /// </summary> /// <param name="id"></param> /// <returns></returns> public static int DelNews(int id) { using (Entities db = new Entities()) { var details = db.ht_news.Find(id); #region 支付过的删除时备份一下 if (details.pay_status == 1) { ht_news_del bk = new ht_news_del() { news_id = details.id, cateid = details.cateid, cate = details.cate, title = details.title, description = details.description, contact_name = details.contact_name, contact_phone = details.contact_phone, validity_num = details.validity_num, validity_unit = details.validity_unit, start_province = details.start_province, start_city = details.start_city, start_district = details.start_district, start_address = details.start_address, stop_province = details.stop_province, stop_city = details.stop_city, stop_district = details.stop_district, stop_address = details.stop_address, tags = details.tags, use_type = details.use_type, use_img = details.use_img, car_length = details.car_length, car_style = details.car_style, goods_type = details.goods_type, goods_weight = details.goods_weight, goods_weight_unit = details.goods_weight_unit, freight = details.freight, use_time = details.use_time, use_mode = details.use_mode, pay_method = details.pay_method, other_remark = details.other_remark, set_top = details.set_top, set_top_money = details.set_top_money, reward_money = details.reward_money, recruit_num = details.recruit_num, imgs = details.imgs, add_userid = details.add_userid, add_nickname = details.add_nickname, add_avatar = details.add_avatar, add_time = details.add_time, update_userid = details.update_userid, update_nickname = details.update_nickname, update_time = details.update_time, audit_userid = details.audit_userid, audit_nickname = details.audit_nickname, audit_time = details.audit_time, status = details.status, pay = details.pay, pay_status = details.pay_status, pay_time = details.pay_time, pay_trade_no = details.pay_trade_no, order_no = details.order_no, view_num = details.view_num, praise_num = details.praise_num, share_num = details.share_num, is_delete = details.is_delete, total = details.total }; db.ht_news_del.Add(bk); } #endregion 支付过的删除时备份一下 db.ht_news.Remove(details); return(db.SaveChanges()); } }