Ejemplo n.º 1
0
        public UserRoleFunction Get(long UserRolesID, long FunctionID)
        {
            UserRoleFunction objUserRoleFunction = new UserRoleFunction();

            UserRole_DL       objUserRole       = new UserRole_DL(Connection);
            SystemFunction_DL objSystemFunction = new SystemFunction_DL(Connection);


            try
            {
                SqlParameter[] paramList = new SqlParameter[] {
                    new SqlParameter("@Original_UserRoleID", UserRolesID),
                    new SqlParameter("@Original_FuncID", FunctionID)
                };

                DataTable dt = Execute.RunSP_DataTable(Connection, "SPADD_Unit", paramList);


                objUserRoleFunction.SystemFunction = objSystemFunction.Get(Convert.ToInt64(dt.Rows[0]["FuncID"]));
                objUserRoleFunction.UserRole       = objUserRole.Get(Convert.ToInt64(dt.Rows[0]["UserRoleID"]));


                return(objUserRoleFunction);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Ejemplo n.º 2
0
        private List <UserRoleFunction> ProcessMappingFromUserRoleGrid(string userRoleFunctionDataParam)
        {
            var userRoleFunctionData = JsonConvert.DeserializeObject <List <UserRoleFunctionGridVo> >(userRoleFunctionDataParam);
            var objResult            = new List <UserRoleFunction>();
            var listUpdate           = userRoleFunctionData;

            if (listUpdate != null && listUpdate.Count != 0)
            {
                foreach (var userRoleFunctionGridVo in listUpdate)
                {
                    var objViewAdd = new UserRoleFunction
                    {
                        DocumentTypeId      = userRoleFunctionGridVo.Id,
                        SecurityOperationId = (int)OperationAction.View,
                        IsDeleted           = !userRoleFunctionGridVo.IsView
                    };
                    objResult.Add(objViewAdd);

                    //Implement View insert
                    var objInsertAdd = new UserRoleFunction
                    {
                        DocumentTypeId      = userRoleFunctionGridVo.Id,
                        SecurityOperationId = (int)OperationAction.Add,
                        IsDeleted           = !userRoleFunctionGridVo.IsInsert
                    };
                    objResult.Add(objInsertAdd);

                    //Implement View update
                    var objUpdateAdd = new UserRoleFunction
                    {
                        DocumentTypeId      = userRoleFunctionGridVo.Id,
                        SecurityOperationId = (int)OperationAction.Update,
                        IsDeleted           = !userRoleFunctionGridVo.IsUpdate
                    };
                    objResult.Add(objUpdateAdd);
                    //Implement View delete
                    var objDeleteAdd = new UserRoleFunction
                    {
                        DocumentTypeId      = userRoleFunctionGridVo.Id,
                        SecurityOperationId = (int)OperationAction.Delete,
                        IsDeleted           = !userRoleFunctionGridVo.IsDelete
                    };
                    objResult.Add(objDeleteAdd);
                    var objProcessAdd = new UserRoleFunction
                    {
                        DocumentTypeId      = userRoleFunctionGridVo.Id,
                        SecurityOperationId = (int)OperationAction.Process,
                        IsDeleted           = !userRoleFunctionGridVo.IsProcess
                    };
                    objResult.Add(objProcessAdd);
                }
            }
            return(objResult);
        }
Ejemplo n.º 3
0
        public int Add(UserRoleFunction obj)
        {
            try
            {
                SqlParameter[] paramList = new SqlParameter[] {
                    new SqlParameter("@UserRoleID", obj.UserRole),
                    new SqlParameter("@FuncID", obj.SystemFunction)
                };

                return(Execute.RunSP_RowsEffected(Connection, "SPADD_UserRoleFunction", paramList));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Ejemplo n.º 4
0
        public ActionResult Create(UserRoleParameter parameters)
        {
            var viewModel      = MapFromClientParameters(parameters);
            var shareViewModel = viewModel.SharedViewModel as DashboardUserRoleShareViewModel;

            if (shareViewModel != null)
            {
                var listRoleFunctionUpdate = shareViewModel.CheckAll ? GetAllRoleFunction() : ProcessMappingFromUserRoleGrid(shareViewModel.UserRoleFunctionData);
                var listRoleFunctionOld    = new List <UserRoleFunction>();
                // Check user have edit some value in list role old => delete role old and add role new
                foreach (var oldItem in listRoleFunctionOld)
                {
                    if (listRoleFunctionUpdate.Any(o => o.DocumentTypeId == oldItem.DocumentTypeId))
                    {
                        oldItem.IsDeleted = true;
                    }
                }
                //after check user removed, remove item of the list new with conditions has property IsDelete equal true;

                //Copy listRoleFunctionUpdate
                var listRoleFunctionUpdateRecheck = listRoleFunctionUpdate.ToList();
                foreach (var item in listRoleFunctionUpdateRecheck.Where(item => item.IsDeleted))
                {
                    listRoleFunctionUpdate.Remove(item);
                }
                var objListFunctionForEntity = new List <UserRoleFunction>();
                // Add listUpdate
                objListFunctionForEntity.AddRange(listRoleFunctionUpdate);
                // Add list data in old
                foreach (var itemOld in listRoleFunctionOld.Where(o => !o.IsDeleted))
                {
                    var objAdd = new UserRoleFunction
                    {
                        DocumentTypeId      = itemOld.DocumentTypeId,
                        SecurityOperationId = itemOld.SecurityOperationId
                    };
                    objListFunctionForEntity.Add(objAdd);
                }
                var entity = shareViewModel.MapTo <UserRole>();
                entity.UserRoleFunctions = objListFunctionForEntity;
                var savedEntity = MasterFileService.Add(entity);
                MenuExtractData.Instance.RefershListData();
                return(Json(new { savedEntity.Id }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { Id = 0 }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public int Update(UserRoleFunction obj, UserRoleFunction OriginalUserRoleFunction)
        {
            try
            {
                SqlParameter[] paramList = new SqlParameter[] {
                    new SqlParameter("@UserRoleID", obj.UserRole),
                    new SqlParameter("@FuncID", obj.SystemFunction),
                    new SqlParameter("@Original_UserRoleID", obj.UserRole),
                    new SqlParameter("@Original_FuncID", obj.UserRole)
                };

                return(Execute.RunSP_RowsEffected(Connection, "SPUPDATE_UserRoleFunction", paramList));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Ejemplo n.º 6
0
        private List <UserRoleFunction> GetAllRoleFunction()
        {
            var objResult           = new List <UserRoleFunction>();
            var objListDocumentType = _userRoleService.GetAllDocumentTypeId();

            foreach (var id in objListDocumentType)
            {
                var objViewAdd = new UserRoleFunction
                {
                    DocumentTypeId      = id,
                    SecurityOperationId = (int)OperationAction.View
                };
                objResult.Add(objViewAdd);
                var objInsertAdd = new UserRoleFunction
                {
                    DocumentTypeId      = id,
                    SecurityOperationId = (int)OperationAction.Add
                };
                objResult.Add(objInsertAdd);
                var objUpdateAdd = new UserRoleFunction
                {
                    DocumentTypeId      = id,
                    SecurityOperationId = (int)OperationAction.Update
                };
                objResult.Add(objUpdateAdd);
                var objDeleteAdd = new UserRoleFunction
                {
                    DocumentTypeId      = id,
                    SecurityOperationId = (int)OperationAction.Delete
                };
                objResult.Add(objDeleteAdd);
                var objProcessAdd = new UserRoleFunction
                {
                    DocumentTypeId      = id,
                    SecurityOperationId = (int)OperationAction.Process
                };
                objResult.Add(objProcessAdd);
            }
            return(objResult);
        }
Ejemplo n.º 7
0
        public int SetupFranchisee(FranchiseeTenant franchiseeTenant, FranchiseeConfiguration franchiseeConfiguration)
        {
            using (var scope = new TransactionScope())
            {
                //Add Franchise
                ValidateBusinessRules(franchiseeTenant);
                _franchiseeTenantRepository.Add(franchiseeTenant);
                _franchiseeTenantRepository.Commit();
                int i = 0;
                var connectionString = PersistenceHelper.GenerateConnectionString(franchiseeTenant.Server,
                                                                                  franchiseeTenant.Database, franchiseeTenant.UserName, franchiseeTenant.Password);
                var database = franchiseeTenant.Database;

                // Create franchisee configuaration
                // Check franchisee configuaration has exists
                #region
                _franchiseeConfigurationRepository.DeleteAllFranchiseeConfigurationBySqlString(database);

                var franchiseeId             = PasswordHelper.HashString(franchiseeTenant.Id.ToString(), franchiseeTenant.Name);
                var licenseKey               = franchiseeTenant.LicenseKey;
                var franchiseeContact        = franchiseeConfiguration.FranchiseeContact;
                var primaryContactPhone      = franchiseeConfiguration.PrimaryContactPhone;
                var primaryContactEmail      = franchiseeConfiguration.PrimaryContactEmail;
                var primaryContactFax        = franchiseeConfiguration.PrimaryContactFax;
                var primaryContactCellNumber = franchiseeConfiguration.PrimaryContactCellNumber;
                var name        = franchiseeConfiguration.Name;
                var city        = franchiseeConfiguration.City;
                var state       = franchiseeConfiguration.State;
                var zip         = franchiseeConfiguration.Zip;
                var address1    = franchiseeConfiguration.Address1;
                var address2    = franchiseeConfiguration.Address2;
                var officePhone = franchiseeConfiguration.OfficePhone;
                var faxNumber   = franchiseeConfiguration.FaxNumber;
                var industryId  = franchiseeConfiguration.IndustryId;
                var logo        = franchiseeConfiguration.Logo;

                var franchiseeconfig = new FranchiseeConfiguration
                {
                    FranchiseeId             = franchiseeId,
                    LicenseKey               = licenseKey,
                    FranchiseeContact        = franchiseeContact,
                    PrimaryContactPhone      = primaryContactPhone,
                    PrimaryContactEmail      = primaryContactEmail,
                    PrimaryContactFax        = primaryContactFax,
                    PrimaryContactCellNumber = primaryContactCellNumber,
                    Name        = name,
                    City        = city,
                    State       = state,
                    Zip         = zip,
                    Address1    = address1,
                    Address2    = address2,
                    OfficePhone = officePhone,
                    FaxNumber   = faxNumber,
                    Logo        = logo,
                    IndustryId  = industryId
                };
                _franchiseeConfigurationRepository.AddFranchiseeConfigurationBySqlString(franchiseeconfig, database);
                #endregion

                // Create a franchisee admin role
                #region

                _userRoleRepository.ChangeConnectionString(connectionString);

                var franchiseeAdminRole   = _userRoleRepository.FirstOrDefault(o => o.AppRoleName == AppRole.GlobalAdmin.ToString());
                var idFranchiseeAdminRole = 0;
                if (franchiseeAdminRole == null)
                {
                    // Create franchisee admin role
                    var franchiseeAdminRoleAdd = new UserRole
                    {
                        Name              = "Franchisee Admin",
                        AppRoleName       = AppRole.GlobalAdmin.ToString(),
                        UserRoleFunctions = new List <UserRoleFunction>()
                    };
                    // Create list userRoleFunction for franchisee admin
                    var objListDocumentType = _userRoleRepository.GetAllDocumentType();
                    foreach (var documentType in objListDocumentType)
                    {
                        var objViewAdd = new UserRoleFunction
                        {
                            DocumentTypeId      = documentType.Id,
                            SecurityOperationId = (int)OperationAction.View
                        };
                        franchiseeAdminRoleAdd.UserRoleFunctions.Add(objViewAdd);

                        //Implement View insert
                        var objInsertAdd = new UserRoleFunction
                        {
                            DocumentTypeId      = documentType.Id,
                            SecurityOperationId = (int)OperationAction.Add,
                        };
                        franchiseeAdminRoleAdd.UserRoleFunctions.Add(objInsertAdd);

                        //Implement View update
                        var objUpdateAdd = new UserRoleFunction
                        {
                            DocumentTypeId      = documentType.Id,
                            SecurityOperationId = (int)OperationAction.Update,
                        };
                        franchiseeAdminRoleAdd.UserRoleFunctions.Add(objUpdateAdd);
                        //Implement View delete
                        var objDeleteAdd = new UserRoleFunction
                        {
                            DocumentTypeId      = documentType.Id,
                            SecurityOperationId = (int)OperationAction.Delete,
                        };
                        franchiseeAdminRoleAdd.UserRoleFunctions.Add(objDeleteAdd);

                        var objProcessAdd = new UserRoleFunction
                        {
                            DocumentTypeId      = documentType.Id,
                            SecurityOperationId = (int)OperationAction.Process,
                        };
                        franchiseeAdminRoleAdd.UserRoleFunctions.Add(objProcessAdd);
                    }
                    _userRoleRepository.Add(franchiseeAdminRoleAdd);
                    _userRoleRepository.Commit();
                    idFranchiseeAdminRole = franchiseeAdminRoleAdd.Id;
                }
                else
                {
                    idFranchiseeAdminRole = franchiseeAdminRole.Id;
                }
                #endregion

                // Create franchisee admin user
                // Check user admin has exists
                #region
                _userRepository.ChangeConnectionString(connectionString);
                var isExistsUserFranchiseeAdmin = _userRepository.CheckExist(o => o.UserRoleId == idFranchiseeAdminRole);
                if (!isExistsUserFranchiseeAdmin)
                {
                    var    randomPassword = "******";
                    string username       = franchiseeTenant.Name.Replace(" ", "");
                    var    password       = PasswordHelper.HashString(randomPassword, username);
                    var    phoneNumber    = franchiseeConfiguration.PrimaryContactPhone;      // "1111111111";
                    var    email          = franchiseeConfiguration.PrimaryContactEmail;      //  "*****@*****.**";
                    var    cellPhone      = franchiseeConfiguration.PrimaryContactCellNumber; // "1111111111";

                    // Create user franchisee admin
                    var userFranchiseeAdmin = new User
                    {
                        UserName    = username,
                        Password    = password,
                        UserRoleId  = idFranchiseeAdminRole,
                        IsActive    = true,
                        FirstName   = "Admin",
                        LastName    = "Franchisee",
                        HomePhone   = phoneNumber,
                        MobilePhone = cellPhone,
                        Email       = email,
                    };
                    _userRepository.AddUserBySqlString(userFranchiseeAdmin, database);
                }
                #endregion
                scope.Complete();
                return(franchiseeTenant.Id);
            }
        }