public List <task> GetNotifiTaskList(long userID) { List <task> taskList = new List <task>(); taskuser taskuser = entities.taskusers.Where(m => m.user_id == userID).FirstOrDefault(); if (taskuser == null) { taskuser = new taskuser(); taskuser.user_id = userID; taskuser.task_list = null; entities.taskusers.Add(taskuser); entities.SaveChanges(); } else { string taskListStr = taskuser.task_list; if (taskListStr != null) { string[] taskIDList = taskListStr.Split(','); for (int i = 0; i < taskIDList.Length; i++) { long taskID = Convert.ToInt64(taskIDList[i]); task taskItem = entities.tasks.Find(taskID); taskList.Add(taskItem); } } } return(taskList); }
public ActionResult newtask(string task_name, string description, string responsable, string task_date, string task_time, string comments, int share, int status, string estimated_date, string estimated_time ) { try { long userId = (long)Session["USER_ID"]; task newTask = new task(); newTask.task_name = task_name; newTask.description = description; newTask.responsable = responsable; newTask.comments = comments; newTask.task_date = DateTime.ParseExact(task_date + " " + task_time, "yyyy-MM-dd HH:mm", System.Globalization.CultureInfo.CurrentCulture); newTask.estimated_date = DateTime.ParseExact(estimated_date + " " + estimated_time, "yyyy-MM-dd HH:mm", System.Globalization.CultureInfo.CurrentCulture); newTask.share = share; newTask.status = status; newTask.created_at = DateTime.Now; newTask.updated_at = DateTime.Now; newTask.community_id = Convert.ToInt64(Session["CURRENT_COMU"]); entities.tasks.Add(newTask); entities.SaveChanges(); taskuser taskuser = entities.taskusers.Where(m => m.user_id == userId).FirstOrDefault(); if (taskuser == null) { taskuser = new taskuser(); taskuser.user_id = userId; taskuser.task_list = newTask.id.ToString(); entities.taskusers.Add(taskuser); } else { string taskList = taskuser.task_list; if (taskList == null) { taskuser.task_list = newTask.id.ToString(); } else { taskuser.task_list = taskList + "," + newTask.id.ToString(); } } entities.SaveChanges(); return(Redirect(Url.Action("listado", "tareas", new { area = "webmaster" }))); } catch (Exception ex) { return(Redirect(Url.Action("agregar", "tareas", new { area = "webmaster", exception = ex.Message }))); } }
public ActionResult vertarea(long id) { if (Session["USER_ID"] != null) { try { long communityAct = Convert.ToInt64(Session["CURRENT_COMU"]); long userId = (long)Session["USER_ID"]; user curUser = entities.users.Find(userId); List <ShowMessage> pubMessageList = ep.GetChatMessages(userId); List <TaskVerItem> taskcommentList = new List <TaskVerItem>(); List <taskcomment> commentList = entities.taskcomments .Where(m => m.task_id == id).ToList(); foreach (var item in commentList) { TaskVerItem taskVerItem = new TaskVerItem(); taskVerItem.comment_datetime = item.created_at; taskVerItem.task_comment = item.comment; long taskUserId = item.user_id; user taskUser = entities.users.Find(taskUserId); taskVerItem.comment_username = taskUser.first_name1 + " " + taskUser.last_name1; taskcommentList.Add(taskVerItem); } taskuser taskuser = entities.taskusers.Where(m => m.user_id == userId).FirstOrDefault(); string taskList = taskuser.task_list; if (taskList != null) { string[] strList = taskList.Split(','); var list = new List <string>(strList); list.Remove(id.ToString()); string tempListStr = ""; foreach (var item in list) { if (item == list.Last()) { tempListStr += item; } else { tempListStr += item + ","; } } if (tempListStr == "") { taskuser.task_list = null; } else { taskuser.task_list = tempListStr; } entities.SaveChanges(); } tareasViewModel viewModel = new tareasViewModel(); titulosList = ep.GetTitulosByTitular(userId); listComunities = ep.GetCommunityListByTitular(titulosList); viewModel.communityList = listComunities; viewModel.side_menu = "tareas"; viewModel.side_sub_menu = "tareas_vertarea"; viewModel.document_category_list = entities.document_type.Where(x => x.community_id == communityAct).ToList(); viewModel.curUser = curUser; viewModel.pubTaskList = ep.GetNotifiTaskList(userId); viewModel.viewTask = entities.tasks.Find(id); viewModel.pubMessageList = pubMessageList; viewModel.messageCount = ep.GetUnreadMessageCount(pubMessageList); viewModel.taskcommentList = taskcommentList; return(View(viewModel)); } catch (Exception ex) { return(Redirect(Url.Action("Index", "Error"))); } } else { return(Redirect(Url.Action("iniciar", "iniciar"))); } }
public ActionResult ver(long?viewID) { if (Session["USER_ID"] != null) { if (viewID != null) { long userId = (long)Session["USER_ID"]; user curUser = entities.users.Find(userId); List <ShowMessage> pubMessageList = ep.GetChatMessages(userId); List <TaskVerItem> taskcommentList = new List <TaskVerItem>(); List <taskcomment> commentList = entities.taskcomments .Where(m => m.task_id == viewID).ToList(); task viewTask = entities.tasks.Find(viewID); foreach (var item in commentList) { TaskVerItem taskVerItem = new TaskVerItem(); taskVerItem.comment_datetime = item.created_at; taskVerItem.task_comment = item.comment; long taskUserId = item.user_id; user taskUser = entities.users.Find(taskUserId); taskVerItem.comment_username = taskUser.first_name1 + " " + taskUser.last_name1; taskcommentList.Add(taskVerItem); } taskuser taskuser = entities.taskusers.Where(m => m.user_id == userId).FirstOrDefault(); string taskList = taskuser.task_list; if (taskList != null) { string[] strList = taskList.Split(','); var list = new List <string>(strList); list.Remove(viewID.ToString()); string tempListStr = ""; foreach (var item in list) { if (item == list.Last()) { tempListStr += item; } else { tempListStr += item + ","; } } if (tempListStr == "") { taskuser.task_list = null; } else { taskuser.task_list = tempListStr; } entities.SaveChanges(); } verTareasViewModel viewModel = new verTareasViewModel(); viewModel.side_menu = "tareas"; viewModel.side_sub_menu = "tareas_ver"; viewModel.viewTask = viewTask; viewModel.curUser = curUser; viewModel.pubTaskList = ep.GetNotifiTaskList(userId); viewModel.pubMessageList = pubMessageList; viewModel.messageCount = ep.GetUnreadMessageCount(pubMessageList); return(View(viewModel)); } else { return(Redirect(Url.Action("NotFound", "Error"))); } } else { return(Redirect(ep.GetLogoutUrl())); } }