public HttpResponseMessage getTasks(DTOFilterGetTasksRequest request) { using (var db = new CRMEntities()) { var filter = request.getFilter(); 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.attachableobjecttype }).ToList(), "application/json")); } if (request.isTaskstateFilter()) { var acik = new 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" )); } }
public HttpResponseMessage insertTaskState(DTOtaskstatepool request) { var user = KOCAuthorizeAttribute.getCurrentUser(); using (var db = new CRMEntities()) { var tsp = new taskstatepool { taskstate = request.taskstate, statetype = request.statetype, creationdate = DateTime.Now, lastupdated = DateTime.Now, updatedby = user.userId, deleted = false }; db.taskstatepool.Add(tsp); db.SaveChanges(); var errormessage = new DTOResponseError { errorCode = 1, errorMessage = "İşlem Başarılı" }; return(Request.CreateResponse(HttpStatusCode.OK, errormessage, "application/json")); } }