public ActionResult Edit(int id, WebAuthorityCommands entity)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var old = webAuthorityCommandsRepository.Find(id);
             old.ActionName     = entity.ActionName;
             old.ClassName      = entity.ClassName;
             old.Name           = entity.Name;
             old.Feature        = entity.Feature;
             old.LastModifyTime = DateTime.Now;
             webAuthorityCommandsRepository.Update(old);
             MvcExtensions.ReloadWebAuthorityCommands();
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("", "请认真填写表单!");
             return(View(entity));
         }
     }
     catch (Exception)
     {
         ModelState.AddModelError("", "数据处理出错,请重新提交!");
         return(View(entity));
     }
 }
Esempio n. 2
0
        public async Task <ActionResult> ViewSourcePage(TypeOfSource source, int page)
        {
            ViewBag.MetaItem = await _mModel.SelectById(new MetaItemKey
            {
                Type  = MetaType.Source,
                Value = source.ToString()
            });

            ViewBag.ItemId = MvcExtensions.GetDisplayTextForEnum(source);

            List <Build> builds = await _bModel.SelectSource(source, PAGE_SIZE, (page - 1) *PAGE_SIZE);

            ViewBag.PageNumber = page;
            ViewBag.PageCount  = Math.Ceiling(Convert.ToDouble(await _bModel.SelectSourceCount(source)) / Convert.ToDouble(PAGE_SIZE));

            if (ViewBag.PageNumber > ViewBag.PageCount)
            {
                return(new HttpNotFoundResult());
            }

            return(View("viewSource", builds));
        }
        private void RenderPage(HttpContextBase httpContext, RouteData routeData, string pagePath)
        {
            var location = _pageLocations.Where(p => p.Key == pagePath).Select(p => p.Value).FirstOrDefault();

            if (location == null)
            {
                // If no page is found for this location, rerun LocatePages to pick up any newly
                // added pages.
                lock (_lockObject)
                {
                    this.LocatePages();

                    // Try to find the location once more.
                    location = _pageLocations.Where(p => p.Key == pagePath).Select(p => p.Value).FirstOrDefault();

                    if (location == null)
                    {
                        return;
                    }
                }
            }

            if (!_contentLocators.Any(l => l.PageUrl == pagePath))
            {
                // If no content locator for the page to register exists, render the page to create them.
                lock (_lockObject)
                {
                    if (!_contentLocators.Any(l => l.PageUrl == pagePath))
                    {
                        var viewPath       = "~/" + Web.Helpers.GetVirtualPath(Path.Combine(location, "index.cshtml"));
                        var requestContext = new RequestContext(httpContext, routeData);
                        var controller     = DependencyInjector.Get(typeof(PageController)) as Controller;
                        controller.ControllerContext = new ControllerContext(requestContext, controller);
                        MvcExtensions.RenderViewToString(controller.ControllerContext, viewPath);
                    }
                }
            }
        }
 /// <summary>
 /// 删除按钮
 /// 注意:当按钮已经被分配,则不提供删除
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult Delete(int id)
 {
     try
     {
         var entity = webAuthorityCommandsRepository.Find(id);
         var list   = webManageRoles_WebManageMenus_Authority_RRepository.GetModel().Where(i => (i.Authority & entity.Flag) == entity.Flag);
         if (list == null || list.Count() == 0)
         {
             //删除主表
             webAuthorityCommandsRepository.Delete(entity);
             MvcExtensions.ReloadWebAuthorityCommands();
             return(RedirectToAction("Index"));
         }
         else
         {
             return(Content("<script>alert('本功能按钮【已被使用】,不能进行删除!');location.href='/WebAuthorityCommand/Index';</script>"));
         }
     }
     catch (Exception)
     {
         return(RedirectToAction("Index"));
     }
 }
        public ActionResult Create(WebAuthorityCommands entity)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (webAuthorityCommandsRepository.Find(i => i.Name.ToLower() == entity.Name.ToLower()) != null)
                    {
                        ModelState.AddModelError("", "这个按钮按钮已经在数据库里存在,请重新填写!");
                        return(View(entity));
                    }

                    List <WebAuthorityCommands> list = webAuthorityCommandsRepository.GetModel().ToList();
                    var total = list.BinaryOr(i => i.Flag);
                    var valid = GetValidNumber(total);
                    entity.Flag = valid;
                    if (valid == 0)
                    {
                        valid       = webAuthorityCommandsRepository.GetModel().Max(i => i.Flag);
                        entity.Flag = valid << 1;
                    }
                    webAuthorityCommandsRepository.Insert(entity);
                    MvcExtensions.ReloadWebAuthorityCommands();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "请认真填写表单!");
                    return(View(entity));
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "数据处理出错,请重新提交!");
                return(View(entity));
            }
        }
