コード例 #1
0
        public ActionResult Create(TopicModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                if (!model.IsPasswordProtected)
                {
                    model.Password = null;
                }

                var topic = model.ToEntity();
                _topicService.InsertTopic(topic);
                //locales
                UpdateLocales(topic, model);

                NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.Topics.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = topic.Id }) : RedirectToAction("List");
            }

            // If we got this far, something failed, redisplay form
            PrepareStoresMappingModel(model, null, true);

            return View(model);
        }
コード例 #2
0
ファイル: TopicController.cs プロジェクト: cmcginn/StoreFront
        public ActionResult Create(TopicModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            //decode description
            model.Body = HttpUtility.HtmlDecode(model.Body);
            foreach (var localized in model.Locales)
                localized.Body = HttpUtility.HtmlDecode(localized.Body);

            if (ModelState.IsValid)
            {
                if (!model.IsPasswordProtected)
                {
                    model.Password = null;
                }

                var topic = model.ToEntity();
                _topicService.InsertTopic(topic);
                //locales
                UpdateLocales(topic, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Topics.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = topic.Id }) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #3
0
        public void UpdateLocales(Topic topic, TopicModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(topic,
                                                               x => x.Title,
                                                               localized.Title,
                                                               localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.Body,
                                                           localized.Body,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.MetaKeywords,
                                                           localized.MetaKeywords,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.MetaDescription,
                                                           localized.MetaDescription,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.MetaTitle,
                                                           localized.MetaTitle,
                                                           localized.LanguageId);
            }
        }
コード例 #4
0
        protected void UpdateLocales(Topic topic, TopicModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(topic,
                                                               x => x.Title,
                                                               localized.Title,
                                                               localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.Body,
                                                           localized.Body,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.MetaKeywords,
                                                           localized.MetaKeywords,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.MetaDescription,
                                                           localized.MetaDescription,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.MetaTitle,
                                                           localized.MetaTitle,
                                                           localized.LanguageId);

                //search engine name
                var seName = topic.ValidateSeName(localized.SeName, localized.Title, false);
                _urlRecordService.SaveSlug(topic, seName, localized.LanguageId);
            }
        }
コード例 #5
0
        public ActionResult Create(TopicModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                if (!model.IsPasswordProtected)
                {
                    model.Password = null;
                }

                var topic = new Topic()
                {
                    Body = model.Body,
                    IncludeInSitemap = model.IncludeInSitemap,
                    IsPasswordProtected = model.IsPasswordProtected,
                    MetaDescription = model.MetaDescription,
                    MetaKeywords = model.MetaKeywords,
                    MetaTitle = model.MetaTitle,
                    Password = model.Password,
                    SystemName = model.SystemName,
                    Title = model.Title
                };
                _topicService.InsertTopic(topic);
                //locales
                UpdateLocales(topic, model);

                SuccessNotification("Chủ đề đã được tạo.");
                return continueEditing ? RedirectToAction("Edit", new { id = topic.Id }) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #6
0
        public ActionResult Create(TopicModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                if (!model.IsPasswordProtected)
                {
                    model.Password = null;
                }

                var topic = model.ToEntity();
                _topicService.InsertTopic(topic);
                //search engine name
                model.SeName = topic.ValidateSeName(model.SeName, topic.Title ?? topic.SystemName, true);
                _urlRecordService.SaveSlug(topic, model.SeName, 0);
                //Stores
                SaveStoreMappings(topic, model);
                //locales
                UpdateLocales(topic, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Topics.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = topic.Id }) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form

            //templates
            PrepareTemplatesModel(model);
            //Stores
            PrepareStoresMappingModel(model, null, true);
            return View(model);
        }
コード例 #7
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            var model = new TopicModel();
            //locales
            AddLocales(_languageService, model.Locales);
            return View(model);
        }
コード例 #8
0
        protected virtual void PrepareTemplatesModel(TopicModel model)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            var templates = _topicTemplateService.GetAllTopicTemplates();
            foreach (var template in templates)
            {
                model.AvailableTopicTemplates.Add(new SelectListItem
                {
                    Text = template.Name,
                    Value = template.Id.ToString()
                });
            }
        }
コード例 #9
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            var model = new TopicModel();
            //Stores
            PrepareStoresMappingModel(model, null, false);
            //locales
            AddLocales(_languageService, model.Locales);

            model.TitleTag = "h1";

            return View(model);
        }
        public ActionResult AddTopic(string content)
        {
            // TODO: validate received data from form

            if (content.Length > 3)
            {
                TopicModel topic = new TopicModel()
                {
                    Content = content,
                    IsActive = true,
                };

                db.Topics.Add(topic);
                db.SaveChanges();
            }

            return PartialView("_TopicsList", db.Topics.ToList());
        }
コード例 #11
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            var model = new TopicModel();
            //templates
            PrepareTemplatesModel(model);
            //Stores
            PrepareStoresMappingModel(model, null, false);
            //locales
            AddLocales(_languageService, model.Locales);

            //default values
            model.DisplayOrder = 1;

            return View(model);
        }
