public ActionResult ArticleAdd(int?articleId, bool?confirmation)
        {
            Article article;

            if (articleId.HasValue)
            {
                ViewBag.EditMode  = true;
                article           = db.Articles.Find(articleId);
                article.Text      = Server.HtmlDecode(article.Text);
                article.IntroText = Server.HtmlDecode(article.IntroText);
            }
            else
            {
                ViewBag.EditMode      = false;
                article               = new Article();
                article.DateOfPublish = DateTime.Now;
            }
            var             tags      = db.ArticlesTags.OrderBy(tn => tn.Name).ToList();
            List <TagCheck> tagsCheck = new List <TagCheck>();

            foreach (var tag in tags)
            {
                var tagCheck = new TagCheck {
                    Tag = tag, Value = false
                };
                tagsCheck.Add(tagCheck);
            }
            var vm = new ArticleAddViewModel()
            {
                Article = article, ArticlesCategories = db.ArticlesCategories, TagsList = db.ArticlesTags.OrderBy(t => t.Name).ToList(), TagsListChecked = tagsCheck
            };

            vm.Confirmation = confirmation;
            return(View("ArticleAdd", vm));
        }
示例#2
0
        public static bool TryGetRoom(int width, int height, FloorGenData genData, TagCheck requiredTag, out PrefabRoom room)
        {
            if (_indexTable.ContainsKey(new Vector2Int(width, height)))
            {
                // there is a room of that size
                foreach (var r in _indexTable[new Vector2Int(width, height)])
                {
                    if (requiredTag[r.Key])
                    {
                        // we found the right tag
                        foreach (var opt in r.Value.AsArray().EnumerateRandom())
                        {
                            if (genData.PlacedRooms.Contains(opt))
                            {
                                continue;
                            }
                            bool valid = true;
                            foreach (var myTag in opt.Tags)
                            {
                                if (genData.ExcludedTags.ContainsKey(myTag))
                                {
                                    valid = false;
                                    break;
                                }
                            }
                            if (!valid)
                            {
                                continue;
                            }
                            foreach (var exTag in opt.ExcludeTags)
                            {
                                if (genData.ExistingTags.ContainsKey(exTag))
                                {
                                    valid = false;
                                    break;
                                }
                            }
                            if (valid)
                            {
                                room = opt;
                                return(true);
                            }
                        }
                    }
                }
            }



            room = null;
            return(false);
        }