Exemple #1
0
        public static void SendMail_CreateWS(KMailInfo kMailInfo, CreateWSModel createWSModel)
        {
            var kMailModel = KMail.SendMail(kMailInfo);

            KWSLogCreateWS kWSLogCreateWS = new KWSLogCreateWS
            {
                KMailModel = kMailModel,
                CreateWSModel = createWSModel,
            };

            KWSLog kWSLog = new KWSLog
            {
                EngNum = createWSModel.EngNum,
                KWSLogType = createWSModel.IsAuto.GetValueOrDefault(true) ? KWSLogType.CreateWSAuto : KWSLogType.CreateWSManual,
                Info = KSerDSer.JSerialize<KWSLogCreateWS>(kWSLogCreateWS),
            };

            IMWrapWSLog.KWSLog(kWSLog);

            //Task task = new Task(() =>
            //{
            //    var kMailModel = KMail.SendMail(kMailInfo);

            //    KWSLogCreateWS kWSLogCreateWS = new KWSLogCreateWS
            //    {
            //        KMailModel = kMailModel,
            //        CreateWSModel = createWSModel,
            //    };

            //    KWSLog kWSLog = new KWSLog
            //    {
            //        EngNum = createWSModel.EngNum,
            //        KWSLogType = createWSModel.IsAuto.GetValueOrDefault(true) ? KWSLogType.CreateWSAuto : KWSLogType.CreateWSManual,
            //        Info = KSerDSer.JSerialize<KWSLogCreateWS>(kWSLogCreateWS),
            //    };

            //    IMWrapWSLog.KWSLog(kWSLog);
            //});

            //task.Start(TaskScheduler.FromCurrentSynchronizationContext());
        }
Exemple #2
0
 public JObject CreateWS(CreateWSModel createWSModel)
 {
     var result = KCreate.CreateWS(createWSModel);
     return JObject.FromObject(result);
 }
