public ActionResult Create(UserAccessViewModel objEntity)
        {
            UserAccessRepository objUserAccessRepository = new UserAccessRepository();

            if (ModelState.IsValid)
            {
                objEntity.UserAccessTitle = objEntity.UserAccessTitle.Trim();
                objEntity.Url = objEntity.Url.Trim();
                objEntity.CssClass = objEntity.CssClass.Trim();

                objEntity.CreatedBy = 1;//admin

                objEntity = objUserAccessRepository.Insert(objEntity);

                if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {
                    //   Install-Package MvcFlashMessages
                    this.Flash("Success", "User Access Insert successfully");

                    return RedirectToAction("Index");
                }
                else if (objEntity.Result == ResultFlags.Failure.GetHashCode())
                {
                    this.Flash("Error", "Failed to Insert UserAccess");
                    return RedirectToAction("Index");
                }
                else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode())
                {
                    this.Flash("Warning", "UserAccess Name is Already Exist");
                    return RedirectToAction("Index");
                }
            }
            return View(objEntity);
        }
        public List<UserAccessViewModel> Select(int Flag, UserAccessViewModel objEntity)
        {
            var objEntityList = new List<UserAccessViewModel>();
            try
            {
                Database objDB = base.GetDatabase();
                // Create a suitable command type and add the required parameter.
                using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SPS_USERACCESSVIEWMODELSELECT))
                {
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_FLAG, DbType.Int32, Flag);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_USERACCESS_ID, DbType.Int32, objEntity.UserAccessId);

                    using (IDataReader reader = objDB.ExecuteReader(sprocCmd))
                    {
                        while (reader.Read())
                        {
                            var objEntityViewModel = new UserAccessViewModel();

                            objEntityViewModel.UserAccessId = reader.GetColumnValue<Int16>(COLUMN_NAME_USERACCESS_ID);
                            objEntityViewModel.ParentId = (UserAccessParentIdEnum)reader.GetColumnValue<Int16>(COLUMN_NAME_PARENT_ID);
                            objEntityViewModel.UserAccessTitle = reader.GetColumnValue<String>(COLUMN_NAME_USERACCESS_TITLE);
                            objEntityViewModel.Url = reader.GetColumnValue<String>(COLUMN_NAME_URL);
                            objEntityViewModel.CssClass = reader.GetColumnValue<String>(COLUMN_NAME_CSSCLASS);

                            objEntityViewModel.UserAccessStatus = (StatusEnum)reader.GetColumnValue<Int16>(COLUMN_NAME_USERACCESS_STATUS);

                            objEntityViewModel.SortOrder = reader.GetColumnValue<Int16>(COLUMN_NAME_SORT_ORDER);

                            objEntityViewModel.CreatedDate = reader.GetColumnValue<DateTime>(COLUMN_NAME_CREATED_DATE);
                            objEntityViewModel.CreatedBy = reader.GetColumnValue<Int32>(COLUMN_NAME_CREATED_BY);

                            objEntityViewModel.ModifiedDate = reader.GetColumnValue<DateTime>(COLUMN_NAME_MODIFIED_DATE);
                            objEntityViewModel.ModifiedBy = reader.GetColumnValue<Int32>(COLUMN_NAME_MODIFIED_BY);

                            if (objEntityViewModel != null)
                            {
                                objEntityList.Add(objEntityViewModel);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return objEntityList;
        }
        public ActionResult Edit(int id)
        {
            UserAccessRepository objUserAccessRepository = new UserAccessRepository();

            var objEntity = new UserAccessViewModel();

            objEntity = objUserAccessRepository.Select(RoleFlags.SelectByID.GetHashCode(), new UserAccessViewModel()
            {
                UserAccessId = (Int16)id
            }).FirstOrDefault();
            if (objEntity == null)
            {
                this.Flash("Error", "Failed to edit Role details");

                return RedirectToAction("Index");
            }

            return View(objEntity);
        }
        public UserAccessViewModel Insert(UserAccessViewModel objEntity)
        {
            try
            {
                Database objDB = base.GetDatabase();
                // Create a suitable command type and add the required parameter.
                using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SPS_USERACCESSVIEWMODELINSERT))
                {

                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_PARENT_ID, DbType.Int16, objEntity.ParentId);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_USERACCESS_TITLE, DbType.String, objEntity.UserAccessTitle);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_URL, DbType.String, objEntity.Url);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_CSSCLASS, DbType.String, objEntity.CssClass);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_SORT_ORDER, DbType.Int16, objEntity.SortOrder);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_USERACCESS_STATUS, DbType.Int16, objEntity.UserAccessStatus);

                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_CREATED_BY, DbType.Int32, objEntity.CreatedBy);

                    objDB.AddOutParameter(sprocCmd, COLUMN_NAME_USERACCESS_ID, DbType.Int16, objEntity.UserAccessId);
                    objDB.AddOutParameter(sprocCmd, COLUMN_NAME_RESULT, DbType.Int32, objEntity.Result);

                    objDB.ExecuteNonQuery(sprocCmd);

                    objEntity.UserAccessId = Convert.ToInt16(objDB.GetParameterValue(sprocCmd, COLUMN_NAME_USERACCESS_ID));
                    objEntity.Result = Convert.ToInt32(objDB.GetParameterValue(sprocCmd, COLUMN_NAME_RESULT));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return objEntity;
        }
        public List<UserAccessViewModel> Select(int Flag, Int16 RoleId, UserAccessViewModel objEntity)
        {
            var objEntityList = new List<UserAccessViewModel>();
            try
            {
                Database objDB = base.GetDatabase();
                // Create a suitable command type and add the required parameter.
                using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SPS_USERACCESSVIEWMODELMENUSELECT))
                {
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_FLAG, DbType.Int32, Flag);

                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_ROLE_ID, DbType.Int32, RoleId);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_URL, DbType.String, objEntity.Url);

                    using (IDataReader reader = objDB.ExecuteReader(sprocCmd))
                    {
                        while (reader.Read())
                        {
                            var objEntityViewModel = new UserAccessViewModel();

                            objEntityViewModel.UserAccessId = reader.GetColumnValue<Int16>(COLUMN_NAME_USERACCESS_ID);
                            objEntityViewModel.ParentId = (UserAccessParentIdEnum)reader.GetColumnValue<Int16>(COLUMN_NAME_PARENT_ID);
                            objEntityViewModel.UserAccessTitle = reader.GetColumnValue<String>(COLUMN_NAME_USERACCESS_TITLE);
                            objEntityViewModel.Url = reader.GetColumnValue<String>(COLUMN_NAME_URL);
                            objEntityViewModel.CssClass = reader.GetColumnValue<String>(COLUMN_NAME_CSSCLASS);

                            objEntityViewModel.UserAccessStatus = (StatusEnum)reader.GetColumnValue<Int16>(COLUMN_NAME_USERACCESS_STATUS);

                            objEntityViewModel.SortOrder = reader.GetColumnValue<Int16>(COLUMN_NAME_SORT_ORDER);

                            objEntityViewModel.AddPermission = reader.GetColumnValue<bool>(COLUMN_NAME_ADDPERMISSION);
                            objEntityViewModel.EditPermission = reader.GetColumnValue<Boolean>(COLUMN_NAME_EDITPERMISSION);
                            objEntityViewModel.ViewPermission = reader.GetColumnValue<Boolean>(COLUMN_NAME_VIEWPERMISSION);

                            objEntityViewModel.DeletePermission = reader.GetColumnValue<Boolean>(COLUMN_NAME_DELETEPERMISSION);

                            if (objEntityViewModel != null)
                            {
                                objEntityList.Add(objEntityViewModel);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return objEntityList;
        }
        public ActionResult Edit(int id, UserAccessViewModel objEntity)
        {
            var objUserAccessRepository = new UserAccessRepository();

            if (ModelState.IsValid)
            {
                // objEntity.Name = objEntity.Name.Trim();

                objEntity.UserAccessId = (Int16)id;

                objEntity = objUserAccessRepository.Update(RoleFlags.UpdateByID.GetHashCode(), objEntity);
                if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {
                    this.Flash("success", "UserAccess Details updated successfully");
                    //reload all new setting
                    MenuHelpers.SetMenuByRoleMaster();
                    MenuHelpers.SetMenuByRoleMain();
                    return RedirectToAction("Index");
                }
                else if (objEntity.Result == ResultFlags.Failure.GetHashCode())
                {

                    this.Flash("error", "UserAccess Details failed to Update");
                }

            }

            return View(objEntity);
        }
Example #7
0
        private void CheckRoleUserAccess(ActionExecutingContext filterContext, UserAccessViewModel objUserAccessViewModel, Int16 RoleId)
        {
            var objUserAccessRepository = new UserAccessRepository();
            objUserAccessViewModel = objUserAccessRepository.Select(UserAccessFlags.SelectPermissionByUrlRoleId.GetHashCode(), RoleId,
              objUserAccessViewModel).FirstOrDefault();

            if (objUserAccessViewModel != null)
            {

                switch (ActionAccess)
                {
                    case ActionUserAccessEnum.Default:
                        break;
                    case ActionUserAccessEnum.Index:
                        {

                            if (objUserAccessViewModel.ViewPermission != true && RoleId != RoleUserDefinedEnum.Admin.GetHashCode())
                            {
                                RedirectUnAuthorizedUserLogin(filterContext);
                            }

                            break;
                        }
                    case ActionUserAccessEnum.Details:
                        {
                            if (objUserAccessViewModel.ViewPermission != true && RoleId != RoleUserDefinedEnum.Admin.GetHashCode())
                            {
                                RedirectUnAuthorizedUserLogin(filterContext);
                            }
                            break;
                        }
                    case ActionUserAccessEnum.Create:
                        {
                            if (objUserAccessViewModel.AddPermission != true && RoleId != RoleUserDefinedEnum.Admin.GetHashCode())
                            {
                                RedirectUnAuthorizedUserLogin(filterContext);
                            }
                            break;
                        }
                    case ActionUserAccessEnum.Edit:
                        {
                            if (objUserAccessViewModel.EditPermission != true && RoleId != RoleUserDefinedEnum.Admin.GetHashCode())
                            {
                                RedirectUnAuthorizedUserLogin(filterContext);
                            }
                            break;
                        }
                    case ActionUserAccessEnum.Delete:
                        {
                            if (objUserAccessViewModel.DeletePermission != true && RoleId != RoleUserDefinedEnum.Admin.GetHashCode())
                            {
                                RedirectUnAuthorizedUserLogin(filterContext);
                            }
                            break;
                        }
                    default:
                        break;
                }
            }
            else
            {
                RedirectUnAuthorizedUserLogin(filterContext);
            }
        }