Exemple #1
0
        public ActionResult ManageRoles_Create([DataSourceRequest] DataSourceRequest request, PersonRolesMapping _objPersonRoles)
        {
            if (ModelState.IsValid)
            {
                _objPersonRoles.CreatedBy   = CurrentUser.NameIdentifierInt64;
                _objPersonRoles.CreatedDate = DateTime.Now;
                _objPersonRoles.PersonID    = Convert.ToInt64(Request.QueryString["PersonID"]);
                CRM_EnrolmentHistory EnrolmentHistory = new CRM_EnrolmentHistory();
                EnrolmentHistory.CreatedBy = CurrentUser.NameIdentifierInt64;
                EnrolmentHistory.CreatedOn = DateTime.Now;
                EnrolmentHistory.PersonID  = Convert.ToInt64(Request.QueryString["PersonID"]);
                EnrolmentHistory.RoleName  = "Trainee";
                _objPersonRoles.ClientType = ClientType.ClientType_Internal;
                if (_objPersonRoles.IsLogin == true && _objPersonRoles.Password != null)
                {
                    var person = _PersonBAL.Person_GetAllByIdBAL(Convert.ToString(_objPersonRoles.PersonID));

                    if (_UserBAL.LoginUsers_DuplicationCheckBAL(new LoginUsers {
                        Email = person.Email
                    }) > 0)
                    {
                        ModelState.AddModelError(lr.UsersTitle, lr.UserEmailAlreadyExist);
                        if (_PersonBAL.TMS_PersonRolesMapping_DuplicationCheckBAL(_objPersonRoles) > 0)
                        {
                            ModelState.AddModelError(lr.VenueName, lr.VenueDuplicationCheck);
                        }
                        else
                        {
                            _objPersonRoles.ID = _PersonBAL.TMS_PersonRolesMapping_CreateBAL(_objPersonRoles);
                            _PersonBAL.Enrolment_CreateBAL(EnrolmentHistory);
                            string ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                            if (string.IsNullOrEmpty(ip))
                            {
                                ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                            }
                            _objConfigurationBAL.Audit_CreateBAL(ip, DateTime.Now, CurrentUser.CompanyID, CurrentUser.NameIdentifierInt64, EventType.Create, System.Web.HttpContext.Current.Request.Browser.Browser);
                        }
                    }
                    else
                    {
                        _objPersonRoles.Password = Crypto.CreatePasswordHash(_objPersonRoles.Password);
                        _PersonBAL.TMS_PersonintoUser_CreateBAL(_objPersonRoles);
                        if (_PersonBAL.TMS_PersonRolesMapping_DuplicationCheckBAL(_objPersonRoles) > 0)
                        {
                            ModelState.AddModelError(lr.VenueName, lr.VenueDuplicationCheck);
                        }
                        else
                        {
                            _objPersonRoles.ID = _PersonBAL.TMS_PersonRolesMapping_CreateBAL(_objPersonRoles);
                            _PersonBAL.Enrolment_CreateBAL(EnrolmentHistory);
                        }
                    }
                }
                else
                {
                    if (_PersonBAL.TMS_PersonRolesMapping_DuplicationCheckBAL(_objPersonRoles) > 0)
                    {
                        ModelState.AddModelError(lr.VenueName, lr.VenueDuplicationCheck);
                    }
                    else
                    {
                        _objPersonRoles.ID = _PersonBAL.TMS_PersonRolesMapping_CreateBAL(_objPersonRoles);
                        _PersonBAL.Enrolment_CreateBAL(EnrolmentHistory);
                        string ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                        if (string.IsNullOrEmpty(ip))
                        {
                            ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                        }
                        _objConfigurationBAL.Audit_CreateBAL(ip, DateTime.Now, CurrentUser.CompanyID, CurrentUser.NameIdentifierInt64, EventType.Create, System.Web.HttpContext.Current.Request.Browser.Browser);
                    }
                }
            }
            var resultData = new[] { _objPersonRoles };

            return(Json(resultData.ToDataSourceResult(request, ModelState)));
        }