public JsonResult CreateTask(Task TaskData) { var dat = new List<object>(); string msg = ""; bool TaskCreateStatus = false; int UID = Convert.ToInt32(this.Session["UserProfile"].ToString()); //user.getSession(); Task newTask = new Task(); try { using (db) { if (ModelState.IsValid) { newTask.TASK_NAME = TaskData.TASK_NAME; newTask.TASK_USER_ID = UID; // TaskData.TASK_USER_ID; newTask.TASK_PROJECT_ID = TaskData.TASK_PROJECT_ID; newTask.TASK_START_DATE = TaskData.TASK_START_DATE; newTask.TASK_END_DATE = TaskData.TASK_END_DATE; newTask.TASK_STATUS = "NOT STARTED"; newTask.TASK_PRIORITY = TaskData.TASK_PRIORITY; newTask.TASK_ESTIMATED_HOUR = TaskData.TASK_ESTIMATED_HOUR; newTask.TASK_HOUR_CONSUMED = 0; newTask.PROJECT_PHASE = TaskData.PROJECT_PHASE; newTask.TASK_DESCRIPTION = TaskData.TASK_DESCRIPTION; newTask.U_TASK_CREATE_DATE = DateTime.Now; db.Tasks.Add(newTask); db.SaveChanges(); TaskCreateStatus = true; msg = "Success"; } else { msg = "Failed!"; } } } catch (Exception ex) { msg = ex.Message; } dat.Add(new { Message = msg, Status = TaskCreateStatus, Formdata = TaskData }); return new JsonResult { Data = dat }; //, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; // //return new JsonResult { Data = message }; }
public ActionResult TaskEditAction(Task UpdateTask) { bool TaskStatus = false; string msg = " "; var dat = new List<object>(); try { using (db) { if (ModelState.IsValid) { var Task = db.Tasks.Where(a => a.TASK_ID.Equals(UpdateTask.TASK_ID)).FirstOrDefault(); if (Task != null) { Task.TASK_PROJECT_ID = UpdateTask.TASK_PROJECT_ID; Task.TASK_NAME = UpdateTask.TASK_NAME; Task.TASK_START_DATE = UpdateTask.TASK_END_DATE; Task.TASK_PRIORITY = UpdateTask.TASK_PRIORITY; Task.PROJECT_PHASE = UpdateTask.PROJECT_PHASE; Task.TASK_ESTIMATED_HOUR = UpdateTask.TASK_ESTIMATED_HOUR; Task.TASK_DESCRIPTION = UpdateTask.TASK_DESCRIPTION; db.SaveChanges(); TaskStatus = true; msg = "Successfully updated task"; } else { msg = "Task not found"; } } else { msg = "Invalid modal state to update status"; } } dat.Add(new { Message = msg, Status = TaskStatus }); return new JsonResult { Data = dat }; } catch (Exception ex) { dat.Add(new { Message = ex, Status = TaskStatus }); return new JsonResult { Data = dat }; } }