更新查詢方式
This commit is contained in:
@@ -63,17 +63,17 @@ public class activityController : ApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.activities.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activities.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
//刪除相關資料
|
||||
var prod2 = _db.activity_relating.AsEnumerable().Where(q => q.activity_num == id).ToList(); //相關項目
|
||||
var prod2 = _db.activity_relating.Where(q => q.activity_num == id).ToList(); //相關項目
|
||||
if (prod2.Count > 0)
|
||||
{
|
||||
//查詢結果全部刪除
|
||||
_db.activity_relating.RemoveRange(prod2);
|
||||
}
|
||||
var prod3 = _db.activity_spares.AsEnumerable().Where(q => q.activity_num == id).ToList(); //備品項目
|
||||
var prod3 = _db.activity_spares.Where(q => q.activity_num == id).ToList(); //備品項目
|
||||
if (prod3.Count > 0)
|
||||
{
|
||||
_db.activity_spares.RemoveRange(prod3);
|
||||
@@ -98,7 +98,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteItem/{id}")]
|
||||
public void DeleteItem(int id)
|
||||
{
|
||||
var prod = _db.actItems.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.actItems.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
/*if (prod != null)
|
||||
{
|
||||
//var prod2 = _db.actItem_files.AsEnumerable().Where(q => q.actItem_num == id).ToList(); //相關項目
|
||||
@@ -144,11 +144,11 @@ public class activityController : ApiController
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
|
||||
var prod = _db.activities.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var prod = _db.activities.Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
//var prod2 = _db.activity_relating.AsEnumerable().Where(q => ids.Contains(Convert.ToInt32(q.activity_num))).ToList();
|
||||
var prod2 = _db.activity_relating.AsEnumerable().Where(q => ids.Any(x => x == q.activity_num)).ToList();
|
||||
var prod2 = _db.activity_relating.Where(q => ids.Contains(q.activity_num)).ToList();
|
||||
if (prod2.Count > 0)
|
||||
{
|
||||
_db.activity_relating.RemoveRange(prod2);
|
||||
@@ -156,7 +156,7 @@ public class activityController : ApiController
|
||||
}
|
||||
|
||||
//var prod3 = _db.activity_spares.AsEnumerable().Where(q => ids.Contains(Convert.ToInt32(q.activity_num))).ToList();
|
||||
var prod3 = _db.activity_spares.AsEnumerable().Where(q => ids.Any(x => x == q.activity_num)).ToList();
|
||||
var prod3 = _db.activity_spares.Where(q => ids.Contains(q.activity_num)).ToList();
|
||||
if (prod3.Count > 0)
|
||||
{
|
||||
_db.activity_spares.RemoveRange(prod3);
|
||||
@@ -186,11 +186,11 @@ public class activityController : ApiController
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var prod = _db.actItems.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var prod = _db.actItems.Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
//var prod2 = _db.actItem_files.AsEnumerable().Where(q => ids.Contains(Convert.ToInt32(q.actItem_num))).ToList();
|
||||
var prod2 = _db.actItem_files.AsEnumerable().Where(q => ids.Any(x => x == q.actItem_num)).ToList();
|
||||
var prod2 = _db.actItem_files.Where(q => ids.Contains(q.actItem_num)).ToList();
|
||||
if (prod2.Count > 0)
|
||||
{
|
||||
_db.actItem_files.RemoveRange(prod2);
|
||||
@@ -224,7 +224,7 @@ public class activityController : ApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.activity q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.activities.AsEnumerable();
|
||||
var qry = _db.activities.AsQueryable();
|
||||
if (!string.IsNullOrEmpty(q.subject))
|
||||
qry = qry.Where(o => o.subject.Contains(q.subject));
|
||||
if (q.kind.HasValue && q.kind > 0)
|
||||
@@ -319,7 +319,7 @@ public class activityController : ApiController
|
||||
{
|
||||
|
||||
//var stockDt = _db.stocks.AsEnumerable(); ;//庫存
|
||||
var fileDt = _db.files.AsEnumerable().Where(f => f.subject.Contains(q.fileTxt)).Select(f => f.num.ToString());//文件
|
||||
var fileDt = _db.files.Where(f => f.subject.Contains(q.fileTxt)).Select(f => f.num.ToString());//文件
|
||||
|
||||
//每個品項在每個倉庫的結餘量
|
||||
var stockDt = (
|
||||
@@ -348,7 +348,7 @@ public class activityController : ApiController
|
||||
|
||||
|
||||
////var qry = _db.actItems.Where(a => a.IsDel == false).AsEnumerable();////不確定是否新增欄位? 先註解
|
||||
var qry = _db.actItems.AsEnumerable();
|
||||
var qry = _db.actItems.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.subject))
|
||||
qry = qry.Where(o => o.subject.Contains(q.subject.Trim()));
|
||||
@@ -711,7 +711,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteFilesItem/{id}")]//刪除品項的相關文件
|
||||
public void DeleteFilesItem(int id)
|
||||
{
|
||||
var prod = _db.actItem_files.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.actItem_files.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -731,7 +731,7 @@ public class activityController : ApiController
|
||||
if (this_id > 0)
|
||||
{
|
||||
//檢查
|
||||
var qry = _db.activity_kind_detail.AsEnumerable();
|
||||
var qry = _db.activity_kind_detail.AsQueryable();
|
||||
qry = qry.Where(o => o.activity_kind_num == this_id);
|
||||
int i = 1;
|
||||
|
||||
@@ -830,7 +830,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteActKindDetail/{id}")]//刪除活動分類的detail
|
||||
public void DeleteActKindDetail(int id)
|
||||
{
|
||||
var prod = _db.activity_kind_detail.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activity_kind_detail.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -849,7 +849,7 @@ public class activityController : ApiController
|
||||
if (this_act_id > 0)
|
||||
{
|
||||
//檢查
|
||||
var prod = _db.activities.AsEnumerable().Where(o => o.num == this_act_id).FirstOrDefault();
|
||||
var prod = _db.activities.Where(o => o.num == this_act_id).FirstOrDefault();
|
||||
if (prod != null)
|
||||
{
|
||||
int kind = prod.kind ?? 0; //分類
|
||||
@@ -927,7 +927,7 @@ public class activityController : ApiController
|
||||
if (kind > 0)
|
||||
{
|
||||
int i = 1;
|
||||
var qry2 = _db.activity_kind_detail.AsEnumerable();
|
||||
var qry2 = _db.activity_kind_detail.AsQueryable();
|
||||
qry2 = qry2.Where(o => o.activity_kind_num == kind);
|
||||
var count2 = qry2.Count(); //pageSize = count2;//一次取回??
|
||||
if (pageSize > 0) qry2 = qry2.ToPagedList(page, pageSize);
|
||||
@@ -992,7 +992,7 @@ public class activityController : ApiController
|
||||
public IHttpActionResult GetKindList([FromBody] Model.ViewModel.activity_kind q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.activity_kind.AsEnumerable();
|
||||
var qry = _db.activity_kind.AsQueryable();
|
||||
if (q.num.HasValue && q.num > 0)
|
||||
qry = qry.Where(o => o.num == q.num);
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
@@ -1031,7 +1031,7 @@ public class activityController : ApiController
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
var qry = _db.activity_kind.AsEnumerable();
|
||||
var qry = _db.activity_kind.AsQueryable();
|
||||
qry = qry.Where(o => o.num == id);
|
||||
var prop3 = qry.FirstOrDefault();
|
||||
if (prop3 != null)
|
||||
@@ -1151,7 +1151,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteRelatingData/{id}")]//刪除活動的相關資料
|
||||
public void DeleteRelatingData(int id)
|
||||
{
|
||||
var prod = _db.activity_relating.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activity_relating.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -1169,14 +1169,14 @@ public class activityController : ApiController
|
||||
if (this_act_id > 0)
|
||||
{
|
||||
//檢查
|
||||
var prod = _db.activities.AsEnumerable().Where(o => o.num == this_act_id).FirstOrDefault();
|
||||
var prod = _db.activities.Where(o => o.num == this_act_id).FirstOrDefault();
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
|
||||
int kind = prod.kind ?? 0; //分類
|
||||
|
||||
var qry1 = _db.activity_spares.AsEnumerable();
|
||||
var qry1 = _db.activity_spares.AsQueryable();
|
||||
qry1 = qry1.Where(o => o.activity_num == this_act_id);
|
||||
|
||||
qry1 = qry1.OrderBy(o => o.num);
|
||||
@@ -1278,7 +1278,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteSparesData/{id}")]//刪除活動的備品資料
|
||||
public void DeleteSparesData(int id)
|
||||
{
|
||||
var prod = _db.activity_spares.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activity_spares.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -1331,7 +1331,7 @@ public class activityController : ApiController
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
|
||||
var qry = _db.activity_check.AsEnumerable();
|
||||
var qry = _db.activity_check.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.activityTxt))
|
||||
qry = qry.Where(o => o.activity.subject.Contains(q.activityTxt.Trim()));
|
||||
@@ -1416,7 +1416,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteCheck/{id}")]
|
||||
public void DeleteCheck(int id)
|
||||
{
|
||||
var prod = _db.activity_check.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activity_check.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -1439,7 +1439,7 @@ public class activityController : ApiController
|
||||
if (!string.IsNullOrEmpty(num[i]))
|
||||
ids[i] = Convert.ToInt32(num[i]);
|
||||
}
|
||||
var prod = _db.activity_check.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var prod = _db.activity_check.Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
|
||||
@@ -1458,7 +1458,7 @@ public class activityController : ApiController
|
||||
{
|
||||
DateTime _now = DateTime.Now;
|
||||
|
||||
var qry = _db.activities.AsEnumerable();
|
||||
var qry = _db.activities.AsQueryable();
|
||||
|
||||
if (q.reg_time1.HasValue)
|
||||
qry = qry.Where(o => o.reg_time >= q.reg_time1.Value);
|
||||
@@ -1510,7 +1510,7 @@ public class activityController : ApiController
|
||||
public IHttpActionResult GetCategoryKindList([FromBody] Model.ViewModel.activity_category_kind q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.activity_category_kind.AsEnumerable();
|
||||
var qry = _db.activity_category_kind.AsQueryable();
|
||||
if (q.num.HasValue && q.num > 0)
|
||||
qry = qry.Where(o => o.num == q.num);
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
|
||||
@@ -99,7 +99,7 @@ public class orderController : ApiController
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
var prod = _db.pro_order_detail.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.pro_order_detail.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
//刪除掛單表單
|
||||
@@ -134,7 +134,7 @@ public class orderController : ApiController
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',');
|
||||
|
||||
var prod = _db.pro_order.AsEnumerable().Where(q => ids.Contains(q.order_no)).ToList();
|
||||
var prod = _db.pro_order.Where(q => ids.Contains(q.order_no)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
var prod2 = _db.pro_order_detail.AsEnumerable().Where(q => ids.Contains(Convert.ToString(q.order_no))).ToList();
|
||||
@@ -201,7 +201,7 @@ public class orderController : ApiController
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
|
||||
var qry = _db.pro_order.AsEnumerable();
|
||||
var qry = _db.pro_order.AsQueryable();
|
||||
//var aIDt = _db.actItems.AsEnumerable().Where(f => f.subject.Contains(q.actItemTxt.Trim())).Select(f => f.num);//品項
|
||||
|
||||
|
||||
@@ -801,15 +801,15 @@ public class orderController : ApiController
|
||||
{
|
||||
|
||||
//家族 : 家長是我的人,跟我同家長的人,我的家長本人,我本人
|
||||
var cc = _db.followers.Where(x => x.num == _follower || x.leader == _follower).Select(x => x.num);
|
||||
var qry = _db.followers.AsEnumerable().Where(f => cc.Any(x => x == f.num) || cc.Any(x => x == f.leader));
|
||||
var ccList = _db.followers.Where(x => x.num == _follower || x.leader == _follower).Select(x => x.num).ToList();
|
||||
var qry = _db.followers.Where(f => ccList.Contains(f.num) || ccList.Contains(f.leader));
|
||||
|
||||
//未付款資料
|
||||
var unpayDt = _db.pro_order_detail.AsEnumerable();
|
||||
var unpayDt = _db.pro_order_detail.AsQueryable();
|
||||
var coDt = unpayDt.Where(x => x.keyin1 == (int)Model.pro_order.detailKeyin1.Collection);//只列出報名狀態為"收款中"的項目
|
||||
|
||||
//未付款訂單
|
||||
var orderDt = _db.pro_order.AsEnumerable();
|
||||
var orderDt = _db.pro_order.AsQueryable();
|
||||
if (!string.IsNullOrEmpty(order_no))
|
||||
orderDt = orderDt.Where(x => x.order_no == order_no);
|
||||
orderDt = orderDt.Where(x => coDt.Select(d => d.order_no).Contains(x.order_no));
|
||||
@@ -855,7 +855,7 @@ public class orderController : ApiController
|
||||
{
|
||||
|
||||
//未付款資料
|
||||
var unpayDt = _db.pro_order_detail.AsEnumerable();
|
||||
var unpayDt = _db.pro_order_detail.AsQueryable();
|
||||
unpayDt = unpayDt.Where(x => x.keyin1 == (int)Model.pro_order.detailKeyin1.Collection);//只列出報名狀態為"收款中"的項目
|
||||
|
||||
if (!string.IsNullOrEmpty(q.order_no))
|
||||
@@ -1118,7 +1118,7 @@ public class orderController : ApiController
|
||||
[Route("api/order/DeleteRecordDetail/{id}")]//刪除收款註記
|
||||
public void DeleteRecordDetail(int id)
|
||||
{
|
||||
var prod = _db.pro_order_record.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.pro_order_record.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class projectController : BaseApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.projects.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.projects.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.project_sub.RemoveRange(prod.project_sub); //刪除活動資料
|
||||
@@ -75,7 +75,7 @@ public class projectController : BaseApiController
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var prod = _db.projects.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var prod = _db.projects.Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
foreach (var item in prod)
|
||||
@@ -103,7 +103,7 @@ public class projectController : BaseApiController
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
var prod = _db.project_sub.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.project_sub.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.project_sub.Remove(prod);
|
||||
@@ -117,7 +117,7 @@ public class projectController : BaseApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.project q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.projects.AsEnumerable();
|
||||
var qry = _db.projects.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.subject))
|
||||
qry = qry.Where(o => o.subject.Contains(q.subject.Trim()));
|
||||
@@ -192,7 +192,7 @@ public class projectController : BaseApiController
|
||||
public IHttpActionResult GetKindList([FromBody] Model.ViewModel.project_kind q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.project_kind.AsEnumerable();
|
||||
var qry = _db.project_kind.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
@@ -247,7 +247,7 @@ public class projectController : BaseApiController
|
||||
|
||||
if (q.num.HasValue)
|
||||
{
|
||||
var qry = _db.project_sub.AsEnumerable();
|
||||
var qry = _db.project_sub.AsQueryable();
|
||||
|
||||
qry = qry.Where(o => o.pro_id == q.num.Value);
|
||||
|
||||
@@ -337,11 +337,11 @@ public class projectController : BaseApiController
|
||||
public IHttpActionResult GetPatronizeList([FromBody] Model.ViewModel.pro_order_detail q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var projectDt = _db.projects.AsEnumerable(); ;//專案
|
||||
var projectDt = _db.projects.AsQueryable(); ;//專案
|
||||
|
||||
try
|
||||
{
|
||||
var qry = _db.pro_order_detail.AsEnumerable();
|
||||
var qry = _db.pro_order_detail.AsQueryable();
|
||||
qry = qry.Where(o => (int?)o.actItem.category == (int)Model.activity.category.Patronize);
|
||||
|
||||
if (q.f_num.HasValue)
|
||||
|
||||
Reference in New Issue
Block a user