public CommunityIndexViewModel(ViewModelContext context, IEnumerable<string> zones, IEnumerable<Community> communities)
        {
            var grouped = from zone in zones
                          join community in communities on zone equals community.Zone into groups
                          select new { zone, groups };

            this.Zones = grouped.ToDictionary(
                e => e.zone,
                e => e.groups.OrderBy(c => c.Name).Select(c => new CommunityViewModel(context, c, (c.Ratings == null) ? null : c.Ratings.Values.Average())).ToList() as IEnumerable<CommunityViewModel>);
        }
Пример #2
0
 public static SceneViewModel ToViewModel(this Scene scene, ViewModelContext context)
 {
     return new SceneViewModel
     {
         Walls = scene.Walls.Select(wall => new WallViewModel
         {
             Title = wall.Title,
             Width = wall.Width,
             Bricks = wall.Bricks.Select(brick => BrickViewModel<Brick>.Create(context, brick))
         })
     };
 }
Пример #3
0
        public CommunityViewModel(ViewModelContext context, Community community, double? rating)
        {
            this.DeleteUrl = context.UrlHelper.Action("Delete", "Community", new { id = community.UrlId });
            this.DetailsUrl = context.UrlHelper.Action("Details", "Community", new { id = community.UrlId });
            this.Name = community.Name;
            this.UrlId = community.UrlId;
            this.GpsBounds = community.GpsBounds;
            this.GpsLocation = community.GpsLocation;

            this.Properties = FilterProperty.Get(typeof(Community))
                .ToDictionary(
                    p => p.Property.Name,
                    p => p.Property.GetValue(community, null)
                );

            this.PopupHtml = "<div><a href='{1}'>{2}</a></div><div>{0}</div>{3}".FormatWith(
                context.Config.Review.RatingEnabled
                    ? context.HtmlHelper.RatingStars(rating)
                    : MvcHtmlString.Empty,
                this.DetailsUrl, this.Name, community.ShortDescription);
        }
Пример #4
0
 public ReviewViewModel(ViewModelContext context, string targetId)
 {
     this.context = context;
     this.TargetId = targetId;
     this.RatingEnabled = context.Config.Review.RatingEnabled;
 }