public List <TaskDTO> GetTaskList(TaskDTO pTaskDTO) { try { using (TasksEntities ctx = new TasksEntities()) { var objPredicate = Filters(pTaskDTO); return(ctx.TASK .Where(objPredicate) .Select(x => new TaskDTO { DateCreation = x.DATE_CREATION, Description = x.DESCRIPTION, Name = x.NAME, Status = (TaskEnum.Status)x.STATUS, TaskID = x.ID }).ToList()); } } catch (Exception e) { throw e; } }
public JsonResult SaveTask(Task task) { var success = false; using (TasksEntities dc = new TasksEntities()) { if (task.Category == null) { task.Category = " "; } if (task.EventID > 0) { //update all values in a task multipurpose for all save functions specify active or complete on js side var newTask = dc.Tasks.Where(a => a.EventID == task.EventID).FirstOrDefault(); if (newTask != null) { newTask.Name = task.Name; newTask.startDate = task.startDate; newTask.endDate = task.endDate; newTask.Description = task.Description; newTask.Category = task.Category; newTask.assigned = task.assigned; newTask.completed = task.completed; newTask.ThemeColor = task.ThemeColor; } } else { Task newTask1 = new Task(); DateTime?dateOrNull = task.startDate; if (dateOrNull != null) { task.startDate = dateOrNull.Value; } DateTime?dateOrNull2 = task.endDate; if (dateOrNull2 != null) { task.endDate = dateOrNull2.Value; } newTask1.Name = task.Name; newTask1.startDate = dateOrNull.Value; newTask1.endDate = dateOrNull2.Value; newTask1.Description = task.Description; newTask1.Category = task.Category; newTask1.assigned = task.assigned; newTask1.createdDate = DateTime.Now; newTask1.completed = task.completed; newTask1.ThemeColor = task.ThemeColor; dc.Tasks.Add(newTask1); } dc.SaveChanges(); success = true; } return(new JsonResult { Data = new { success = success } }); }
public JsonResult GetTasks() { using (TasksEntities dc = new TasksEntities()) { var tasks = dc.Tasks.ToList(); return(new JsonResult { Data = tasks, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
// get Task by ID public HttpResponseMessage Get(int id) { using (TasksEntities context = new TasksEntities()) { var list = context.Tasks.FirstOrDefault(task => task.Quote == id); if (list == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "There is no tasks with id" + id.ToString() + "to Get")); } else { return(Request.CreateResponse(HttpStatusCode.OK, list)); } } }
// get All Tasks public HttpResponseMessage Get() { using (TasksEntities context = new TasksEntities()) { var list = context.Tasks.ToList(); if (list == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "There is no tasks to see")); } else { return(Request.CreateResponse(HttpStatusCode.OK, list)); } } }
// post task by id public HttpResponseMessage Post([FromBody] Task t) { using (TasksEntities context = new TasksEntities()) { if (t == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "make sure your task is right")); } else { context.Tasks.Add(t); context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created, t)); } } }
// delete task by id public HttpResponseMessage Delete(int id) { using (TasksEntities context = new TasksEntities()) { var list = context.Tasks.FirstOrDefault(task => task.Quote == id); if (list == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "There is no tasks to delete")); } else { context.Tasks.Remove(list); context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, list)); } } }
public JsonResult DeleteTask(int eventID) { var success = false; using (TasksEntities dc = new TasksEntities()) { var oldTask = dc.Tasks.Where(a => a.EventID == eventID).FirstOrDefault(); if (oldTask != null) { dc.Tasks.Remove(oldTask); dc.SaveChanges(); success = true; } return(new JsonResult { Data = new { success = success } }); } }
// update task by id public HttpResponseMessage Put(int id, [FromBody] Task TASK) { using (TasksEntities context = new TasksEntities()) { var task = context.Tasks.FirstOrDefault(tas => tas.Quote == id); if (task == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "There is no task with Id: " + id.ToString() + " to update")); } else { task.QuoteType = TASK.QuoteType; task.Contact = TASK.Contact; task.Task1 = TASK.Task1; task.DateDue = TASK.DateDue; context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, TASK)); } } }
public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup <Startup>() .Build(); using (TasksEntities context = new TasksEntities()) { TaskUser newTaskUser = new TaskUser { UserId = Guid.NewGuid(), UserName = "******" }; context.TaskUsers.Add(newTaskUser); context.SaveChanges(); } host.Run(); }