コード例 #12
0
        public async Task <IActionResult> Create()
        {
            var model = new TopicModel();
            //templates
            await _topicViewModelService.PrepareTemplatesModel(model);

            //Stores
            await model.PrepareStoresMappingModel(null, _storeService, false);

            //locales
            await AddLocales(_languageService, model.Locales);

            //ACL
            await model.PrepareACLModel(null, false, _customerService);

            //default values
            model.DisplayOrder = 1;

            return(View(model));
        }
コード例 #13
0
        public bool CanComment(TopicModel topic)
        {
            if (topic == null || topic.Status != Enums.TopicStatus.Published || !topic.AllowComment)
            {
                return(false);
            }
            if (!this.Settings.AllowComment)
            {
                return(false);
            }
            if (this.Settings.CloseCommentDays > 0)
            {
                if (topic.Date.AddDays(this.Settings.CloseCommentDays) < DateTime.Now)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #14
0
        public IActionResult Edit(int id)
        {
            // Page available only to administrators
            if (!HttpContext.Session.GetIsAdmin())
            {
                return(NotFound());
            }

            // topic from DB
            var data = manager.GetTopic(id);

            TopicModel model = new TopicModel();

            model.Topics = manager.GetAllTopics();
            // fill in model with a data from DB
            model.Title = data.Title;
            model.Id    = data.Id;

            return(View(model));
        }
コード例 #15
0
        private async void GetTopic()
        {
            try
            {
                pr_Load.Visibility = Visibility.Visible;
                WebClientClass wc      = new WebClientClass();
                string         results = await wc.GetResults(new Uri("http://www.bilibili.com/index/slideshow.json"));

                TopicModel model = JsonConvert.DeserializeObject <TopicModel>(results);
                list_Topic.ItemsSource = JsonConvert.DeserializeObject <List <TopicModel> >(model.list.ToString());
            }
            catch (Exception ex)
            {
                messShow.Show("读取话题失败\r\n" + ex.Message, 3000);
            }
            finally
            {
                pr_Load.Visibility = Visibility.Collapsed;
            }
        }
コード例 #16
0
        //topic
        public static TopicModel ToModel(this Topic entity, Language language)
        {
            var model = new TopicModel {
                Id                  = entity.Id,
                SystemName          = entity.SystemName,
                IncludeInSitemap    = entity.IncludeInSitemap,
                IsPasswordProtected = entity.IsPasswordProtected,
                Password            = entity.Password,
                Title               = entity.IsPasswordProtected ? "" : entity.GetLocalized(x => x.Title, language.Id),
                Body                = entity.IsPasswordProtected ? "" : entity.GetLocalized(x => x.Body, language.Id),
                MetaKeywords        = entity.GetLocalized(x => x.MetaKeywords, language.Id),
                MetaDescription     = entity.GetLocalized(x => x.MetaDescription, language.Id),
                MetaTitle           = entity.GetLocalized(x => x.MetaTitle, language.Id),
                SeName              = entity.GetSeName(language.Id),
                TopicTemplateId     = entity.TopicTemplateId,
                Published           = entity.Published
            };

            return(model);
        }
コード例 #17
0
ファイル: TopicController.cs プロジェクト: Shikyoh/HSWB2B2C
        public ActionResult Add(long?id)
        {
            if (!id.HasValue)
            {
                return(View(new TopicModel()));
            }
            TopicInfo  topicInfo  = ServiceHelper.Create <ITopicService>().GetTopicInfo(id.Value);
            TopicModel topicModel = new TopicModel()
            {
                BackgroundImage = topicInfo.BackgroundImage,
                Id              = topicInfo.Id,
                Name            = topicInfo.Name,
                TopImage        = topicInfo.TopImage,
                TopicModuleInfo = topicInfo.TopicModuleInfo,
                IsRecommend     = topicInfo.IsRecommend,
                SelfDefineText  = topicInfo.SelfDefineText
            };

            return(View(topicModel));
        }
コード例 #18
0
        /// <summary>
        /// Methode which define number of elements that are displayed on the page.
        /// </summary>
        /// <param name="modelView"> Current model</param>
        /// <param name="pageNumber"> Current number of page</param>
        private PageSetup DefinePageSetup(TopicModel modelView, int pageNumber)
        {
            if (User.Identity.IsAuthenticated)
            {
                var currentUser = UserManager.FindById(User.Identity.GetUserId());

                return(currentUser.PageSetup);
            }

            else
            {
                var pageSetup = new PageSetup
                {
                    PageNumber = pageNumber,
                    TotalItems = modelView.Periodicals.Count()
                };

                return(pageSetup);
            }
        }
コード例 #19
0
        private void btnAddRelationship_Click(object sender, EventArgs e)
        {
            var topicsList = new TopicModel().GetSelectedIds(lbTopicsList);
            var examsList  = new ExamModel().GetSelectedIds(lbExamList);

            if (ValidateData(topicsList.Count, examsList.Count))
            {
                foreach (var topicId in topicsList)
                {
                    new ExamRelationModel().Save(topicId, examsList);
                }

                ApplicationSettingData.Setting.Helper.ShowMessage("Done.", DialogTitles.Info);
                ResetData();
            }
            else
            {
                ApplicationSettingData.Setting.Helper.ShowMessage("Please select Subject/ Topic/ Exam(s).", DialogTitles.Error);
            }
        }
コード例 #20
0
        protected virtual TopicModel PrepareTopicModel(Topic topic)
        {
            if (topic == null)
            {
                throw new ArgumentNullException("topic");
            }

            var model = new TopicModel
            {
                Id              = topic.Id,
                SystemName      = topic.SystemName,
                Title           = topic.Title,
                Body            = topic.Body,
                MetaKeywords    = topic.MetaKeywords,
                MetaTitle       = topic.MetaTitle,
                MetaDescription = topic.MetaDescription
            };

            return(model);
        }
コード例 #21
0
        private static void DraftTopic(string topic, string path)
        {
            string     pathToFolder = Path.Combine(path, "default", "projects");
            TopicModel topicModel   = JsonConvert.DeserializeObject <TopicModel>(File.ReadAllText(topic));

            topicModel.localization = "default";
            string vmbFile = topicModel.vmpPath.Replace(".vmp", ".vmb");

            if (File.Exists(vmbFile))
            {
                string unzipFolder = Path.Combine(pathToFolder, topicModel.name.Replace(" ", "_"));
                if (Directory.Exists(unzipFolder))
                {
                    foreach (string f in Directory.GetFiles(unzipFolder))
                    {
                        File.Delete(f);
                    }
                }

                if (!string.IsNullOrEmpty(topicModel.pathToZip) && File.Exists(topicModel.pathToZip))
                {
                    topicModel.pathToZip = topicModel.pathToZip.Replace("data\\", UsersHelper.GetToolsFolder() + "\\");
                    topicModel.pathToZip = topicModel.pathToZip.Replace("data/", UsersHelper.GetToolsFolder() + "/");
                    string toolsDir = PathHelper.GetUserProcessingFolder();
                    string pathOne  = Path.Combine(toolsDir, "input/resourceFolder").Replace("\\", "/");
                    string pathTwo  = Path.Combine(toolsDir, "input").Replace("\\", "/");
                    File.Copy(topicModel.pathToZip, Path.Combine(pathOne, Path.GetFileName(topicModel.pathToZip)).Replace("\\", "/"), true);
                    File.Copy(topicModel.pathToZip, Path.Combine(pathTwo, Path.GetFileName(topicModel.pathToZip)).Replace("\\", "/"), true);
                }

                Unzip(vmbFile, unzipFolder);
                ConvertToX3D(unzipFolder, Path.Combine(path, "default", "pub_draft"), topicModel.name + new Random().Next(1000, 9999), topicModel.type == "info", topicModel);
            }

            if (!string.IsNullOrEmpty(topicModel.pathToZip) && File.Exists(topicModel.pathToZip))
            {
                string fileCopy = topicModel.pathToZip.Replace("pub_in", "pub_draft");
                File.Copy(topicModel.pathToZip, fileCopy, true);
                SVNManager.AddFile(fileCopy.Replace(Path.Combine(UsersHelper.GetUserFolder(), UsersHelper.GetToolsFolder()) + "/", ""));
            }
        }
コード例 #22
0
        public static void ChangeVmpPath(string root, string oldName, string newName)
        {
            foreach (string folder in Directory.GetDirectories(root))
            {
                string folderName = new DirectoryInfo(folder).Name;
                string newPath    = Path.Combine(root, folderName);
                if (folderName == "topics")
                {
                    foreach (string f in Directory.GetFiles(newPath))
                    {
                        TopicModel topic = JsonConvert.DeserializeObject <TopicModel>(File.ReadAllText(f));

                        if (string.IsNullOrEmpty(topic.vmpPath) && !string.IsNullOrEmpty(topic.vmpPathDEFAULT))
                        {
                            topic.vmpPath = topic.vmpPathDEFAULT;
                        }

                        if (string.IsNullOrEmpty(topic.pathToZip) && !string.IsNullOrEmpty(topic.pathToZipDEFAULT))
                        {
                            topic.pathToZip = topic.pathToZipDEFAULT;
                        }

                        if (!string.IsNullOrEmpty(topic.vmpPath))
                        {
                            topic.vmpPath        = topic.vmpPath.Replace(oldName, newName);
                            topic.vmpPathDEFAULT = topic.vmpPath;
                        }
                        if (!string.IsNullOrEmpty(topic.pathToZip))
                        {
                            topic.pathToZip        = topic.pathToZip.Replace(oldName, newName);
                            topic.pathToZipDEFAULT = topic.pathToZip;
                        }
                        File.WriteAllText(f, JsonConvert.SerializeObject(topic));
                    }
                }
                else
                {
                    ChangeVmpPath(newPath, oldName, newName);
                }
            }
        }
コード例 #23
0
        public async Task <IActionResult> Create(TopicModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                if (!model.IsPasswordProtected)
                {
                    model.Password = null;
                }

                var topic = await MapperFactory.MapAsync <TopicModel, Topic>(model);

                if (model.WidgetZone != null)
                {
                    topic.WidgetZone = string.Join(',', model.WidgetZone);
                }

                topic.CookieType = (CookieType?)model.CookieType;

                _db.Topics.Add(topic);
                await _db.SaveChangesAsync();

                var slugResult = await topic.ValidateSlugAsync(model.SeName, true);

                model.SeName = slugResult.Slug;
                await _urlService.ApplySlugAsync(slugResult, true);

                await SaveStoreMappingsAsync(topic, model.SelectedStoreIds);
                await SaveAclMappingsAsync(topic, model.SelectedCustomerRoleIds);
                await UpdateLocalesAsync(topic, model);

                AddCookieTypes(model, model.CookieType);

                await Services.EventPublisher.PublishAsync(new ModelBoundEvent(model, topic, Request.Form));

                NotifySuccess(T("Admin.ContentManagement.Topics.Updated"));
                return(continueEditing ? RedirectToAction("Edit", new { id = topic.Id }) : RedirectToAction("List"));
            }

            // If we got this far something failed. Redisplay form.
            return(View(model));
        }
コード例 #24
0
        public List <TopicModel> GetAllActiveTopicsByLessonId(long id)
        {
            var list = _context.Topics.Where(x => x.IsActive && x.Lesson_Id == id).ToList();
            var ans  = new List <TopicModel>();

            foreach (var temp in list)
            {
                var t = new TopicModel();
                t.IsActive      = temp.IsActive;
                t.Description   = temp.Description;
                t.Id            = temp.Id;
                t.LessonId      = temp.Lesson_Id;
                t.LesoonName    = temp.Lesson.Name;
                t.Name          = temp.Name;
                t.Price         = temp.Price;
                t.QuestionPrice = temp.QuestionPrice;
                t.TextPrice     = temp.TextPrice;
                ans.Add(t);
            }
            return(ans);
        }
コード例 #25
0
        public async Task <IActionResult> RandomSingleTopic()
        {
            Dictionary <int, int> ids = new();
            int counter = 0;

            foreach (TopicModel topic in await _db.Topics.ToListAsync())
            {
                ids.Add(++counter, topic.Id);
            }

            Random Random = new();

            int Index   = Random.Next(1, counter + 1);
            int TopicId = ids[Index];

            TopicModel t = await _db.Topics.FirstOrDefaultAsync(o => o.Id == TopicId);

            HttpContext.Session.SetInt32("fid", (int)t.ForumId);

            return(RedirectToAction("OpenTopic", "SingleForum", new { TopicId = t.Id }));
        }
コード例 #26
0
        public ActionResult Edit(TopicModel model)
        {
            if (model.UploadImage != null && ModelState.IsValid)
            {
                string filePath = System.IO.Path.GetFileName(model.UploadImage.FileName);

                model.UploadImage.SaveAs(Server.MapPath("~/Images/Topics/" + filePath));
                model.ImageName = filePath;
            }

            else
            {
                return(View(model));
            }

            var modelBL = _mapper.Map <TopicBL>(model);

            _service.Update(modelBL);

            return(RedirectToAction("Index"));
        }
コード例 #27
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
            {
                return(AccessDeniedView());
            }

            var model = new TopicModel();

            //templates
            PrepareTemplatesModel(model);
            //ACL
            PrepareAclModel(model, null, false);
            //locales
            AddLocales(_languageService, model.Locales);

            //default values
            model.DisplayOrder = 1;

            return(View(model));
        }
