public ActionResult CreateTaskForProjects() { _context = new ApplicationDbContext(); string id = User.Identity.GetUserId(); ApplicationUser employee = _context.Users.SingleOrDefault(emp => emp.Id == id); // List<Projects> projectList = _context.Projects.Select(g => g).ToList<Projects>(); List <Projects> completeProject = (from gr in _context.Projects.ToList() where gr.isComplite.ToString() == "False" select gr).ToList(); var viewModel = new TaskForProjectsViewModel { tasksForProjects = new TasksForProjects(), user = employee, projects = completeProject }; return(View(viewModel)); }
public ActionResult SaveProjectTask(TaskForProjectsViewModel taskForProjectsViewModel) { _context = new ApplicationDbContext(); string id = User.Identity.GetUserId(); if (taskForProjectsViewModel.tasksForProjects.description == null || taskForProjectsViewModel.tasksForProjects.dateTimeEnd == null || taskForProjectsViewModel.tasksForProjects.dateTimeBegin == null) { ApplicationUser employee = _context.Users.SingleOrDefault(emp => emp.Id == id); List <Projects> projectList = _context.Projects.Select(g => g).ToList <Projects>(); List <Projects> completeProject = (from gr in _context.Projects.ToList() where gr.isComplite.ToString() == "False" select gr).ToList(); var viewModel = new TaskForProjectsViewModel { tasksForProjects = new TasksForProjects(), user = employee, projects = completeProject }; return(View("CreateTaskForProjects", viewModel)); } if (_context.TasksForProjects.FirstOrDefault(c => c.Id == taskForProjectsViewModel.tasksForProjects.Id) == null) { string AdminID = User.Identity.GetUserId(); taskForProjectsViewModel.tasksForProjects.fromUserId = taskForProjectsViewModel.user.Id; taskForProjectsViewModel.tasksForProjects.toProjectId = taskForProjectsViewModel.project.Id; List <ProjectsGroups> projectsGroups = (from gr in _context.ProjectsGroups.ToList() where gr.ProjId == taskForProjectsViewModel.tasksForProjects.toProjectId select gr).ToList(); List <string> usersIds = new List <string>(); // users whom we already send notification foreach (ProjectsGroups projectsID in projectsGroups) { if (projectsID.Id.ToString() != null) { List <UsersGroups> userGroups = (from gr in _context.UsersGroups.ToList() where gr.GroupId == projectsID.GroupId select gr).ToList(); foreach (UsersGroups userID in userGroups) { if (userID.Id.ToString() != null) { ApplicationUser employeeFrom = _context.Users.SingleOrDefault(emp => emp.Id == AdminID); string Title = employeeFrom.DisplayName; ApplicationUser employeeTo = _context.Users.SingleOrDefault(emp => emp.Id == userID.UserId.ToString()); //foreach (ApplicationUser user1 in MassivUsersFromGroups) // if (resUsersNotif.isContaint(user1) == false) // resUsersNotif.add(user1); if (employeeTo.FCMToken != null && usersIds.Contains(employeeTo.Id) == false) { usersIds.Add(employeeTo.Id); var FCMToken = employeeTo.FCMToken; string token = FCMToken.ToString(); string TouserId = employeeTo.Id; string Message = taskForProjectsViewModel.tasksForProjects.title; string Type = "Project"; firebase.FirebaseNotification(token, TouserId, Title, Message, Type); firebase.PushFleet(token, Message, Type); } } } } var result = taskForProjectsViewModel.tasksForProjects; _context.TasksForProjects.Add(result); } } _context.SaveChanges(); return(RedirectToAction("Index", "Tasks")); }