public ActionResult Edit(Guid Id) { using (UnitOfWorkManager.NewUnitOfWork()) { var cats = _categoryService.GetAllowedEditCategories(UsersRole, false); if (cats.Count > 0) { var viewModel = new AdminCreateEditTopicViewModel(); viewModel.Categories = _categoryService.GetBaseSelectListCategories(cats); var topic = _topicServic.Get(Id); if (topic == null) { TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = LocalizationService.GetResourceString("Errors.NoFindTopic"), MessageType = GenericMessages.warning }; return(RedirectToAction("Index")); } viewModel.Id = topic.Id; viewModel.Name = topic.Name; viewModel.Category = topic.Category_Id; viewModel.IsLocked = topic.IsLocked; viewModel.IsSticky = topic.IsSticky; viewModel.Image = topic.Image; viewModel.Intro = topic.Intro; viewModel.SEOKeyword = topic.SEOKeyword; viewModel.SEODescription = topic.SEODescription; if (topic.Post_Id != null) { var post = _postSevice.Get((Guid)topic.Post_Id); if (post != null) { viewModel.Content = post.PostContent; } } //viewModel.Po = topic.IsLocked; return(View(viewModel)); } return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission"))); } }
public ActionResult Create() { using (UnitOfWorkManager.NewUnitOfWork()) { var cats = _categoryService.GetAllowedEditCategories(UsersRole, false); if (cats.Count > 0) { var viewModel = new AdminCreateEditTopicViewModel(); viewModel.Categories = _categoryService.GetBaseSelectListCategories(cats); return(View(viewModel)); } return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission"))); } }
public ActionResult Edit(AdminCreateEditTopicViewModel viewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var cats = _categoryService.GetAllowedEditCategories(UsersRole, false); if (cats.Count > 0) { if (ModelState.IsValid) { if (CheckCats(viewModel.Category, cats)) { var topic = _topicServic.Get(viewModel.Id); if (topic == null) { TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = LocalizationService.GetResourceString("Errors.NoFindTopic"), MessageType = GenericMessages.warning }; return(RedirectToAction("Index")); } bool pn = false; Post post; if (topic.Post_Id != null) { post = _postSevice.Get((Guid)topic.Post_Id); } else { post = new Post(); pn = true; } topic.Name = viewModel.Name; topic.Category_Id = viewModel.Category; topic.Image = viewModel.Image; topic.IsLocked = viewModel.IsLocked; topic.IsSticky = viewModel.IsSticky; topic.MembershipUser_Id = LoggedOnReadOnlyUser.Id; topic.Post_Id = post.Id; topic.Intro = viewModel.Intro; topic.SEOKeyword = viewModel.SEOKeyword; topic.SEODescription = viewModel.SEODescription; post.PostContent = viewModel.Content; post.MembershipUser_Id = LoggedOnReadOnlyUser.Id; post.Topic_Id = topic.Id; post.IsTopicStarter = true; topic.ShotContent = string.Concat(StringUtils.ReturnAmountWordsFromString(StringUtils.StripHtmlFromString(post.PostContent), 50), "...."); topic.isAutoShotContent = true; var i = topic.ShotContent.Length; if (i > 450) { topic.ShotContent = topic.ShotContent.Substring(0, 440) + "..."; } try { _topicServic.Update(topic); if (pn) { _postSevice.Add(post); } else { _postSevice.Update(post); } unitOfWork.Commit(); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = LocalizationService.GetResourceString("Success.TopicCreateSuccess"), MessageType = GenericMessages.success }; //return RedirectToAction("Edit", new { Id = topic.Id }); } catch (Exception ex) { LoggingService.Error(ex.Message); unitOfWork.Rollback(); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = LocalizationService.GetResourceString("Error.TopicCreateError"), MessageType = GenericMessages.warning }; } } else { //viewModel.Category = null; //No permission to create a Poll so show a message but create the topic //TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel //{ // Message = LocalizationService.GetResourceString("Errors.NoPermissionCatergory"), // MessageType = GenericMessages.info //}; ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Errors.CatergoryMessage")); } } viewModel.Categories = _categoryService.GetBaseSelectListCategories(cats); return(View(viewModel)); } return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission"))); } }