コード例 #28
0
ファイル: TopicController.cs プロジェクト: yuyu2you/Caf.CMS
        protected void PrepareTopicModel(TopicModel model, Topic topic)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            #region templates

            var templates      = _modelTemplateService.GetAllModelTemplates();
            var singleTemplate = templates.Where(p => p.TemplageTypeId == (int)TemplateTypeFormat.SinglePage).ToList();
            foreach (var template in singleTemplate)
            {
                model.AvailableTopicTemplates.Add(new SelectListItem()
                {
                    Text  = template.Name,
                    Value = template.Id.ToString()
                });
            }

            #endregion
        }
コード例 #29
0
        public async Task <IActionResult> Post([FromBody] TopicModel model)
        {
            var logger = new LoggerConfiguration()
                         .WriteTo.Sentry(_configuration.GetConnectionString("SENTRY"))
                         .WriteTo.Console()
                         .Enrich.FromLogContext()
                         .CreateLogger();

            try
            {
                logger.Information("Запрос на добавление темы");
                await _topicService.AddTopic(model.ToEntity());

                return(StatusCode(StatusCodes.Status201Created));
            }
            catch (Exception e)
            {
                logger.Error(e, "Произошла ошибка");
                return(StatusCode(StatusCodes.Status500InternalServerError, "Произошла ошибка, обратитесь в службу поддержки!"));
            }
        }
