public HttpResponseMessage getTaskList(DTOFilterGetTasksRequest request) { using (var db = new KOCSAMADLSEntities()) { var filter = request.getFilter(); filter.fieldFilters.Add(new DTOFieldFilter { fieldName = "deleted", value = 0, op = 2 }); var querySql = filter.subTables["taskid"].getPagingSQL(request.pageNo, request.rowsPerPage); var res = db.task.SqlQuery(querySql).ToList(); var ptypeids = res.Select(r => r.attachablepersoneltype).Distinct().ToList(); var personels = db.objecttypes.Where(p => ptypeids.Contains(p.typeid)).ToList(); var obtpyeids = res.Select(r => r.attachableobjecttype).Distinct().ToList(); var objects = db.objecttypes.Where(o => obtpyeids.Contains(o.typeid)).ToList(); var ttypeids = res.Select(s => s.tasktype).Distinct().ToList(); var tasktypess = db.tasktypes.Where(t => ttypeids.Contains(t.TaskTypeId)).ToList(); res.ForEach(r => { r.objecttypes = objects.Where(t => t.typeid == r.attachableobjecttype).FirstOrDefault(); r.personeltypes = personels.Where(p => p.typeid == r.attachablepersoneltype).FirstOrDefault(); r.tasktypes = tasktypess.Where(t => t.TaskTypeId == r.tasktype).FirstOrDefault(); }); return(Request.CreateResponse(HttpStatusCode.OK, res.Select(s => s.toDTO()).ToList(), "application/json")); } }
public HttpResponseMessage getTasks(DTOFilterGetTasksRequest request) { using (var db = new KOCSAMADLSEntities(false)) { var filter = request.getFilter(); filter.fieldFilters.Add(new DTOFieldFilter { fieldName = "deleted", value = 0, op = 2 }); if (request.isTaskFilter()) { return(Request.CreateResponse(HttpStatusCode.OK, db.task.SqlQuery(filter.subTables["taskid"].getFilterSQL()) .OrderBy(t => t.taskname) .Select(t => new { t.taskid, t.taskname, t.tasktype }).ToList(), "application/json")); } if (request.isTaskstateFilter()) { var acik = new adsl_taskstatepool { taskstate = "AÇIK", taskstateid = 0 }; var query = filter.getFilterSQL(); var tspIds = db.taskstatematches.SqlQuery(query) .Select(t => t.stateid).ToList(); var res = db.taskstatepool.Where(tsp => tspIds.Contains(tsp.taskstateid)).OrderBy(tsp => tsp.taskstate).ToList(); res.Insert(0, acik); return(Request.CreateResponse(HttpStatusCode.OK, res.Select(r => r.toDTO()).ToList(), "application/json")); } if (request.isObjecttypeFilter()) { var objids = db.task.SqlQuery(filter.subTables["taskid"].getFilterSQL()).Select(s => s.attachableobjecttype).Distinct().ToList(); var res = db.objecttypes.Where(o => objids.Contains(o.typeid)) .OrderBy(t => t.typname) .ToList(); return(Request.CreateResponse(HttpStatusCode.OK, res.Select(s => new { s.typeid, s.typname }).ToList(), "application/json")); } if (request.isPersonelTypeFilter()) { var pids = db.task.SqlQuery(filter.subTables["taskid"].getFilterSQL()).Select(s => s.attachablepersoneltype).Distinct().ToList(); var res = db.objecttypes.Where(p => pids.Contains(p.typeid)).OrderBy(p => p.typname).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, res.Select(t => new { t.typeid, t.typname }).ToList(), "application/json")); } return(Request.CreateResponse(HttpStatusCode.OK, db.tasktypes.SqlQuery(filter.subTables["tasktype"].getFilterSQL()) .Select(tt => new { tt.TaskTypeId, tt.TaskTypeName }) .OrderBy(tt => tt.TaskTypeName).ToList(), "application/json" )); } }
DTOFilter ITaskRequest.getFilter() { return(taskRequest.getFilter()); }