Esempio n. 1
0
 public void UpdateProject(ProjectViewModel m)
 {
     using (new TransactionScope(TransactionScopeOption.Suppress))
     {
         var now = DateTime.UtcNow;
         var d = new ProjectsDataContext();
         var p = new Project();
         p.ProjectName = (m.ProjectName == "null") ? null : m.ProjectName;
         p.Comment = (m.Comment == "null") ? null : m.Comment;
         p.ProjectID = Guid.NewGuid();
         p.VersionOwnerContactID = m.Creator;
         p.VersionUpdated = now;
         p.VersionUpdatedBy = m.User;
         d.Projects.InsertOnSubmit(p);
         var n = new ProjectPlan();
         n.ProjectPlanID = Guid.NewGuid();
         n.ProjectID = p.ProjectID;
         n.ProjectPlanName = "Resource Modelling";
         n.ResponsibleContactID = m.Creator;
         n.VersionOwnerContactID = m.User;
         n.VersionUpdated = now;
         n.VersionUpdatedBy = m.User;
         d.ProjectPlans.InsertOnSubmit(n);
         var t = new ProjectPlanTask();
         t.ProjectPlanTaskID = Guid.NewGuid();
         t.ProjectPlanID = n.ProjectPlanID;
         t.ProjectTaskName = m.StageName;
         t.VersionOwnerContactID = m.Creator;
         t.VersionUpdated = now;
         t.VersionUpdatedBy = m.User;
         d.ProjectPlanTasks.InsertOnSubmit(t);
         var tr = new ProjectPlanTask();
         tr.ProjectPlanTaskID = Guid.NewGuid();
         tr.ProjectPlanID = n.ProjectPlanID;
         tr.ProjectTaskName = "Review";
         tr.VersionOwnerContactID = m.Reviewer;
         tr.VersionUpdated = now.AddSeconds(-1); //This is not the current task
         tr.VersionUpdatedBy = m.User;
         d.ProjectPlanTasks.InsertOnSubmit(tr);
         var tc = new ProjectPlanTask();
         tc.ProjectPlanTaskID = Guid.NewGuid();
         tc.ProjectPlanID = n.ProjectPlanID;
         tc.ProjectTaskName = "Complete";
         tc.VersionOwnerContactID = m.User;
         tc.VersionUpdated = now.AddSeconds(-1); //This is not the current task
         tc.VersionUpdatedBy = m.User;
         d.ProjectPlanTasks.InsertOnSubmit(tr);
         d.SubmitChanges();
     }
 }
Esempio n. 2
0
        public ActionResult EditProject(ProjectViewModel m)
        {
            //Only process new projects atm
            if (m.Project != default(Guid))
                throw new NotImplementedException();

            //Do save project here
            if (ModelState.IsValid)
            {
                try
                {
                    if (!Services.Authorizer.Authorize(Permissions.ManageProjects, T("Couldn't create project.")))
                        return new HttpUnauthorizedResult();

                    //Validate
                    if (string.IsNullOrEmpty(m.ProjectName))
                        ModelState.AddModelError("ProjectName", T("Project name is required.").ToString());

                    if (ModelState.IsValid)
                    {
                        ProjectService.UpdateProject(m);
                        return RedirectToAction("ProjectList");
                    }

                    return View(m);
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
                ViewData["EditError"] = "Please, correct all errors.";
            if (m.Project == default(Guid))
                return EditProject();
            else
                return EditProject(m.Project.ToString());
        }
Esempio n. 3
0
 public ActionResult EditProject(string id = null, string verb = null)
 {
     if (!Services.Authorizer.Authorize(Permissions.ManageProjects, T("Couldn't edit the project.")))
         return new HttpUnauthorizedResult();
     //is new
     if (string.IsNullOrEmpty(id))
     {
         var model = new ProjectViewModel
         {
             User = getCurrentUserID()
         };
         model.Contacts = UserService.GetContactList();
         model.Creator = model.User;
         return View(model);
     }
     //delete
     else if (verb == "delete")
     {
         ProjectService.DeleteProject(new Guid(id), getCurrentUserID());
         return RedirectToAction("ProjectList");
     }
     //edit
     else
     {
         var model = new ProjectViewModel
         {
             Projects = ProjectService.GetProjectList(),
             User = UserService.GetContactID(Services.WorkContext.CurrentUser.UserName).Value
         };
         model.Project = new Guid(id);
         model.Stages = ProjectService.GetStagesList(model.Project);
         model.Contacts = UserService.GetContactList();
         model.Creator = model.User;
         return View(model);
     }
 }