コード例 #30
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id != null)
            {
                TopicModel model = await _db.Topics
                                   .Include(r => r.Replies)
                                   .Include(r => (r.Replies as ReplyModel).Pictures)
                                   .Include(p => p.Pictures)
                                   .FirstOrDefaultAsync(p => p.Id == id);

                if (model != null)
                {
                    _db.DeleteTopic(model);

                    await _db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            return(NotFound());
        }
コード例 #31
0
        public virtual Topic InsertTopicModel(TopicModel model)
        {
            if (!model.IsPasswordProtected)
            {
                model.Password = null;
            }

            var topic = model.ToEntity();

            _topicService.InsertTopic(topic);
            //search engine name
            model.SeName  = topic.ValidateSeName(model.SeName, topic.Title ?? topic.SystemName, true);
            topic.Locales = model.Locales.ToLocalizedProperty(topic, x => x.Title, _urlRecordService);
            topic.SeName  = model.SeName;
            _topicService.UpdateTopic(topic);
            _urlRecordService.SaveSlug(topic, model.SeName, "");

            //activity log
            _customerActivityService.InsertActivity("AddNewTopic", topic.Id, _localizationService.GetResource("ActivityLog.AddNewTopic"), topic.Title ?? topic.SystemName);
            return(topic);
        }
コード例 #32
0
        public ActionResult Edit(int id)
        {
            var Object = new TopicModel().GetTopicById(id);
            var Result = new TopicView();

            Result.Name          = Object.Name;
            Result.Code          = Object.Code;
            Result.ImageId       = Object.ImageId;
            Result.Descrip       = Object.Descrip;
            Result.OrderDisplay  = Object.OrderDisplay;
            Result.TopicParentID = new TopicModel().GetNameById(Object.TopicParentID);
            if (Object.LangId == 0)
            {
                Result.LangId = "Tiếng Việt";
            }
            else
            {
                Result.LangId = "Tiếng Anh";
            }
            return(View(Result));
        }
コード例 #33
0
        public async Task <IActionResult> Delete(TopicModel model)
        {
            var topic = await _db.Topics.FindByIdAsync(model.Id);

            if (topic == null)
            {
                return(RedirectToAction(nameof(List)));
            }

            if (topic.IsSystemTopic)
            {
                NotifyError(T("Admin.ContentManagement.Topics.CannotBeDeleted"));
                return(RedirectToAction(nameof(Edit), new { id = topic.Id }));
            }

            _db.Topics.Remove(topic);
            await _db.SaveChangesAsync();

            NotifySuccess(T("Admin.ContentManagement.Topics.Deleted"));
            return(RedirectToAction(nameof(List)));
        }
コード例 #34
0
		private void PrepareStoresMappingModel(TopicModel model, Topic topic, bool excludeProperties)
		{
			if (model == null)
				throw new ArgumentNullException("model");

			model.AvailableStores = _storeService
				.GetAllStores()
				.Select(s => s.ToModel())
				.ToList();
			if (!excludeProperties)
			{
				if (topic != null)
				{
					model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(topic);
				}
				else
				{
					model.SelectedStoreIds = new int[0];
				}
			}
		}
コード例 #35
0
        public ActionResult EditOfTopic(TopicModel topic, HttpPostedFileBase photo = null)
        {
            if (topic == null)
            {
                return(HttpNotFound());
            }

            if (photo != null)
            {
                topic.PathForMainPhoto = Upload(photo);
            }

            Mapper.Initialize(configuration => configuration.CreateMap <TopicModel, TopicDTO>());
            var topicDTOForEdit = Mapper.Map <TopicModel, TopicDTO>(topic);

            topicService.UpdateElement(topicDTOForEdit);

            logger.Info("The topic (ID: " + topic.Header + ") has been changed.");

            return(RedirectToAction("GetAllTopics"));
        }
コード例 #36
0
 public TopicModel getTopic(int id)
 {
     try
     {
         var o   = _topicRepo.GetById(id);
         var res = new TopicModel
         {
             Id          = o.Id,
             dateAdded   = o.dateAdded,
             user_code   = o.user_code,
             topic_name  = o.topic_name,
             desc        = o.desc,
             enabled_flg = o.enabled_flg
         };
         return(res);
     }
     catch (System.Exception)
     {
         return(null);
     }
 }
コード例 #37
0
ファイル: TopicController.cs プロジェクト: krreddy123/appcode
 private void AddCookieTypes(TopicModel model, int?selectedType = 0)
 {
     model.AvailableCookieTypes.Add(new SelectListItem()
     {
         Text     = "Required",
         Value    = ((int)CookieType.Required).ToString(),
         Selected = CookieType.Required == (CookieType?)selectedType
     });
     model.AvailableCookieTypes.Add(new SelectListItem()
     {
         Text     = "Analytics",
         Value    = ((int)CookieType.Analytics).ToString(),
         Selected = CookieType.Analytics == (CookieType?)selectedType
     });
     model.AvailableCookieTypes.Add(new SelectListItem()
     {
         Text     = "ThirdParty",
         Value    = ((int)CookieType.ThirdParty).ToString(),
         Selected = CookieType.ThirdParty == (CookieType?)selectedType
     });
 }
コード例 #38
0
        public ActionResult Edit(int topicId = -1)
        {
            TopicInfo topicInfo = AdminTopic.AdminGetTopicById(topicId);

            if (topicInfo == null)
            {
                return(PromptView("活动专题不存在"));
            }

            TopicModel model = new TopicModel();

            model.StartTime = topicInfo.StartTime;
            model.EndTime   = topicInfo.EndTime;
            model.Title     = topicInfo.Title;
            model.HeadHtml  = topicInfo.HeadHtml;
            model.BodyHtml  = topicInfo.BodyHtml;
            model.IsShow    = topicInfo.IsShow;

            ViewData["referer"] = MallUtils.GetMallAdminRefererCookie();
            return(View(model));
        }
コード例 #39
0
        public async Task <IActionResult> OpenTopic(int TopicId, int?ForumId)
        {
            if (ForumId != null)
            {
                HttpContext.Session.SetInt32("fid", (int)ForumId);
            }

            TopicModel topic = await _db.Topics
                               .Include(r => (r.Replies as ReplyModel).Author)
                               .Include(r => (r.Replies as ReplyModel).Pictures)
                               .Include(a => a.Author)
                               .Include(f => f.Forum)
                               .Include(p => p.Pictures)
                               .FirstOrDefaultAsync(i => i.Id == TopicId);

            if (topic != null)
            {
                return(View(topic));
            }
            return(NotFound());
        }
コード例 #40
0
        public ActionResult Create(TopicModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                if (!model.IsPasswordProtected)
                {
                    model.Password = null;
                }

                var topic = model.ToEntity();
                _topicService.InsertTopic(topic);
                //search engine name
                model.SeName = topic.ValidateSeName(model.SeName, topic.Title ?? topic.SystemName, true);
                _urlRecordService.SaveSlug(topic, model.SeName, 0);
                //ACL (customer roles)
                SaveTopicAcl(topic, model);
                //Stores
                SaveStoreMappings(topic, model);
                //locales
                UpdateLocales(topic, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Topics.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = topic.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form

            //templates
            PrepareTemplatesModel(model);
            //ACL
            PrepareAclModel(model, null, true);
            //Stores
            PrepareStoresMappingModel(model, null, true);
            return(View(model));
        }
コード例 #41
0
        public ActionResult Create(TopicModel model, bool continueEditing)
        {
            if (!Services.Permissions.Authorize(StandardPermissionProvider.ManageTopics))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                if (!model.IsPasswordProtected)
                {
                    model.Password = null;
                }

                var topic = model.ToEntity();

                if (model.WidgetZone != null)
                {
                    topic.WidgetZone = string.Join(",", model.WidgetZone);
                }

                _topicService.InsertTopic(topic);

                model.SeName = topic.ValidateSeName(model.SeName, topic.Title.NullEmpty() ?? topic.SystemName, true);
                _urlRecordService.SaveSlug(topic, model.SeName, 0);

                SaveStoreMappings(topic, model);
                SaveAclMappings(topic, model);
                UpdateLocales(topic, model);

                NotifySuccess(T("Admin.ContentManagement.Topics.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = topic.Id }) : RedirectToAction("List"));
            }

            // If we got this far, something failed, redisplay form.
            PrepareStoresMappingModel(model, null, true);
            PrepareAclModel(model, null, true);

            return(View(model));
        }
コード例 #42
0
ファイル: TopicController.cs プロジェクト: krreddy123/appcode
        public ActionResult Create(TopicModel model, bool continueEditing, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                if (!model.IsPasswordProtected)
                {
                    model.Password = null;
                }

                var topic = model.ToEntity();

                if (model.WidgetZone != null)
                {
                    topic.WidgetZone = string.Join(",", model.WidgetZone);
                }

                topic.CookieType = (CookieType?)model.CookieType;

                _topicService.InsertTopic(topic);

                model.SeName = topic.ValidateSeName(model.SeName, topic.Title.NullEmpty() ?? topic.SystemName, true);
                _urlRecordService.SaveSlug(topic, model.SeName, 0);

                SaveStoreMappings(topic, model.SelectedStoreIds);
                SaveAclMappings(topic, model.SelectedCustomerRoleIds);
                UpdateLocales(topic, model);
                AddCookieTypes(model, model.CookieType);

                Services.EventPublisher.Publish(new ModelBoundEvent(model, topic, form));

                NotifySuccess(T("Admin.ContentManagement.Topics.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = topic.Id }) : RedirectToAction("List"));
            }

            // If we got this far, something failed, redisplay form.
            PrepareStoresMappingModel(model, null, true);
            PrepareAclModel(model, null, true);

            return(View(model));
        }
コード例 #43
0
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            var topic = _topicService.GetTopicById(id);
            if (topic == null)
                //No topic found with the specified id
                return RedirectToAction("List");

            var model = new TopicModel()
            {
                Body = topic.Body,
                Id = topic.Id,
                IncludeInSitemap = topic.IncludeInSitemap,
                IsPasswordProtected = topic.IsPasswordProtected,
                MetaDescription = topic.MetaDescription,
                MetaKeywords = topic.MetaKeywords,
                MetaTitle = topic.MetaTitle,
                Password = topic.Password,
                SystemName = topic.SystemName,
                Title = topic.Title
            };
            model.Url = Url.RouteUrl("Topic", new { SystemName = topic.SystemName }, "http");
            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Title = topic.GetLocalized(x => x.Title, languageId, false, false);
                locale.Body = topic.GetLocalized(x => x.Body, languageId, false, false);
                locale.MetaKeywords = topic.GetLocalized(x => x.MetaKeywords, languageId, false, false);
                locale.MetaDescription = topic.GetLocalized(x => x.MetaDescription, languageId, false, false);
                locale.MetaTitle = topic.GetLocalized(x => x.MetaTitle, languageId, false, false);
            });

            return View(model);
        }
コード例 #44
0
        protected virtual List<LocalizedProperty> UpdateLocales(Topic topic, TopicModel model)
        {
            List<LocalizedProperty> localized = new List<LocalizedProperty>();

            foreach (var local in model.Locales)
            {
                var seName = topic.ValidateSeName(local.SeName, local.Title, false);
                _urlRecordService.SaveSlug(topic, seName, local.LanguageId);

                if (!(String.IsNullOrEmpty(seName)))
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId = local.LanguageId,
                        LocaleKey = "SeName",
                        LocaleValue = seName
                    });

                if (!(String.IsNullOrEmpty(local.Body)))
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId = local.LanguageId,
                        LocaleKey = "Body",
                        LocaleValue = local.Body
                    });

                if (!(String.IsNullOrEmpty(local.MetaDescription)))
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId = local.LanguageId,
                        LocaleKey = "MetaDescription",
                        LocaleValue = local.MetaDescription
                    });

                if (!(String.IsNullOrEmpty(local.MetaKeywords)))
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId = local.LanguageId,
                        LocaleKey = "MetaKeywords",
                        LocaleValue = local.MetaKeywords
                    });

                if (!(String.IsNullOrEmpty(local.MetaTitle)))
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId = local.LanguageId,
                        LocaleKey = "MetaTitle",
                        LocaleValue = local.MetaTitle
                    });

                if (!(String.IsNullOrEmpty(local.Title)))
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId = local.LanguageId,
                        LocaleKey = "Title",
                        LocaleValue = local.Title
                    });

            }
            return localized;
        }
