Beispiel #1
0
 public ActionResult SaveExistProject(Project project, string activenodes, string startdate)
 {
     if (ModelState.IsValid)
     {
         if (project.Id == 0)
         {
             if (_projectRepository.FindAll().Any(x => x.ErpCode == project.ErpCode))
             {
                 return Json(new JsonResponse { Success = false, Message = "Erp帐号重复,已有该帐号的工程录入" });
             }
             if (!string.IsNullOrWhiteSpace(project.NumberOf186) && _projectRepository.FindAll().Any(x => x.NumberOf186 == project.NumberOf186))
             {
                 return Json(new JsonResponse { Success = false, Message = "传单编号重复,已有该编号的工程录入" });
             }
             project.Category = _categoryRepostitory.Find(project.CategoryId);
             _projectRepository.Add(project);
             project.TaskLogs = new Collection<TaskLog>();
             project.Documents = new Collection<Document>();
             project.GenerateTaskLog(DateTime.Parse(startdate),activenodes);
             project.GenerateDocument();
             UnitOfWork.Commit();
         }
         UnitOfWork.Commit();
         return Json(new JsonResponse { Success = true,Message = "已录入工程"+project.ErpCode+project.Name});
     }
     return Json(new JsonResponse { Success = false, Message = "不能保存,请检查输入是否正确,或者联系管理员" });
 }
Beispiel #2
0
        public ActionResult Save(Project project)
        {
            if (ModelState.IsValid)
            {
                if (project.Id==0)
                {
                    if (_projectRepository.FindAll().Any(x => x.ErpCode == project.ErpCode))
                    {
                        return Json(new JsonResponse { Success = false, Message = "Erp帐号重复,已有该帐号的工程录入" });
                    }
                    if (!string.IsNullOrWhiteSpace(project.NumberOf186) && _projectRepository.FindAll().Any(x => x.NumberOf186 == project.NumberOf186))
                    {
                        return Json(new JsonResponse { Success = false, Message = "传单编号重复,已有该编号的工程录入" });
                    }
                    project.Category = _categoryRepostitory.Find(project.CategoryId);
                    project.TaskLogs = new Collection<TaskLog>();
                    project.Documents = new Collection<Document>();
                    _projectRepository.Add(project);
                    project.GenerateTaskLog(DateTime.Now.Date);
                    project.GenerateDocument();
                    var startnode = project.TaskLogs.SingleOrDefault(x => x.TaskNode.NodeFlag == 1);
                    startnode.UserId = CurrentUser.UserId;
                    startnode.Kickoff(DateTime.Now);
                    UnitOfWork.Commit();
                }
                else
                {
                   var prj = _projectRepository.Find(project.Id);
                   if (prj.ErpCode != project.ErpCode)
                    {
                        if (_projectRepository.FindAll().Any(x => x.ErpCode == project.ErpCode))
                        {
                            return Json(new JsonResponse { Success = false, Message = "Erp帐号重复,已有该帐号的工程录入" });
                        }
                    }
                    if (prj.NumberOf186 != project.NumberOf186)
                    {
                        if (!string.IsNullOrWhiteSpace(project.NumberOf186) && _projectRepository.FindAll().Any(x => x.NumberOf186 == project.NumberOf186))
                        {
                            return Json(new JsonResponse { Success = false, Message = "传单编号重复,已有该编号的工程录入" });
                        }
                    }

                    TryUpdateModel(prj);
                    UnitOfWork.Commit();
                }

                return Json(new JsonResponse { Success = true, Message = "已录入工程" + project.ErpCode + project.Name });
            }
            return Json(new JsonResponse { Success = false, Message = "不能保存,请检查输入是否正确,或者联系管理员" });
        }