Esempio n. 6
0
        public async Task <ActionResult> ViewFamilyPage(ProjectFamily family, int page)
        {
            ViewBag.MetaItem = await _mModel.SelectById(new MetaItemKey
            {
                Type  = MetaType.Family,
                Value = family.ToString()
            });

            ViewBag.Item   = family;
            ViewBag.ItemId = MvcExtensions.GetDisplayDescriptionForEnum(family);

            var builds = await _bModel.SelectFamily(family, PAGE_SIZE, (page - 1) *PAGE_SIZE);

            ViewBag.PageNumber = page;
            ViewBag.PageCount  =
                Math.Ceiling(Convert.ToDouble(await _bModel.SelectFamilyCount(family)) / Convert.ToDouble(PAGE_SIZE));

            if (ViewBag.PageNumber > ViewBag.PageCount)
            {
                return(new HttpNotFoundResult());
            }

            return(View("viewFamily", builds));
        }
Esempio n. 7
0
        public async Task <ActionResult> Sitemap()
        {
            var builds = await _bModel.SelectBuildsByOrder();

            var actions = new Dictionary <string, SitemapPagedAction[]>
            {
                {
                    "Pages", new[]
                    {
                        new SitemapPagedAction
                        {
                            UrlParams = new RouteValueDictionary(new
                            {
                                controller = "Front",
                                action     = "Index",
                                page       = 1
                            }),
                            Pages = (builds.Count + (FrontController.PAGE_SIZE - 1)) / FrontController.PAGE_SIZE
                        }
                    }
                },
                {
                    "Versions", (from b in builds
                                 group b by new BuildVersion
                    {
                        Major = b.MajorVersion,
                        Minor = b.MinorVersion
                    }
                                 into bv
                                 orderby bv.Key.Major descending, bv.Key.Minor descending
                                 select new SitemapPagedAction
                    {
                        Name = $"{InvariantTerms.ProductName} {bv.Key.Major}.{bv.Key.Minor}",
                        UrlParams = new RouteValueDictionary(new
                        {
                            controller = "Front",
                            action = "ViewVersion",
                            major = bv.Key.Major,
                            minor = bv.Key.Minor,
                            page = 1
                        }),
                        Pages = (bv.Count() + (FrontController.PAGE_SIZE - 1)) / FrontController.PAGE_SIZE
                    }).ToArray()
                },
                {
                    "Labs", (from b in builds
                             where !string.IsNullOrEmpty(b.Lab)
                             group b by b.Lab
                             into bv
                             orderby bv.Key
                             select new SitemapPagedAction
                    {
                        Name = bv.Key,
                        UrlParams = new RouteValueDictionary(new
                        {
                            controller = "Front",
                            action = "ViewLab",
                            lab = bv.Key,
                            page = 1
                        }),
                        Pages = (bv.Count() + (FrontController.PAGE_SIZE - 1)) / FrontController.PAGE_SIZE
                    }).ToArray()
                },
                {
                    "Years", (from b in builds
                              where b.BuildTime.HasValue
                              group b by b.BuildTime.Value.Year
                              into bv
                              orderby bv.Key descending
                              select new SitemapPagedAction
                    {
                        Name = bv.Key.ToString(),
                        UrlParams = new RouteValueDictionary(new
                        {
                            controller = "Front",
                            action = "ViewYear",
                            year = bv.Key,
                            page = 1
                        }),
                        Pages = (bv.Count() + (FrontController.PAGE_SIZE - 1)) / FrontController.PAGE_SIZE
                    }).ToArray()
                },
                {
                    "Sources", (from b in builds
                                group b by b.SourceType
                                into bv
                                orderby bv.Key
                                select new SitemapPagedAction
                    {
                        Name = MvcExtensions.GetDisplayTextForEnum(bv.Key),
                        UrlParams = new RouteValueDictionary(new
                        {
                            controller = "Front",
                            action = "ViewSource",
                            source = bv.Key,
                            page = 1
                        }),
                        Pages = (bv.Count() + (FrontController.PAGE_SIZE - 1)) / FrontController.PAGE_SIZE
                    }).ToArray()
                }
            };


            var model = new SitemapData
            {
                Builds = (from b in builds
                          group b by new
                {
                    Major = b.MajorVersion,
                    Minor = b.MinorVersion,
                    Build = b.Number,
                    b.Revision
                }
                          into bg
                          orderby bg.Key.Major descending, bg.Key.Minor descending, bg.Key.Build descending, bg.Key.Revision
                          descending
                          select new SitemapDataBuildGroup
                {
                    Id = new BuildGroup
                    {
                        Major = bg.Key.Major,
                        Minor = bg.Key.Minor,
                        Build = bg.Key.Build,
                        Revision = bg.Key.Revision
                    },
                    Builds = (from bgb in bg
                              select new SitemapDataBuild
                    {
                        Id = bgb.Id,
                        Name = bgb.FullBuildString
                    }).ToArray()
                }).ToArray(),
                Actions = actions,
                Labs    = (from b in builds
                           group b by b.Lab
                           into lab
                           select lab.Key).ToArray()
            };

            return(View(model));
        }