コード例 #45
0
ファイル: TopicController.cs プロジェクト: aumankit/nop
 protected virtual void SaveTopicAcl(Topic topic, TopicModel model)
 {
     var existingAclRecords = _aclService.GetAclRecords(topic);
     var allCustomerRoles = _customerService.GetAllCustomerRoles(true);
     foreach (var customerRole in allCustomerRoles)
     {
         if (model.SelectedCustomerRoleIds != null && model.SelectedCustomerRoleIds.Contains(customerRole.Id))
         {
             //new role
             if (existingAclRecords.Count(acl => acl.CustomerRoleId == customerRole.Id) == 0)
                 _aclService.InsertAclRecord(topic, customerRole.Id);
         }
         else
         {
             //remove role
             var aclRecordToDelete = existingAclRecords.FirstOrDefault(acl => acl.CustomerRoleId == customerRole.Id);
             if (aclRecordToDelete != null)
                 _aclService.DeleteAclRecord(aclRecordToDelete);
         }
     }
 }
コード例 #46
0
ファイル: TopicController.cs プロジェクト: aumankit/nop
        protected virtual void PrepareAclModel(TopicModel model, Topic topic, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            model.AvailableCustomerRoles = _customerService
                .GetAllCustomerRoles(true)
                .Select(cr => cr.ToModel())
                .ToList();
            if (!excludeProperties)
            {
                if (topic != null)
                {
                    model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(topic);
                }
            }
        }
