//
        // GET: /Projects/Details/{id}
        public ActionResult Details(int id)
        {
            if (!Auth.IsLoggedIn())
            {
                return RedirectToAction("Login", "Home");
            }

            ProjectContext projectContext = null;

            using (var db = new DataClassesDataContext())
            {
                Project project = (from p in db.Projects
                                   where p.TenantId == Auth.GetCurrentUser().TenantId && p.ProjectId == id
                                   select p).FirstOrDefault();
                if (project != null)
                {
                    projectContext = new ProjectContext(project);
                }
            }

            if (projectContext == null)
            {
                return View("NotFound");
            }

            return View(projectContext);
        }
        public ActionResult Edit(ProjectContext projectToModify)
        {
            using (var db = new DataClassesDataContext())
            {
                var project = (from p in db.Projects
                               where p.ProjectId == projectToModify.ProjectId
                               select p).FirstOrDefault();

                //Check to make sure user actually input values

                project.Name = (!string.IsNullOrWhiteSpace(projectToModify.Name)) ? projectToModify.Name : "(Untitled Project)";
                if (projectToModify.RawDateStart != null && projectToModify.RawDateStart != DateTime.MinValue)
                    project.Start = projectToModify.RawDateStart;
                if (projectToModify.RawDateEnd != null && projectToModify.RawDateEnd != DateTime.MinValue)
                    project.ExpectedEnd = projectToModify.RawDateEnd;

                //Check if the start date occurs after the end date, and swap them if so
                if (project.Start.Value.CompareTo(project.ExpectedEnd.Value) > 0)
                {
                    var start = project.Start;
                    project.Start = project.ExpectedEnd;
                    project.ExpectedEnd = start;
                }

                if (projectToModify.StatusId > 0)
                    project.Status = projectToModify.StatusId;

                db.SubmitChanges();

            }
            return RedirectToAction("Index");
        }