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);
        }
        public ActionResult Create(Community community)
        {
            if (ModelState.IsValid)
            {
                if (this.repos.Communities.Collection.Count(GetCommunityQuery(community.UrlId)) != 0)
                {
                    return View("Error",new HandleErrorInfo(new InvalidOperationException(
                                "There is already community with UrlId \"" + community.UrlId + "\""), "Community", "Create"));
                }

                this.repos.Communities.Insert(community);

                var templateSceneId = this.Request.Form["templateSceneId"];
                if (!string.IsNullOrEmpty(templateSceneId))
                {
                    var template = this.repos.SpecialScenes.First(s => s.SceneId == templateSceneId);
                    this.SaveScene(community.CommunityId, template.Scene);
                }
                return RedirectToAction("Edit", new { id = community.UrlId });
            }

            ViewBag.CityZones = new SelectList(this.repos.Cities.First(c => c.Name == config.City).Zones, community.Zone);
            return View(community);
        }
        public ActionResult Edit(Community community)
        {
            if (ModelState.IsValid)
            {
                community.Ratings = CalculateCommunityRating(community.CommunityId);
                community.Scene = GetSceneHolder(community.CommunityId).Scene;
                this.repos.Communities.Save(community);

                return RedirectToAction("Details", new { id = community.UrlId });
            }
            ViewBag.CityZones = new SelectList(this.repos.Cities.First(c => c.Name == config.City).Zones, community.Zone);
            return View(community);
        }
Exemple #4
0
        public ActionResult Create(Community community)
        {
            if (ModelState.IsValid)
            {
                this.repos.Communities.Insert(community);

                var templateSceneId = this.Request.Form["templateSceneId"];
                if (!string.IsNullOrEmpty(templateSceneId))
                {
                    SceneUtils.ApplyTemplate(this.repos, templateSceneId, community.CommunityId);
                }
                return RedirectToAction("Edit", new { id = community.UrlId });
            }

            ViewBag.CityZones = new SelectList(this.repos.Cities.First(c => c.Name == config.City).Zones, community.Zone);
            return View(community);
        }