コード例 #47
0
        public ActionResult Edit(TopicModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            var topic = _topicService.GetTopicById(model.Id);
            if (topic == null)
                //No topic found with the specified id
                return RedirectToAction("List");

            model.Url = Url.RouteUrl("Topic", new { SystemName = topic.SystemName }, "http");

            if (!model.IsPasswordProtected)
            {
                model.Password = null;
            }

            if (ModelState.IsValid)
            {
                topic = model.ToEntity(topic);
                _topicService.UpdateTopic(topic);
                //Stores
                SaveStoreMappings(topic, model);
                //locales
                UpdateLocales(topic, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Topics.Updated"));
                return continueEditing ? RedirectToAction("Edit", topic.Id) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form

            //Store
            PrepareStoresMappingModel(model, topic, true);
            return View(model);
        }
コード例 #48
0
ファイル: QueryController.cs プロジェクト: RussMan/CS308RD
        /*****************************************************************************************
         *                          POST-FETCHING RELATED ACTIONS                                *
         *****************************************************************************************/
        public ActionResult get_topics()
        {
            //Get the topics available for the user to choose
            List<string> topic_lst = new List<string>();
            try
            {
                using (MySqlConnection connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlConnString"].ConnectionString))
                {
                    if (connection.State != System.Data.ConnectionState.Open)
                        connection.Open();
                    MySqlCommand command = new MySqlCommand("SELECT * FROM contopic;", connection);
                    MySqlDataReader dr = command.ExecuteReader();
                    while (dr.Read())
                    {
                        if (!(topic_lst.Contains(dr.GetString(1))))  //Make sure the topics do not repeat
                            topic_lst.Add(dr.GetString(1));
                    }
                    dr.Close();
                    connection.Close();//Added close because it was always open
                }
            }
            catch (Exception ex)
            {
                return Content("An error occured: " + ex.Message);
            }

            var viewModel = new TopicModel { topics = topic_lst };

            return View(viewModel); //Return the topics via a Topic Model
        }
コード例 #49
0
        public ActionResult Edit(TopicModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            var topic = _topicService.GetTopicById(model.Id);
            if (topic == null)
                //No topic found with the specified id
                return RedirectToAction("List");

            model.Url = Url.RouteUrl("Topic", new { SystemName = topic.SystemName }, "http");

            if (!model.IsPasswordProtected)
            {
                model.Password = null;
            }

            if (ModelState.IsValid)
            {
                topic.Body = model.Body;
                topic.IncludeInSitemap = model.IncludeInSitemap;
                topic.IsPasswordProtected = model.IsPasswordProtected;
                topic.MetaDescription = model.MetaDescription;
                topic.MetaKeywords = model.MetaKeywords;
                topic.MetaTitle = model.MetaTitle;
                topic.Password = model.Password;
                topic.SystemName = model.SystemName;
                topic.Title = model.Title;
                _topicService.UpdateTopic(topic);
                //locales
                UpdateLocales(topic, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Topics.Updated"));
                return continueEditing ? RedirectToAction("Edit", topic.Id) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #50
0
        public ActionResult Edit(TopicModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            var topic = _topicService.GetTopicById(model.Id);
            if (topic == null)
                //No topic found with the specified id
                return RedirectToAction("List");

            if (!model.IsPasswordProtected)
            {
                model.Password = null;
            }

            if (ModelState.IsValid)
            {
                topic = model.ToEntity(topic);
                _topicService.UpdateTopic(topic);
                //search engine name
                model.SeName = topic.ValidateSeName(model.SeName, topic.Title ?? topic.SystemName, true);
                _urlRecordService.SaveSlug(topic, model.SeName, 0);
                //Stores
                SaveStoreMappings(topic, model);
                //locales
                UpdateLocales(topic, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Topics.Updated"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

                    return RedirectToAction("Edit",  new {id = topic.Id});
                }
                return RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form

            model.Url = Url.RouteUrl("Topic", new { SeName = topic.GetSeName() }, "http");
            //templates
            PrepareTemplatesModel(model);
            //Store
            PrepareStoresMappingModel(model, topic, true);
            return View(model);
        }
コード例 #51
0
        protected virtual void PrepareStoresMappingModel(TopicModel model, Topic topic, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            model.AvailableStores = _storeService
                .GetAllStores()
                .Select(s => s.ToModel())
                .ToList();
            if (!excludeProperties)
            {
                if (topic != null)
                {
                    model.SelectedStoreIds = topic.Stores.ToArray();
                }
            }
        }
コード例 #52
0
 protected virtual void SaveStoreMappings(Topic topic, TopicModel model)
 {
     var existingStoreMappings = _storeMappingService.GetStoreMappings(topic);
     var allStores = _storeService.GetAllStores();
     foreach (var store in allStores)
     {
         if (model.SelectedStoreIds != null && model.SelectedStoreIds.Contains(store.Id))
         {
             //new store
             if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0)
                 _storeMappingService.InsertStoreMapping(topic, store.Id);
         }
         else
         {
             //remove store
             var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id);
             if (storeMappingToDelete != null)
                 _storeMappingService.DeleteStoreMapping(storeMappingToDelete);
         }
     }
 }
コード例 #53
0
        protected virtual void PrepareAclModel(TopicModel model, Topic topic, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            if (!excludeProperties && topic != null)
                model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(topic).ToList();

            var allRoles = _customerService.GetAllCustomerRoles(true);
            foreach (var role in allRoles)
            {
                model.AvailableCustomerRoles.Add(new SelectListItem
                {
                    Text = role.Name,
                    Value = role.Id.ToString(),
                    Selected = model.SelectedCustomerRoleIds.Contains(role.Id)
                });
            }
        }
コード例 #54
0
        protected virtual void PrepareStoresMappingModel(TopicModel model, Topic topic, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            if (!excludeProperties && topic != null)
                model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(topic).ToList();

            var allStores = _storeService.GetAllStores();
            foreach (var store in allStores)
            {
                model.AvailableStores.Add(new SelectListItem
                {
                    Text = store.Name,
                    Value = store.Id.ToString(),
                    Selected = model.SelectedStoreIds.Contains(store.Id)
                });
            }
        }
コード例 #55
0
ファイル: TopicController.cs プロジェクト: cmcginn/StoreFront
        public ActionResult Edit(TopicModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
                return AccessDeniedView();

            var topic = _topicService.GetTopicById(model.Id);
            if (topic == null)
                throw new ArgumentException("No topic found with the specified id");

            //decode description
            model.Body = HttpUtility.HtmlDecode(model.Body);
            foreach (var localized in model.Locales)
                localized.Body = HttpUtility.HtmlDecode(localized.Body);

            model.Url = Url.RouteUrl("Topic", new { SystemName = topic.SystemName }, "http");

            if (!model.IsPasswordProtected)
            {
                model.Password = null;
            }

            if (ModelState.IsValid)
            {
                topic = model.ToEntity(topic);
                _topicService.UpdateTopic(topic);
                //locales
                UpdateLocales(topic, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Topics.Updated"));
                return continueEditing ? RedirectToAction("Edit", topic.Id) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }