Exemple #1
0
        public IHttpActionResult CreateProject(ReimageInfo entity)
        {
            using (var tran = new TransactionScope())
            {
                entity.Id         = Guid.NewGuid();
                entity.ProjectId  = ProjectInfo.CreateMainProject(FlowCode.Reimage, entity.USCode, NodeCode.Start, entity.CreateUserAccount);
                entity.CreateDate = DateTime.Now;
                entity.Add();
                entity.AddProjectUsers();
                entity.SendRemind();
                entity.SendWorkTask();
                entity.CreateSubProject();
                entity.CreateAttachmentsMemo();
                ProjectNode.GenerateOnCreate(FlowCode.Reimage, entity.ProjectId);
                tran.Complete();
            }

            return(Ok(entity));
        }
Exemple #2
0
        public IHttpActionResult UploadAttachment(string flowCode, string typeCode, string usCode, Guid Id)
        {
            var refTableId   = string.Empty;
            var refTableName = string.Empty;
            var projectInfo  = ProjectInfo.Get(Id);
            var projectId    = string.Empty;

            if (projectInfo == null)
            {
                projectId = ProjectInfo.CreateDLProject(Id, flowCode, usCode, NodeCode.Start, ClientCookie.UserCode, false);
            }
            else
            {
                projectId = projectInfo.ProjectId;
            }
            using (TransactionScope tranScope = new TransactionScope())
            {
                switch (flowCode)
                {
                case FlowCode.Closure:
                    refTableName = "ClosureInfo";
                    var closureInfo = ClosureInfo.FirstOrDefault(i => i.ProjectId == projectId);
                    if (closureInfo != null)
                    {
                        refTableId = closureInfo.Id.ToString();
                    }
                    else
                    {
                        closureInfo                    = new ClosureInfo();
                        closureInfo.Id                 = Guid.NewGuid();
                        closureInfo.ProjectId          = projectId;
                        closureInfo.USCode             = usCode;
                        closureInfo.CreateDate         = DateTime.Now;
                        closureInfo.CreateUserAccount  = ClientCookie.UserCode;
                        closureInfo.CreateUserNameENUS = ClientCookie.UserNameENUS;
                        closureInfo.CreateUserNameZHCN = ClientCookie.UserNameZHCN;
                        closureInfo.Add();
                        refTableId = closureInfo.Id.ToString();
                    }
                    break;

                case FlowCode.Rebuild:
                    refTableName = "RebuildInfo";
                    var rebuildInfo = RebuildInfo.FirstOrDefault(i => i.ProjectId == projectId);
                    if (rebuildInfo != null)
                    {
                        refTableId = rebuildInfo.Id.ToString();
                    }
                    else
                    {
                        rebuildInfo                    = new RebuildInfo();
                        rebuildInfo.Id                 = Guid.NewGuid();
                        rebuildInfo.ProjectId          = projectId;
                        rebuildInfo.USCode             = usCode;
                        rebuildInfo.CreateTime         = DateTime.Now;
                        rebuildInfo.CreateUserAccount  = ClientCookie.UserCode;
                        rebuildInfo.CreateUserNameENUS = ClientCookie.UserNameENUS;
                        rebuildInfo.CreateUserNameZHCN = ClientCookie.UserNameZHCN;
                        rebuildInfo.Add();
                        refTableId = rebuildInfo.Id.ToString();
                    }
                    break;

                case FlowCode.MajorLease:
                    refTableName = "MajorLeaseInfo";
                    var majorLeaseInfo = MajorLeaseInfo.FirstOrDefault(i => i.ProjectId == projectId);
                    if (majorLeaseInfo != null)
                    {
                        refTableId = majorLeaseInfo.Id.ToString();
                    }
                    else
                    {
                        majorLeaseInfo                    = new MajorLeaseInfo();
                        majorLeaseInfo.Id                 = Guid.NewGuid();
                        majorLeaseInfo.ProjectId          = projectId;
                        majorLeaseInfo.USCode             = usCode;
                        majorLeaseInfo.CreateTime         = DateTime.Now;
                        majorLeaseInfo.CreateUserAccount  = ClientCookie.UserCode;
                        majorLeaseInfo.CreateUserNameENUS = ClientCookie.UserNameENUS;
                        majorLeaseInfo.CreateUserNameZHCN = ClientCookie.UserNameZHCN;
                        majorLeaseInfo.Add();
                        refTableId = majorLeaseInfo.Id.ToString();
                    }
                    break;

                case FlowCode.Renewal:
                    refTableName = "RenewalInfo";
                    var renewalInfo = RenewalInfo.Get(projectId);
                    if (renewalInfo != null)
                    {
                        refTableId = renewalInfo.Id.ToString();
                    }
                    else
                    {
                        renewalInfo                   = new RenewalInfo();
                        renewalInfo.Id                = Guid.NewGuid();
                        renewalInfo.ProjectId         = projectId;
                        renewalInfo.USCode            = usCode;
                        renewalInfo.CreateTime        = DateTime.Now;
                        renewalInfo.CreateUserAccount = ClientCookie.UserCode;
                        renewalInfo.Add();
                        refTableId = renewalInfo.Id.ToString();
                    }
                    break;

                case FlowCode.Reimage:
                    refTableName = "ReimageInfo";
                    var reimageInfo = ReimageInfo.GetReimageInfo(projectId);
                    if (reimageInfo != null)
                    {
                        refTableId = reimageInfo.Id.ToString();
                    }
                    else
                    {
                        reimageInfo                    = new ReimageInfo();
                        reimageInfo.Id                 = Guid.NewGuid();
                        reimageInfo.ProjectId          = projectId;
                        reimageInfo.USCode             = usCode;
                        reimageInfo.CreateDate         = DateTime.Now;
                        reimageInfo.CreateUserAccount  = ClientCookie.UserCode;
                        reimageInfo.CreateUserNameENUS = ClientCookie.UserNameENUS;
                        reimageInfo.CreateUserNameZHCN = ClientCookie.UserNameZHCN;
                        reimageInfo.Add();
                        refTableId = reimageInfo.Id.ToString();
                    }
                    break;
                }

                if (!string.IsNullOrEmpty(refTableId))
                {
                    var    files         = HttpContext.Current.Request.Files;
                    var    file          = files[0];
                    string fileName      = Path.GetFileName(file.FileName);
                    string fileExtension = Path.GetExtension(file.FileName);
                    var    current       = System.Web.HttpContext.Current;
                    string internalName  = Guid.NewGuid() + fileExtension;
                    string absolutePath  = current.Server.MapPath("~/") + "UploadFiles/" + internalName;
                    file.SaveAs(absolutePath);

                    Attachment att = Attachment.FirstOrDefault(i => i.RefTableID == refTableId && i.RefTableName == refTableName && i.TypeCode == typeCode);
                    if (att != null)
                    {
                        att.InternalName    = internalName;
                        att.RefTableName    = refTableName;
                        att.RefTableID      = refTableId;
                        att.RelativePath    = "//";
                        att.Name            = fileName;
                        att.Extension       = fileExtension;
                        att.Length          = file.ContentLength;
                        att.CreateTime      = DateTime.Now;
                        att.CreatorNameZHCN = ClientCookie.UserNameZHCN;
                        att.CreatorNameENUS = ClientCookie.UserNameENUS;
                        att.CreatorID       = ClientCookie.UserCode;
                        Attachment.Update(att);
                    }
                    else
                    {
                        att = new Attachment();
                        att.InternalName    = internalName;
                        att.RefTableName    = refTableName;
                        att.RefTableID      = refTableId;
                        att.RelativePath    = "//";
                        att.Name            = fileName;
                        att.Extension       = fileExtension;
                        att.Length          = file.ContentLength;
                        att.CreateTime      = DateTime.Now;
                        att.CreatorNameZHCN = ClientCookie.UserNameZHCN;
                        att.CreatorNameENUS = ClientCookie.UserNameENUS;
                        att.CreatorID       = ClientCookie.UserCode;
                        att.ID       = Guid.NewGuid();
                        att.TypeCode = typeCode;
                        Attachment.Add(att);
                    }
                }
                tranScope.Complete();
                return(Ok());
            }
        }