Exemple #3
0
        public static bool IsEngFunctionAudit(CreateWSModel createWSModel)
        {
            using (ReferenceDBContext db = new ReferenceDBContext())
            {
                using (var tran = db.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted))
                {
                    var result_00 = db.Engagements.Where(x => x.EngagementNumber.Equals(createWSModel.EngNum, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                    if (result_00 != null)
                    {
                        var result_01 = db.Functions.Where(x => x.FunctionName.Equals("Audit", StringComparison.OrdinalIgnoreCase)).Select(y => y.FucntionID).FirstOrDefault();

                        if (result_01 == null)
                        {
                            throw new KException("Audit Function not defined in Ref.Function table.");
                        }

                        var result_02 = db.DRMSUsers.Where(x => x.EmplID.Equals(createWSModel.PartnerEmpId, StringComparison.OrdinalIgnoreCase)).Select(y => y.GoFunction).FirstOrDefault();

                        if (result_02 == null)
                        {
                            throw new KException(string.Format("Partner[{0}] don't have Function defined in Ref.DRMSUsers.", createWSModel.PartnerEmpId));
                        }

                        if (!result_01.IsEquals(result_02))
                        {
                            throw new KException(string.Format("Partner[{0}] is not associated[GoFunction = {1}] with Audit[FunctionId = {2}] Ref.DRMSUsers.", createWSModel.PartnerEmpId, result_02, result_01));
                        }
                    }
                    else
                    {
                        var result_03 = db.Workspaces.Where(x => x.EngagementNumber.Equals(createWSModel.EngNum, StringComparison.OrdinalIgnoreCase) && x.Function.Equals("Audit", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                        if (result_03 == null)
                        {
                            throw new KException(string.Format("EngNum {0} is not an Audit Engagement", createWSModel.EngNum));
                        }
                    }
                }
            }

            return true;
        }
Exemple #4
0
 public static CreateWSModel CreateWS(CreateWSModel createWSModel)
 {
     return CreateWS_Private(createWSModel);
 }
Exemple #5
0
        private static CreateWSModel CreateWS_Private(CreateWSModel createWSModel)
        {
            CreateWS create = new CreateWS();
            try
            {
                //if (KWSUtility.IsEngFunctionAudit(createWSModel))
                //{
                createWSModel.IsAuto = createWSModel.IsAuto.GetValueOrDefault(true);
                create.Create(createWSModel);
                //}
            }
            catch (Exception ex)
            {
                KElmahUtility.LogException(ex);

                createWSModel.Success = false;
                createWSModel.FailureMsg = createWSModel.FailureMsg + " " + ex.Message;

                KWSLogCreateWS kWSLogCreateWS = new KWSLogCreateWS
                {
                    KMailModel = null,
                    CreateWSModel = createWSModel,
                };

                KWSLog kWSLog = new KWSLog
                {
                    EngNum = createWSModel.EngNum,
                    KWSLogType = KWSLogType.CreateWSFail,
                    Info = KSerDSer.JSerialize<KWSLogCreateWS>(kWSLogCreateWS),
                };

                KRepKWSLog.KWSLog(kWSLog);
            }

            if (createWSModel.Success)
                UpdateWS(createWSModel.EngNum, createWSModel.KPMGOnly);

            return createWSModel;
        }
Exemple #6
0
        private bool ValidateCreateWS(CreateWSModel createWSModel)
        {
            if (createWSModel.EngNum.IsWSExists())
                throw new KException(string.Format("Workspace already exists for [EngNum = {0}].", createWSModel.EngNum));

            createWSModel.PartnerId = createWSModel.PartnerEmpId.ToUserId();
            if (createWSModel.PartnerId == null)
                throw new KException(string.Format("{0} [EmpId = {1}] not present in IManage DOCUSERS table.", "Partner", createWSModel.PartnerEmpId));

            createWSModel.ManagerId = createWSModel.ManagerEmpId.ToUserId();
            if (createWSModel.ManagerId == null)
            {
                createWSModel.FailureMsg = string.Format("Workspace created[Non mandatory field] -> {0} [EmpId = {1}] not present in IManage DOCUSERS table.", "Manager", createWSModel.ManagerEmpId);
                //throw new KException(string.Format("{0} [EmpId = {1}] not present in IManage DOCUSERS table.", "Manager", createWSModel.ManagerEmpId));
                createWSModel.ManagerEmpId = createWSModel.PartnerEmpId;
                createWSModel.ManagerId = createWSModel.PartnerId;

            }

            createWSModel.PartnerAssistanceId = string.IsNullOrWhiteSpace(createWSModel.PartnerAssistanceEmpId) ? "" : createWSModel.PartnerAssistanceEmpId.ToUserId();
            if (createWSModel.PartnerAssistanceId == null)
            {
                createWSModel.FailureMsg = string.Format("Workspace created[Non mandatory field] -> {0} [EmpId = {1}] not present in IManage DOCUSERS table.", "PartnerAssistant", createWSModel.PartnerAssistanceEmpId);
                //throw new KException(string.Format("{0} [EmpId = {1}] not present in IManage DOCUSERS table.", "PartnerAssistant", createWSModel.PartnerAssistanceEmpId));
                createWSModel.PartnerAssistanceEmpId = string.Empty;
            }

            if (!IMDBUtility.IsClientInC1(createWSModel.ClientId))
                throw new KException(string.Format("{0} [ClientId = {1}] not present in IManage CUSTOM1 table.", "Client", createWSModel.ClientId));

            if (!IMDBUtility.IsEngInC2(createWSModel.EngNum, createWSModel.ClientId))
                if (KConfig.IsToInsertEngInC2)
                {
                    IMDBUtility.AddEngInC2(createWSModel.EngNum, createWSModel.EngDescription, createWSModel.ClientId);
                }
                else
                    throw new KException(string.Format("{0} [EngNum = {1}] and {2} [ClientId = {3}] mapping not present in IManage CUSTOM2 table.", "Engagement", createWSModel.EngNum, "Client", createWSModel.ClientId));

            if (!IMDBUtility.IsPartnerInC4(createWSModel.PartnerEmpId))
                if (KConfig.IsToInsertC4AndC6)
                {
                    IMDBUtility.AddUserInC4(_iMUtil.GetUser(createWSModel.PartnerId));
                }
                else
                    throw new KException(string.Format("{0} [EmpId = {1}] not present in IManage CUSTOM4 table.", "Partner", createWSModel.PartnerEmpId));

            if (!IMDBUtility.IsManagerInC6(createWSModel.ManagerEmpId))
                if (KConfig.IsToInsertC4AndC6)
                {
                    IMDBUtility.AddUserInC6(_iMUtil.GetUser(createWSModel.ManagerEmpId));
                }
                else
                    throw new KException(string.Format("{0} [EmpId = {1}] not present in IManage CUSTOM4 table.", "Manager", createWSModel.ManagerEmpId));

            return true;
        }
Exemple #7
0
        public void Create(CreateWSModel createWSModel)
        {
            if (!ValidateCreateWS(createWSModel))
                return;

            var wsTemplate = (IManWorkspace)_iMUtil.GetObjByID<IManWorkspace>(IMObjType.IManWorkspace, KConfig.WSTemplateId);

            CreateWSGroup(wsTemplate, createWSModel.EngNum);

            var ws = _iMUtil.GetIMDb.CreateWorkspace();
            ws.SubType = IMConstant.CONST_WS_SUBTYPE;
            ws.Name = createWSModel.EngDescription + " - " + createWSModel.EngNum;  //set workspace name

            //set workspace description
            if (ws.Name != null)
            {
                ws.Description = ws.Name;
            }
            else
            {
                //If template description is blank, use workspace category(subClass) description
                if (string.IsNullOrEmpty(wsTemplate.Description))
                {
                    ws.Description = wsTemplate.GetAttributeValueByID(imProfileAttributeID.imProfileSubClassDescription).ToString();
                }
                else
                {
                    ws.Description = wsTemplate.Description;
                }
            } //wsDesc null check

            IManUser wsOwner = _iMUtil.GetIMDb.GetUser(KConfig.IMAdminId);

            if (wsOwner != null)
            {
                ws.Owner = wsOwner;
            }

            var templateSecurity = wsTemplate.Security;
            var wsSecurity = ws.Security;

            //Build Regroups
            var wsGroups = new NameValueCollection();
            foreach (IManGroupACL grpACL in wsTemplate.Security.GroupACLs)
            {
                if (grpACL.Group.Name.Substring(0, 2).ToLower() == "E_".Trim().ToLower())
                {
                    wsGroups.Add(grpACL.Group.Name, createWSModel.EngNum.Trim() + "_" + grpACL.Group.Name);
                }
            }//Group ACLs for loop

            //-----------------------------------------------------------------------------------------------
            ////Set Security
            CopySecurity(templateSecurity, wsSecurity, wsGroups);

            //Set Workspace default security to PRIVATE
            ws.Security.DefaultVisibility = imSecurityType.imPrivate;

            //Set default workspace profile from the template
            ws.Profile.SetAttributeByID(imProfileAttributeID.imProfileSubClass, wsTemplate.GetAttributeValueByID(imProfileAttributeID.imProfileSubClass));
            for (int i = (int)imProfileAttributeID.imProfileCustom1; i <= (int)imProfileAttributeID.imProfileCustom30; i++)
            {
                ws.Profile.SetAttributeByID((imProfileAttributeID)i, wsTemplate.GetAttributeValueByID((imProfileAttributeID)i));
            }

            ws.Profile.SetAttributeByID(imProfileAttributeID.imProfileCustom1, createWSModel.ClientId);
            ws.Profile.SetAttributeByID(imProfileAttributeID.imProfileCustom2, createWSModel.EngNum);
            ws.Profile.SetAttributeByID(imProfileAttributeID.imProfileCustom3, IMConstant.CONST_IMPROFILECUSTOM3);
            ws.Profile.SetAttributeByID(imProfileAttributeID.imProfileCustom4, createWSModel.PartnerEmpId);
            ws.Profile.SetAttributeByID(imProfileAttributeID.imProfileCustom6, createWSModel.ManagerEmpId);
            ws.Profile.SetAttributeByID(imProfileAttributeID.imProfileCustom7, IMConstant.CONST_IMPROFILECUSTOM7);
            ws.SetAttributeByID(imProfileAttributeID.imProfileCustom11, IMConstant.CONST_IMPROFILECUSTOM11);

            //Commit workspace to the database.
            //Workspace has to be committed before adding other objects
            string filePath = Path.GetTempFileName();
            IManProfileUpdateResult updateResult = ws.UpdateAllWithResults(filePath);//Add Workspace tab (home page) Document folders

            CopyWSDocFolders(wsTemplate.DocumentFolders, ws.DocumentFolders, wsOwner, wsGroups);

            //Copy Tabs and Tab objects and security
            CopyWSTabs(wsTemplate.Tabs, ws.Tabs, wsOwner, wsGroups);

            var mailTo = new List<WsUser>();

            if (!String.IsNullOrEmpty(createWSModel.PartnerEmpId))
            {
                var partner = _iMWSUtility.GetWsUser(createWSModel.PartnerId, false);
                partner.UserType = UserType.Partner;
                mailTo.Add(partner);

                _nRTUtility.AddUserToNRTGroup(createWSModel.EngNum + "_E_" + "ADMIN", createWSModel.PartnerId);
                _nRTUtility.AddUserToNRTGroup(createWSModel.EngNum + "_E_" + "MEMBERS", createWSModel.PartnerId);
            }
            if (!String.IsNullOrEmpty(createWSModel.ManagerEmpId))
            {
                var manager = _iMWSUtility.GetWsUser(createWSModel.ManagerId, false);
                manager.UserType = UserType.Manager;
                mailTo.Add(manager);

                _nRTUtility.AddUserToNRTGroup(createWSModel.EngNum + "_E_" + "ADMIN", createWSModel.ManagerId);
                _nRTUtility.AddUserToNRTGroup(createWSModel.EngNum + "_E_" + "MEMBERS", createWSModel.ManagerId);
            }
            if (!String.IsNullOrEmpty(createWSModel.PartnerAssistanceEmpId))
            {
                var partnerAssistance = _iMWSUtility.GetWsUser(createWSModel.PartnerAssistanceId, false);
                partnerAssistance.UserType = UserType.PartnerAssistance;
                mailTo.Add(partnerAssistance);

                _nRTUtility.AddUserToNRTGroup(createWSModel.EngNum + "_E_" + "ADMIN", createWSModel.PartnerAssistanceId);
                _nRTUtility.AddUserToNRTGroup(createWSModel.EngNum + "_E_" + "MEMBERS", createWSModel.PartnerAssistanceId);
            }

            var currentUser = IMUtility2.GetCurrentUser(_iMWSUtility);

            if(KConfig.SendMailToRequestor)
                mailTo.Add(currentUser);

            createWSModel.Success = true;

            IMWrapUtility.SendMail_CreateWS(new KMailInfo
            {
                KMailType = createWSModel.IsAuto.GetValueOrDefault(true) ? KMailType.WSCreateAuto : KMailType.WSCreateManual,
                EngNum = createWSModel.EngNum,
                EngName = createWSModel.EngDescription,
                To = mailTo.GetToMail(),
                Requestor = new KeyValuePair<string, string>(currentUser.Name, currentUser.FullName)
            }, createWSModel);
        }