public ProjectAndResources GetProject(int id, string userid)
        {
            ProjectAndResources model = new ProjectAndResources();
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                model.Project = db.Projects.Include("Tasks").Where(x => x.ProjectId == id && x.UserId == userid).FirstOrDefault();
                model.Resources = db.Resources.Include("Tasks").Include("Contacts").Where(x => x.UserId == userid).ToList();
            }
            model.taskVM = new AddTaskVM() { Task = PrepNewTask(id) };
            model.taskVM.GetResourcesDropDownList(userid);

            return model;
        }
 public ActionResult Index()
 {
     ProjectAndResources model = new ProjectAndResources();
     using (ApplicationDbContext db = new ApplicationDbContext())
     {
         model.Resources = db.Resources.Include("Contacts").Include("Tasks").Where(p => p.UserId == UserId).OrderBy(x => x.CompanyName).ToList();
         model.Projects = db.Projects.Include("Tasks").Where(p => p.UserId == UserId).OrderByDescending(x => x.StartDate).ToList();
     }
     return View(model);
 }
 public ActionResult UpdateOptions()
 {
     ProjectAndResources model = new ProjectAndResources();
     model.Contacts = db.Contacts.OrderBy(x => x.Name).ToList();
     model.Projects = db.Projects.Include("Tasks").Where(p => p.UserId == UserId).ToList();
     List<int> pIDS = new List<int>();
     model.Projects.ForEach(p => pIDS.Add(p.ProjectId));
     model.Resources = db.Resources.Include("Tasks").Include("Contacts").OrderBy(x => x.CompanyName).ToList();
     model.Tasks = db.Tasks.Where(t => pIDS.Contains(t.ProjectId)).OrderBy(x => x.StartDate).ToList();
     return View(model);
 }
        public ActionResult AddTask(ProjectAndResources model)
        {
            try
            {
                _adapter.AddTask(model.taskVM.Task);
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        TempData["Exception"] += string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
                return RedirectToAction("Index");
            }

            return RedirectToAction("ProjectDetails", new { id = model.taskVM.Task.ProjectId });
        }