예제 #1
0
 public int Create(NewModel model, int creatorId)
 {
     return -1;
 }
예제 #2
0
        public int Create(NewModel model, int creatorId)
        {
            Task task = new Task();

            task.Publisher = session.Load<User>(creatorId);
            task.Project = session.Load<Project>(model.CurrentProject.TailSelectedProject.Id);
            addParent(task, model.TaskItem.Parent);
            setAccepter(task, model.TaskItem.Accepter);

            model.TaskItem.Fill(task);

            task.Publish();

            session.Save(task);
            session.Flush();
            // important: to ensure the task is published first and then assigned later!

            if (model.TaskItem.Owner.Id.HasValue)
            {
                task.Owner = session.Load<User>(model.TaskItem.Owner.Id.Value);
                task.Assign();
            }

            return task.Id;
        }
예제 #3
0
        public ActionResult New(int? projectId, int? parentId)
        {
            NewModel model = new NewModel();
            fillNewModel(model, projectId, parentId);

            return View(model);
        }
예제 #4
0
        private void fillNewModel(NewModel model, int? projectId, int? parentId)
        {
            model.TaskItem = new FullItemModel();

            if (parentId.HasValue)
            {
                //TODO: need check first? or return null from service?
                model.TaskItem.Parent = _taskService.GetLite(parentId.Value);
            }

            if (projectId == null)
            {
                if (Request.Cookies[CookieKey.PrevProjectInTaskNew] != null)
                {
                    projectId = int.Parse(Request.Cookies[CookieKey.PrevProjectInTaskNew].Value);
                }
                else
                {
                    model.CurrentProject = _projectService.GetDropdownlistLink(userHelper.CurrentUserId.Value);
                    projectId = model.CurrentProject.TailSelectedProject.Id;
                }
            }
            else
            {
                model.CurrentProject = _projectService.GetDropdownlistLink(userHelper.CurrentUserId.Value, projectId.Value);
            }

            int intProjectId = projectId.Value;
            model.CurrentProject = _projectService.GetDropdownlistLink(userHelper.CurrentUserId.Value, intProjectId);
            model.AllDifficulties = _projectConfigService.GetDifficulties(intProjectId);
            model.Owners = _userService.GetOwners(intProjectId);
            model.Accepters = _userService.GetAccepters(projectId.Value);
            model.AllPriorities = _projectConfigService.GetPriorities(intProjectId);
            //TODO: duplicated with model.CurrentProject?
            model.TaskItem.Project = new FFLTask.SRV.ViewModel.Project.FullItemModel { LiteItem = new FFLTask.SRV.ViewModel.Project.LiteItemModel { Id = intProjectId } };
        }
예제 #5
0
 private ActionResult redirectAfterNew(NewModel model, int taskId)
 {
     switch (model.Redirect)
     {
         case RedirectPage.Current:
             return RedirectToAction("Edit", new { taskId = taskId });
         case RedirectPage.Brother:
             return RedirectToAction("New", new { parentId = model.TaskItem.Parent.Id });
         case RedirectPage.Child:
             return RedirectToAction("New", new { parentId = taskId });
         case RedirectPage.List:
             return RedirectToAction("List", new { projectId = model.CurrentProject.TailSelectedProject.Id });
         case RedirectPage.Other:
             return RedirectToAction("New");
         //TODO:
         default: throw new Exception();
     }
 }
예제 #6
0
        public ActionResult New(NewModel model, IList<HttpPostedFileBase> file)
        {           
            if (model.IdOrName == SearchBy.Name)
            {
                string strSelectedParentId = Request.Form["selectedParentTaskId"];
                if (!string.IsNullOrEmpty(strSelectedParentId))
                {
                    model.TaskItem.Parent.Id =
                        Convert.ToInt32(Request.Form["selectedParentTaskId"]);                    
                }
                //TODO: should use a specific viewmodel for parent task search
                ModelState.Remove("TaskItem.Parent.Id");
            }

            int projectId = model.CurrentProject.TailSelectedProject.Id;
            int? parentId = model.TaskItem.Parent.Id;

            ModelState.Remove("TaskItem.Parent.Title");
            if (!ModelState.IsValid)
            {
                fillNewModel(model, projectId, parentId);
                return View(model);
            }
            if (model.TaskItem.LiteItem.Virtual && model.TaskItem.ExpectedWorkPeriod.HasValue)
            {
                fillNewModel(model, projectId, parentId);
                ModelState.AddModelError("TaskItem.LiteItem.Virtual", "* 虚任务不能包含工时 ");
                return View(model);
            }

            if (getPrivilegeInProject(projectId) != PrivilegeInProject.HasPublish)
            {
                //TODO;
                //throw new NotImplementedException();
            }

            if (parentId.HasValue &&
                string.IsNullOrEmpty(_taskService.GetTitle(parentId.Value)))
            {
                fillNewModel(model, projectId, parentId);
                ViewBag.ShowNotFound = true;
                return View(model);
            }

            int taskId = _taskService.Create(model, userHelper.CurrentUserId.Value);
            upload(file, taskId);

            HttpCookie cookie = new HttpCookie(CookieKey.PrevProjectInTaskNew, projectId.ToString());
            Response.Cookies.Add(cookie);

            return redirectAfterNew(model, taskId);
        }