Example #1
0
        public ActionResult Create(int acid, InsiderTrading.Models.COUserInfoModel objUserInfoModel)
        {
            LoginUserDetails        objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);
            List <PopulateComboDTO> lstSelectedRole     = null;
            UserInfoSL objUserInfoSL = new UserInfoSL();

            InsiderTradingDAL.UserInfoDTO objUserInfoDTO = new UserInfoDTO();
            try
            {
                InsiderTrading.Common.Common.CopyObjectPropertyByName(objUserInfoModel, objUserInfoDTO);
                objUserInfoDTO.UserTypeCodeId = ConstEnum.Code.COUserType;
                objUserInfoDTO.LoggedInUserId = objLoginUserDetails.LoggedInUserID;
                //Encrypt Password
                string o_sPassword = string.Empty;
                if (objUserInfoModel.SubmittedRole != null && objUserInfoModel.SubmittedRole.Count() > 0)
                {
                    var sSubmittedRoleList = String.Join(",", objUserInfoModel.SubmittedRole);
                    objUserInfoDTO.SubmittedRoleIds = sSubmittedRoleList;
                }
                objUserInfoDTO.Password = "";
                objUserInfoSL.InsertUpdateUserDetails(objLoginUserDetails.CompanyDBConnectionString, objUserInfoDTO);
                ArrayList lst = new ArrayList();
                //before showing success message check if first name and last name is NOT NULL
                string fname = objUserInfoDTO.FirstName == null ? "" : objUserInfoDTO.FirstName.Replace("'", "\'").Replace("\"", "\"");
                string lname = objUserInfoDTO.LastName == null ? "" : objUserInfoDTO.LastName.Replace("'", "\'").Replace("\"", "\"");
                lst.Add(fname + " " + lname);
                string AlertMessage = Common.Common.getResource("usr_msg_11266", lst);
                TempData.Remove("SearchArray");
                return(RedirectToAction("Index", "UserDetails",
                                        new { acid = Common.ConstEnum.UserActions.CRUSER_COUSER_VIEW }).
                       Success(HttpUtility.UrlEncode(AlertMessage)));
            }
            catch (Exception exp)
            {
                //check if user has selected role and assign those role
                if (objUserInfoModel.SubmittedRole != null)
                {
                    lstSelectedRole = new List <PopulateComboDTO>();
                    for (int cnt = 0; cnt < objUserInfoModel.SubmittedRole.Count; cnt++)
                    {
                        PopulateComboDTO objPopulateComboDTO = new PopulateComboDTO();
                        objPopulateComboDTO.Key = objUserInfoModel.SubmittedRole[cnt];
                        lstSelectedRole.Add(objPopulateComboDTO);
                    }
                }
                ModelState.AddModelError("Warning", Common.Common.GetErrorMessage(exp));
                ViewBag.StatusDropDown       = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.UserStatus).ToString(), null, null, null, null, false);
                ViewBag.CompanyDropDown      = FillComboValues(ConstEnum.ComboType.CompanyList, null, null, null, null, null, true);
                objUserInfoModel.DefaultRole = FillComboValues(ConstEnum.ComboType.RoleList, ConstEnum.Code.COUserType.ToString(), null, null, null, null, true);
                //check if user has selected role and assign those role
                if (lstSelectedRole != null && lstSelectedRole.Count > 0)
                {
                    objUserInfoModel.AssignedRole  = lstSelectedRole;
                    objUserInfoModel.SubmittedRole = null;
                }
                else
                {
                    objUserInfoModel.AssignedRole = FillComboValues(ConstEnum.ComboType.RoleList, ConstEnum.Code.COUserType.ToString(), objUserInfoModel.UserInfoId.ToString(), null, null, null, false);
                }
                ViewBag.UserAction = InsiderTrading.Common.ConstEnum.UserActions.CRUSER_COUSER_EDIT;
                return(View("Create", objUserInfoModel));
            }
            finally
            {
                objLoginUserDetails = null;
                lstSelectedRole     = null;
                objUserInfoSL       = null;
                objUserInfoDTO      = null;
            }
        }
        public ActionResult Create(UserInfoModel objUserInfoModel, string OldPassword, int acid, bool IsConfirmDetails = false)
        {
            int nUserInfoID = 0;
            LoginUserDetails      objLoginUserDetails      = null;
            UserInfoDTO           objUserInfoDTO           = new UserInfoDTO();
            ImplementedCompanyDTO objImplementedCompanyDTO = new ImplementedCompanyDTO();

            bool show_create_role_link       = true;
            bool show_not_login_user_details = true;

            bool show_confirm_personal_details_btn = false;
            bool showMsgConfirmPersonalDetails     = false;

            List <PopulateComboDTO> lstSelectedRole     = null;
            UserInfoModel           objNewUserInfoModel = new UserInfoModel();

            bool   isError         = false; //flag to check for validation error
            string sMsgDOJ         = "";
            string sMsgDOBI        = "";
            string sMsgDateCompare = "";
            string sMsgException   = "";

            UserPolicyDocumentEventLogDTO objUserPolicyDocumentEventLogDTO = null;
            EmployeeModel objEmployeeModel  = new EmployeeModel();
            string        strConfirmMessage = "";

            try
            {
                //check if details being shown for login user then set flag to do not show create role link
                objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);
                if (objUserInfoModel.UserInfoId != 0 && objUserInfoModel.UserInfoId == objLoginUserDetails.LoggedInUserID)
                {
                    show_create_role_link       = false;
                    show_not_login_user_details = false;

                    //check if login user has already confirm personal details - if user has confirm personal details then do not show confirm button
                    if (objUserInfoModel.IsRequiredConfirmPersonalDetails != null && (bool)objUserInfoModel.IsRequiredConfirmPersonalDetails)
                    {
                        show_confirm_personal_details_btn = true;
                        showMsgConfirmPersonalDetails     = true;
                    }
                }
                ViewBag.show_create_role_link       = show_create_role_link;
                ViewBag.show_not_login_user_details = show_not_login_user_details;

                ViewBag.IsShowMsgConfirmDetails           = showMsgConfirmPersonalDetails;
                ViewBag.show_confirm_personal_details_btn = show_confirm_personal_details_btn;

                ViewBag.user_action = acid;

                switch (objLoginUserDetails.UserTypeCodeId)
                {
                case ConstEnum.Code.Admin:
                case ConstEnum.Code.COUserType:
                    if (objUserInfoModel.UserInfoId > 0)
                    {
                        ViewBag.user_action = ConstEnum.UserActions.INSIDER_INSIDERUSER_EDIT;
                    }
                    else
                    {
                        ViewBag.user_action = ConstEnum.UserActions.INSIDER_INSIDERUSER_CREATE;
                    }
                    break;

                case ConstEnum.Code.NonEmployeeType:
                    if (objUserInfoModel.UserInfoId > 0)
                    {
                        ViewBag.user_action = ConstEnum.UserActions.INSIDER_INSIDERUSER_EDIT;
                    }
                    else
                    {
                        ViewBag.user_action = ConstEnum.UserActions.INSIDER_INSIDERUSER_CREATE;
                    }
                    break;
                }

                using (CompaniesSL objCompaniesSL = new CompaniesSL()){
                    objImplementedCompanyDTO = objCompaniesSL.GetDetails(objLoginUserDetails.CompanyDBConnectionString, 0, 1);
                }

                if (objUserInfoModel.DateOfJoining != null || objUserInfoModel.DateOfBecomingInsider != null)
                {
                    DateTime current_date = Common.Common.GetCurrentDate(objLoginUserDetails.CompanyDBConnectionString);

                    if (objUserInfoModel.DateOfJoining > current_date)
                    {
                        sMsgDOJ = Common.Common.getResource("usr_msg_11413"); // "Date of Joining should be less than today's date";
                        isError = true;
                    }

                    if (objUserInfoModel.DateOfBecomingInsider > current_date)
                    {
                        sMsgDOBI = Common.Common.getResource("usr_msg_11414"); // "Date of Becoming Insider should be less than today's date";
                        isError  = true;
                    }

                    if (objUserInfoModel.DateOfBecomingInsider < objUserInfoModel.DateOfJoining)
                    {
                        sMsgDateCompare = Common.Common.getResource("usr_msg_11415"); // "Date of Becoming Insider should not be less than Date of Joining";
                        isError         = true;
                    }
                }

                //check if validation error by checking flag
                if (!isError)
                {
                    if (objUserInfoModel.UserInfoId != 0)
                    {
                        using (UserInfoSL objUserInfoSL = new UserInfoSL())
                        {
                            objUserInfoDTO = objUserInfoSL.GetUserDetails(objLoginUserDetails.CompanyDBConnectionString, objUserInfoModel.UserInfoId);
                        }
                    }

                    InsiderTrading.Common.Common.CopyObjectPropertyByNameAndActivity(objUserInfoModel, objUserInfoDTO);
                    objUserInfoDTO.UserTypeCodeId = ConstEnum.Code.NonEmployeeType;
                    objUserInfoDTO.IsInsider      = ConstEnum.UserType.Insider;
                    objUserInfoDTO.StatusCodeId   = Common.Common.ConvertToInt32(ConstEnum.UserStatus.Active);
                    objUserInfoDTO.LoggedInUserId = objLoginUserDetails.LoggedInUserID;
                    objUserInfoDTO.AllowUpsiUser  = objUserInfoModel.AllowUpsiUser;

                    if (objUserInfoDTO.StateId == 0)
                    {
                        objUserInfoDTO.StateId = null;
                    }
                    if (objUserInfoDTO.CountryId == 0)
                    {
                        objUserInfoDTO.CountryId = null;
                    }

                    objUserInfoDTO.UPSIAccessOfCompanyID = objImplementedCompanyDTO.CompanyId;

                    objUserInfoDTO.Password = "";
                    using (UserInfoSL objUserInfoSL = new UserInfoSL()){
                        objUserInfoDTO = objUserInfoSL.InsertUpdateUserDetails(objLoginUserDetails.CompanyDBConnectionString, objUserInfoDTO);
                    }

                    if (objUserInfoDTO.UserInfoId != 0)
                    {
                        nUserInfoID = objUserInfoDTO.UserInfoId;
                    }

                    //check if need to confirm personal details
                    if (IsConfirmDetails && objUserInfoModel.IsRequiredConfirmPersonalDetails == true)
                    {
                        int UserInfoID       = 0;
                        int RequiredModuleID = 0;
                        try
                        {
                            objUserPolicyDocumentEventLogDTO = new UserPolicyDocumentEventLogDTO();

                            //set values to save into event log table
                            objUserPolicyDocumentEventLogDTO.EventCodeId     = ConstEnum.Code.Event_ConfirmPersonalDetails;
                            objUserPolicyDocumentEventLogDTO.UserInfoId      = objUserInfoDTO.UserInfoId;
                            objUserPolicyDocumentEventLogDTO.MapToId         = objUserInfoDTO.UserInfoId;
                            objUserPolicyDocumentEventLogDTO.MapToTypeCodeId = ConstEnum.Code.UserDocument;
                            UserInfoID = objUserInfoDTO.UserInfoId;

                            InsiderInitialDisclosureDTO objInsiderInitialDisclosureDTO = null;
                            using (var objInsiderInitialDisclosureSL = new InsiderInitialDisclosureSL())
                            {
                                objInsiderInitialDisclosureDTO = objInsiderInitialDisclosureSL.Get_mst_company_details(objLoginUserDetails.CompanyDBConnectionString);
                                if (objInsiderInitialDisclosureDTO.RequiredModule == InsiderTrading.Common.ConstEnum.Code.RequiredModuleOtherSecurity)
                                {
                                    RequiredModuleID = InsiderTrading.Common.ConstEnum.Code.RequiredModuleOtherSecurity;
                                }
                                else
                                {
                                    RequiredModuleID = InsiderTrading.Common.ConstEnum.Code.RequiredModuleOwnSecurity;
                                }
                            }

                            bool isConfirm = false;

                            using (InsiderInitialDisclosureSL objInsiderInitialDisclosureSL = new InsiderInitialDisclosureSL()){
                                isConfirm = objInsiderInitialDisclosureSL.SaveEvent(objLoginUserDetails.CompanyDBConnectionString, objUserPolicyDocumentEventLogDTO, objLoginUserDetails.LoggedInUserID);
                            }

                            if (isConfirm)
                            {
                                strConfirmMessage = Common.Common.getResource("usr_msg_11420"); //Personal Details confirm successfully.
                                //return RedirectToAction("Index", "InsiderInitialDisclosure", new { acid = ConstEnum.UserActions.INSIDER_DISCLOSURE_DETAILS_INITIAL_DISCLOSURE }).Success(HttpUtility.UrlEncode(strConfirmMessage));
                                return(RedirectToAction("Index", "InsiderInitialDisclosure", new { acid = ConstEnum.UserActions.INSIDER_DISCLOSURE_DETAILS_INITIAL_DISCLOSURE, UserInfoId = UserInfoID, ReqModuleId = RequiredModuleID }).Success(HttpUtility.UrlEncode(strConfirmMessage)));
                            }
                        }
                        catch (Exception ex)
                        {
                            strConfirmMessage = Common.Common.getResource(ex.InnerException.Data[0].ToString());
                            throw ex;
                        }
                        finally{
                            objUserPolicyDocumentEventLogDTO = null;
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                sMsgException = Common.Common.getResource(exp.InnerException.Data[0].ToString());
                isError       = true;
                using (CompaniesSL objCompaniesSL = new CompaniesSL()){
                    objImplementedCompanyDTO = objCompaniesSL.GetDetails(objLoginUserDetails.CompanyDBConnectionString, 0, 1);
                }
            }

            //check if there are validation error and show validation error
            if (isError)
            {
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();

                //set validation error messages
                if (sMsgDOJ != "")
                {
                    ModelState.AddModelError("Error", sMsgDOJ);
                }

                if (sMsgDOBI != "")
                {
                    ModelState.AddModelError("Error", sMsgDOBI);
                }

                if (sMsgDateCompare != "")
                {
                    ModelState.AddModelError("Error", sMsgDateCompare);
                }

                if (sMsgException != "")
                {
                    ModelState.AddModelError("Error", sMsgException);
                }

                if (strConfirmMessage != "")
                {
                    ModelState.AddModelError("Error", strConfirmMessage);
                }

                //check if user has selected role and assign those role
                if (objUserInfoModel.SubmittedRole != null)
                {
                    lstSelectedRole = new List <PopulateComboDTO>();
                    for (int cnt = 0; cnt < objUserInfoModel.SubmittedRole.Count; cnt++)
                    {
                        PopulateComboDTO objPopulateComboDTO = new PopulateComboDTO();
                        objPopulateComboDTO.Key = objUserInfoModel.SubmittedRole[cnt];
                        lstSelectedRole.Add(objPopulateComboDTO);
                        objPopulateComboDTO = null;
                    }
                }

                //check if user already saved and set non editable property with already saved valued in DB
                if (objUserInfoModel.UserInfoId != 0)
                {
                    //get saved info from DB
                    UserInfoDTO objExistingDetails_UserInfoDTO = null;
                    using (UserInfoSL objUserInfoSL = new UserInfoSL()){
                        objExistingDetails_UserInfoDTO = objUserInfoSL.GetUserDetails(objLoginUserDetails.CompanyDBConnectionString, objUserInfoModel.UserInfoId);
                    }

                    //copy editable property into DTO so we get existing property and change property
                    Common.Common.CopyObjectPropertyByNameAndActivity(objUserInfoModel, objExistingDetails_UserInfoDTO);

                    //copy DTO to new model which can be pass to view with already saved details with newly change details
                    Common.Common.CopyObjectPropertyByName(objExistingDetails_UserInfoDTO, objNewUserInfoModel);

                    //set user info model to employee model which content edited info and already save info
                    //objUserInfoModel = objNewUserInfoModel;
                }
                else
                {
                    //set user info model to employee model which content edited info and already save info
                    objNewUserInfoModel = objUserInfoModel;
                }

                objNewUserInfoModel.DefaultRole = FillComboValues(ConstEnum.ComboType.RoleList, ConstEnum.Code.NonEmployeeType.ToString(), null, null, null, null, true);

                //check if user has selected role and assign those role
                if (lstSelectedRole != null && lstSelectedRole.Count > 0)
                {
                    objNewUserInfoModel.AssignedRole = lstSelectedRole;
                }
                else
                {
                    objNewUserInfoModel.AssignedRole = FillComboValues(ConstEnum.ComboType.RoleList, ConstEnum.Code.NonEmployeeType.ToString(), nUserInfoID.ToString(), null, null, null, false);
                }
                lstSelectedRole = null;
                PopulateCombo(objImplementedCompanyDTO.CompanyId);
                objEmployeeModel.userInfoModel = objNewUserInfoModel;

                //check if dmat details model is set or not
                if (objEmployeeModel.dmatDetailsModel == null)
                {
                    objEmployeeModel.dmatDetailsModel = new DMATDetailsModel();

                    if (objUserInfoModel.UserInfoId != 0)
                    {
                        objEmployeeModel.dmatDetailsModel.UserInfoID = objEmployeeModel.userInfoModel.UserInfoId;
                    }
                }

                //check if document details are set or not
                if (objEmployeeModel.documentDetailsModel == null)
                {
                    objEmployeeModel.documentDetailsModel = new DocumentDetailsModel();

                    objEmployeeModel.documentDetailsModel.MapToTypeCodeId = ConstEnum.Code.UserDocument;
                    objEmployeeModel.documentDetailsModel.PurposeCodeId   = null;

                    if (objUserInfoModel.UserInfoId != 0)
                    {
                        objEmployeeModel.documentDetailsModel.MapToId = objEmployeeModel.userInfoModel.UserInfoId;
                    }
                }

                return(View("Create", objEmployeeModel));
            }

            ArrayList lst = new ArrayList();

            //before showing success message check if first name and last name is NOT NULL
            string fname = objUserInfoModel.FirstName == null ? "" : objUserInfoModel.FirstName.Replace("'", "\'").Replace("\"", "\"");
            string lname = objUserInfoModel.LastName == null ? "" : objUserInfoModel.LastName.Replace("'", "\'").Replace("\"", "\"");

            lst.Add(fname + " " + lname);
            string AlertMessage = Common.Common.getResource("usr_msg_11266", lst);

            objUserInfoModel = null;
            return(RedirectToAction("Create", new { acid = ConstEnum.UserActions.INSIDER_INSIDERUSER_EDIT, nUserInfoID = nUserInfoID, isPPD_Details_Saved = true }).Success(HttpUtility.UrlEncode(AlertMessage)));
        }
        public ActionResult Create(UserInfoModel objUserInfoModel, string OldPassword)
        {
            int              nUserInfoID         = 0;
            string           Password            = null;
            UserInfoSL       objUserInfoSL       = new UserInfoSL();
            LoginUserDetails objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);
            UserInfoDTO      objUserInfoDTO      = new UserInfoDTO();

            try
            {
                InsiderTrading.Common.Common.CopyObjectPropertyByName(objUserInfoModel, objUserInfoDTO);
                objUserInfoDTO.UserTypeCodeId = ConstEnum.Code.EmployeeType;
                objUserInfoDTO.IsInsider      = ConstEnum.UserType.Insider;
                objUserInfoDTO.StatusCodeId   = Common.Common.ConvertToInt32(ConstEnum.UserStatus.Active);
                objUserInfoDTO.LoggedInUserId = objLoginUserDetails.LoggedInUserID;
                Common.Common.encryptData(objUserInfoModel.Password, out Password);
                if (!Password.Equals(OldPassword))
                {
                    objUserInfoDTO.Password = Password;
                }
                else
                {
                    objUserInfoDTO.Password = OldPassword;
                }
                if (objUserInfoDTO.StateId == 0)
                {
                    objUserInfoDTO.StateId = null;
                }
                if (objUserInfoDTO.CountryId == 0)
                {
                    objUserInfoDTO.CountryId = null;
                }
                if (objUserInfoDTO.Category == 0)
                {
                    objUserInfoDTO.Category = null;
                }
                if (objUserInfoDTO.SubCategory == 0)
                {
                    objUserInfoDTO.SubCategory = null;
                }
                if (objUserInfoDTO.GradeId == 0)
                {
                    objUserInfoDTO.GradeId = null;
                }
                if (objUserInfoDTO.DesignationId == 0)
                {
                    objUserInfoDTO.DesignationId = null;
                }
                if (objUserInfoDTO.DepartmentId == 0)
                {
                    objUserInfoDTO.DepartmentId = null;
                }
                objUserInfoDTO = objUserInfoSL.InsertUpdateUserDetails(objLoginUserDetails.CompanyDBConnectionString, objUserInfoDTO);
                if (objUserInfoDTO.UserInfoId != 0)
                {
                    nUserInfoID = objUserInfoDTO.UserInfoId;
                }
            }
            catch (Exception exp)
            {
                PopulateCombo();
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();
                string sErrMessage = Common.Common.getResource(exp.InnerException.Data[0].ToString());
                ModelState.AddModelError("Error", sErrMessage);
                return(View("Create", objUserInfoModel));
            }
            finally
            {
                objUserInfoSL       = null;
                objLoginUserDetails = null;
                objUserInfoDTO      = null;
            }
            return(RedirectToAction("Create", new { nUserInfoID = nUserInfoID }));
        }