Example #1
0
        //Use the below code to add the normal button in cshtml view
        //@Html.OpMgrButton("submitButton", "my button label", new {onclick="alert('abc');", @class="btn btn-primary", id="myId1" })
        public static MvcHtmlString OpMgrButton(this HtmlHelper helper, string name, string label, object htmlAttributes)
        {
            string controlText = helper.TextBox(name, label, htmlAttributes).ToString();

            controlText = controlText.Replace("type=\"text\"", "type=\"button\"");
            if (htmlAttributes != null)
            {
                object objId = GetPropValue(htmlAttributes, "id");
                if (objId != null)
                {
                    string id = objId.ToString();
                    OpMgr.Common.DTOs.SessionDTO session = _sessionSvc.GetUserSession();
                    var disabledControl = session.ActionList.FirstOrDefault(a => string.Equals(a.DisabledControlId, id) && string.Equals(a.ParentAction.ActionLink, System.Web.HttpContext.Current.Request.Path));
                    var hiddenControl   = session.ActionList.FirstOrDefault(a => string.Equals(a.HiddenControlId, id) && string.Equals(a.ParentAction.ActionLink, System.Web.HttpContext.Current.Request.Path));
                    if (hiddenControl != null)
                    {
                        return(new MvcHtmlString(""));
                    }
                    if (disabledControl != null)
                    {
                        var editorField = new TagBuilder("span");
                        editorField.AddCssClass("disabledDiv");
                        editorField.InnerHtml += controlText;

                        return(MvcHtmlString.Create(editorField.ToString()));
                    }
                }
            }
            return(MvcHtmlString.Create(controlText));
        }
Example #2
0
        //public static MvcHtmlString OpMgrActionLinkMultiple(this HtmlHelper htmlHelper, string linkText, string url,  object routeValues, object htmlAttributes)
        //{
        //    if(htmlAttributes!=null)
        //    {
        //        object objId = GetPropValue(htmlAttributes, "name");
        //        if (objId != null)
        //        {
        //            string id = objId.ToString();
        //            OpMgr.Common.DTOs.SessionDTO session = _sessionSvc.GetUserSession();
        //            var disabledControl = session.ActionList.FirstOrDefault(a => string.Equals(a.DisabledControlId, id) && string.Equals(a.ParentAction.ActionLink, System.Web.HttpContext.Current.Request.Path));
        //            var hiddenControl = session.ActionList.FirstOrDefault(a => string.Equals(a.HiddenControlId, id) && string.Equals(a.ParentAction.ActionLink, System.Web.HttpContext.Current.Request.Path));
        //            if (hiddenControl != null)
        //            {
        //                return new MvcHtmlString("");
        //            }
        //            if (disabledControl != null)
        //            {
        //                return htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes);
        //            }
        //        }
        //    }
        //    return htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes);
        //}

        public static MvcHtmlString OpMgrActionLinkMultiple(this HtmlHelper htmlHelper, string linkText, string url, object htmlAttributes)
        {
            if (htmlAttributes != null)
            {
                object objId = GetPropValue(htmlAttributes, "name");
                if (objId != null)
                {
                    string id = objId.ToString();
                    OpMgr.Common.DTOs.SessionDTO session = _sessionSvc.GetUserSession();
                    var disabledControl = session.ActionList.FirstOrDefault(a => string.Equals(a.DisabledControlId, id) && string.Equals(a.ParentAction.ActionLink, System.Web.HttpContext.Current.Request.Path));
                    var hiddenControl   = session.ActionList.FirstOrDefault(a => string.Equals(a.HiddenControlId, id) && string.Equals(a.ParentAction.ActionLink, System.Web.HttpContext.Current.Request.Path));
                    if (hiddenControl != null)
                    {
                        return(new MvcHtmlString(""));
                    }
                    if (disabledControl != null)
                    {
                        IDictionary <string, object> attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
                        if (!attributes.ContainsKey("disabled"))
                        {
                            attributes.Add("disabled", "disabled");
                        }
                        var tag = new TagBuilder("a");
                        if (attributes != null)
                        {
                            tag.MergeAttributes(attributes);
                        }
                        tag.SetInnerText(linkText);
                        tag.MergeAttribute("href", url);
                        return(MvcHtmlString.Create(tag.ToString()));
                    }
                }
            }
            IDictionary <string, object> attributes1 = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
            var tag1 = new TagBuilder("a");

            if (attributes1 != null)
            {
                tag1.MergeAttributes(attributes1);
            }
            tag1.SetInnerText(linkText);
            tag1.MergeAttribute("href", url);
            return(MvcHtmlString.Create(tag1.ToString()));
        }
Example #3
0
 public static MvcHtmlString OpMgrDropDownListFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList, string labelText, object htmlAttributes = null)
 {
     if (htmlAttributes != null)
     {
         object objId = GetPropValue(htmlAttributes, "id");
         if (objId != null)
         {
             string id = objId.ToString();
             OpMgr.Common.DTOs.SessionDTO session = _sessionSvc.GetUserSession();
             var disabledControl = session.ActionList.FirstOrDefault(a => string.Equals(a.DisabledControlId, id) && string.Equals(a.ParentAction.ActionLink, System.Web.HttpContext.Current.Request.Path));
             var hiddenControl   = session.ActionList.FirstOrDefault(a => string.Equals(a.HiddenControlId, id) && string.Equals(a.ParentAction.ActionLink, System.Web.HttpContext.Current.Request.Path));
             if (hiddenControl != null)
             {
                 return(new MvcHtmlString(""));
             }
             if (disabledControl != null)
             {
                 return(FormLine(helper.LabelFor(expression, labelText).ToString(), helper.DropDownListFor(expression, selectList, htmlAttributes).ToString(), true, false));
             }
         }
     }
     return(FormLine(helper.LabelFor(expression, labelText).ToString(), helper.DropDownListFor(expression, selectList, htmlAttributes).ToString(), false, false));
 }
Example #4
0
 public void SetUserSession(OpMgr.Common.DTOs.SessionDTO session)
 {
     System.Web.HttpContext.Current.Session[_sessionIdentifier] = session;
 }