Esempio n. 8
0
        public async Task <ActionResult> TwitterCard(Guid id)
        {
            Build b = await _bModel.SelectById(id);

            if (b == null)
            {
                return(new HttpNotFoundResult());
            }

            string path       = Path.Combine(Server.MapPath("~/res/card/"), $"{b.Family}.png");
            bool   backExists = System.IO.File.Exists(path);

            using (Bitmap bm = backExists
                ? new Bitmap(path)
                : new Bitmap(1120, 600))
            {
                using (Graphics gr = Graphics.FromImage(bm))
                {
                    gr.CompositingMode    = CompositingMode.SourceOver;
                    gr.CompositingQuality = CompositingQuality.HighQuality;
                    gr.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    gr.TextRenderingHint  = TextRenderingHint.ClearTypeGridFit;
                    gr.SmoothingMode      = SmoothingMode.HighQuality;
                    gr.PixelOffsetMode    = PixelOffsetMode.HighQuality;

                    if (!backExists)
                    {
                        gr.FillRectangle(new SolidBrush(Color.FromArgb(0x24, 0x24, 0x23)), 0, 0, 1120, 600);
                    }

                    int left = 40;
                    using (GraphicsPath gp = new GraphicsPath())
                    {
                        foreach (char c in "BUILDFEED")
                        {
                            gp.AddString(c.ToString(), new FontFamily("Segoe UI Semibold"), 0, 32, new Point(left, 32), StringFormat.GenericTypographic);

                            RectangleF bounds = gp.GetBounds();
                            left  = Convert.ToInt32(bounds.Width);
                            left += 52;
                        }

                        gr.FillPath(Brushes.White, gp);
                    }

                    using (GraphicsPath gp = new GraphicsPath())
                    {
                        gp.AddString(b.Number.ToString(), new FontFamily("Segoe UI Light"), 0, 260, new Point(32, 114), StringFormat.GenericTypographic);

                        RectangleF bounds = gp.GetBounds();
                        left  = Convert.ToInt32(bounds.Width);
                        left += 44;

                        if (b.Revision.HasValue)
                        {
                            gp.AddString($".{b.Revision}", new FontFamily("Segoe UI Light"), 0, 160, new Point(left, 220), StringFormat.GenericTypographic);
                        }

                        gr.DrawPath(new Pen(new SolidBrush(Color.FromArgb(0x24, 0x24, 0x23)), 4), gp);
                        gr.FillPath(Brushes.White, gp);
                    }

                    using (GraphicsPath gp = new GraphicsPath())
                    {
                        gp.AddString($"{MvcExtensions.GetDisplayTextForEnum(b.Family)} (NT {b.MajorVersion}.{b.MinorVersion})", new FontFamily("Segoe UI Light"), 0, 48, new Point(40, 80), StringFormat.GenericTypographic);

                        gp.AddString(char.ConvertFromUtf32(0xf126), new FontFamily("FontAwesome"), 0, 28, new Point(46, 468), StringFormat.GenericTypographic);
                        gp.AddString(b.Lab, new FontFamily("Segoe UI Light"), 0, 40, new Point(88, 450), StringFormat.GenericTypographic);

                        if (b.BuildTime.HasValue)
                        {
                            gp.AddString(char.ConvertFromUtf32(0xf017), new FontFamily("FontAwesome"), 0, 28, new Point(40, 538), StringFormat.GenericTypographic);
                            gp.AddString($"{b.BuildTime.Value.ToShortTimeString()} on {b.BuildTime.Value.ToLongDateString()}", new FontFamily("Segoe UI Light"), 0, 40, new Point(88, 520), StringFormat.GenericTypographic);
                        }

                        gr.FillPath(Brushes.White, gp);
                    }

                    Response.ContentType = "image/png";
                    bm.Save(Response.OutputStream, ImageFormat.Png);
                }
            }

            return(new EmptyResult());
        }
        /// <summary>
        /// 拦截action
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var returnUrl = MvcExtensions.GetCurrentUrl();

            #region AllowAnonymousAttribute过滤
            //被添加AllowAnonymousAttribute特性的过滤器将不参加AuthorizationLoginFilter的验证
            bool skipAuthorization = filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), inherit: true) ||
                                     filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), inherit: true);
            var    actionType = (((System.Web.Mvc.ReflectedActionDescriptor)(filterContext.ActionDescriptor)).MethodInfo).ReturnType;
            string action     = filterContext.RouteData.Values["action"].ToString();
            string controller = filterContext.RouteData.Values["controller"].ToString();
            var    parentView = filterContext.Controller.ControllerContext.ParentActionViewContext;
            #endregion

            //为登陆页添加例外,其它页都自动在global.asax里添加到全局过滤器中,MVC3及以后版本支持它
            if (!skipAuthorization)
            {
                //验证失败的策略
                Action failAction = () =>
                {
                    if (parentView == null && actionType == typeof(ActionResult))
                    {
                                                                                  //view
                        filterContext.Result = new RedirectToRouteResult("Default", new RouteValueDictionary {
                            { "Action", _failActionName },
                            { "Controller", _failControllerName },
                            { "returnUrl", returnUrl }
                        });
                    }
                    else//PartialView
                    {
                        var indexUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority;
                        if (System.Configuration.ConfigurationManager.AppSettings["UrlHasPort"] == "0")
                        {
                            indexUrl = HttpContext.Current.Request.Url.Scheme
                                       + "://"
                                       + HttpContext.Current.Request.Url.Host;
                        }

                        //防治ajax调用分部视图出现登陆超时,在局部跳转URL的问题
                        filterContext.HttpContext.Response.Write("<script>location.href='"
                                                                 + new UrlHelper(filterContext.RequestContext).Action(_failActionName, _failControllerName, new
                        {
                            returnUrl = indexUrl
                        })
                                                                 + "'</script>");
                        filterContext.HttpContext.Response.End();
                        filterContext.Result = new EmptyResult();//清空当前Action,不执行当前Action代码
                    }
                };

                #region 策略1:app登陆,分发sessionId给客户端,之后每次通讯向服务端发这个id
                var sessionId = filterContext.RequestContext.HttpContext.Request.QueryString["SessionId"];
                if (!string.IsNullOrWhiteSpace(sessionId))
                {
                    if (filterContext.RequestContext.HttpContext.Session.SessionID != sessionId)
                    {
                        failAction();
                    }
                }
                #endregion

                #region 策略2:web登陆,登陆后保存为CurrentUser
                if (!CurrentUser.IsLogin)
                {
                    failAction();
                }
                #endregion
            }
        }
Esempio n. 10
0
 public virtual void Map(MvcExtensions.Model.IDomainDefinition domain, FluentNHibernate.Automapping.AutoPersistenceModel model)
 {
     foreach (var m in Items)
         m.Map(domain, model);
 }
Esempio n. 11
0
        public async Task <IEnumerable <SearchResult> > GetSearchResult(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(new SearchResult[0]);
            }

            const int maxResults = 16;
            var       results    = new List <SearchResult>();

            results.AddRange(from s in (from c in await _bModel.SelectAllSources()
                                        select new
            {
                Text = MvcExtensions.GetDisplayTextForEnum(c),
                Value = c
            })
                             where s.Text.ToLower().Contains(id.ToLower())
                             orderby s.Text.ToLower().IndexOf(id.ToLower(), StringComparison.Ordinal) ascending
                             select new SearchResult
            {
                Url = Url.Route("Source Root",
                                new
                {
                    controller = "Front",
                    action     = "ViewSource",
                    source     = s.Value
                }),
                Label = s.Text.Replace(id, "<strong>" + id + "</strong>"),
                Title = s.Text,
                Group = VariantTerms.Search_Source
            });

            if (results.Count >= maxResults)
            {
                return(results.Take(maxResults));
            }

            results.AddRange(from v in await _bModel.SelectAllVersions()
                             where $"{v.Major}.{v.Minor}".StartsWith(id)
                             orderby v.Major descending, v.Minor descending
                             select new SearchResult
            {
                Url = Url.Route("Version Root",
                                new
                {
                    controller = "Front",
                    action     = "ViewVersion",
                    major      = v.Major,
                    minor      = v.Minor
                }),
                Label = $"{v.Major}.{v.Minor}".Replace(id, "<strong>" + id + "</strong>"),
                Title = "",
                Group = VariantTerms.Search_Version
            });

            if (results.Count >= maxResults)
            {
                return(results.Take(maxResults));
            }

            results.AddRange(from y in await _bModel.SelectAllYears()
                             where y.ToString().Contains(id)
                             orderby y descending
                             select new SearchResult
            {
                Url = Url.Route("Year Root",
                                new
                {
                    controller = "Front",
                    action     = "ViewYear",
                    year       = y
                }),
                Label = y.ToString().Replace(id, "<strong>" + id + "</strong>"),
                Title = "",
                Group = VariantTerms.Search_Year
            });

            if (results.Count >= maxResults)
            {
                return(results.Take(maxResults));
            }

            results.AddRange(from l in await _bModel.SearchLabs(id)
                             select new SearchResult
            {
                Url = Url.Route("Lab Root",
                                new
                {
                    controller = "Front",
                    action     = "ViewLab",
                    lab        = l.Replace('/', '-')
                }),
                Label = l.Replace(id, $"<strong>{id}</strong>"),
                Title = l,
                Group = VariantTerms.Search_Lab
            });

            if (results.Count >= maxResults)
            {
                return(results.Take(maxResults));
            }

            results.AddRange(from b in await _bModel.SelectBuildsByStringSearch(id, maxResults)
                             select new SearchResult
            {
                Url = Url.Route("Build",
                                new
                {
                    controller = "Front",
                    action     = "ViewBuild",
                    id         = b.Id
                }),
                Label = b.FullBuildString.Replace(id, $"<strong>{id}</strong>"),
                Title = b.FullBuildString,
                Group = VariantTerms.Search_Build
            });

            if (results.Count == 0)
            {
                results.Add(new SearchResult
                {
                    Url   = "/",
                    Label = VariantTerms.Search_Empty,
                    Group = ""
                });
            }

            return(results.Take(16));
        }