public async Task <IActionResult> Create(Guid?categoryId, ForumViewModel model) { if (categoryId == null) { return(this.NotFound()); } var user = await this.userManager.GetUserAsync(this.HttpContext.User); if (this.ModelState.IsValid && user != null) { var now = DateTime.UtcNow; var forum = new Forum { Name = model.Name, Description = model.Description, CategoryId = (Guid)categoryId }; this.context.Forums.Add(forum); await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index")); } var foraCategories = await this.context.ForumCategories.OrderBy(x => x.Name).ToListAsync(); this.ViewData["CategoryId"] = new SelectList(foraCategories, "Id", "Name"); return(this.View(model)); }
public async Task <IActionResult> Edit(Guid?id, Guid?categoryId, ForumViewModel model) { if (id == null || categoryId == null) { return(this.NotFound()); } var forum = await this.context.Forums.SingleOrDefaultAsync(m => m.Id == id); if (forum == null) { return(this.NotFound()); } if (this.ModelState.IsValid) { forum.Name = model.Name; forum.Description = model.Description; forum.CategoryId = (Guid)categoryId; await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index")); } return(this.View(model)); }
public IActionResult UnsubscribeForum([FromBody] ForumViewModel model) { Forum ForumToSearch = db.Forums.FirstOrDefault(x => x.Id.ToString() == model.Id); if (ForumToSearch is null) { return(BadRequest(Message.GetMessage("No existeix cap forum amb aquesta id en la base de dades."))); } User user = userGetter.GetUser(); if (user is null) { return(BadRequest(Message.GetMessage("No hi ha cap usuari connectat ara mateix. Connecta't per poder subscriure a un forum"))); } Wallet wallet = db.Wallets.Where(x => x.User.Id == user.Id && x.Forum.Id == ForumToSearch.Id).FirstOrDefault(); if (wallet is null) { return(BadRequest(Message.GetMessage("Aquest usuari no es pot desubscriure perquè no esta subscrit al forum."))); } db.Wallets.Remove(wallet); db.SaveChanges(); return(new JsonResult(Message.GetMessage("El usuari s'ha desubscrit exitosament a aquest forum."))); }
public ActionResult EditForum(ForumViewModel model) { if (ModelState.IsValid) { Category category = _categoryRepository.Get(model.CategoryID); if (category == null) { ModelState.AddModelError("CategoryID", "Category does not exist."); } } if (IsModelValidAndPersistErrors()) { Forum forum = _forumRepository.Get(model.ForumID); forum.Name = model.Name; forum.Description = model.Description; forum.CategoryID = model.CategoryID; forum.VisibleToGuests = model.VisibleToGuests; forum.AllowGuestDownloads = model.AllowGuestDownloads; _forumRepository.Update(forum); SetSuccess("Forum Updated"); return(RedirectToAction("Forums")); } return(RedirectToSelf()); }
// GET: Fora/Edit/5 public async Task <IActionResult> Edit(Guid?id, Guid?categoryId) { if (id == null || categoryId == null) { return(this.NotFound()); } var forum = await this.context.Forums.SingleOrDefaultAsync(m => m.Id == id); if (forum == null) { return(this.NotFound()); } var model = new ForumViewModel { Name = forum.Name, Description = forum.Description, }; var forumCategories = await this.context.ForumCategories.OrderBy(x => x.Name).ToListAsync(); this.ViewBag.CategoryId = categoryId; this.ViewBag.Forum = forum; return(this.View(model)); }
public async Task <IActionResult> AddReply(ForumViewModel forumViewModel, int msgId, int chatRoomID) { if (ModelState.IsValid) { var user = await userManager.GetUserAsync(HttpContext.User); var newRply = new Reply() { ReplyContent = forumViewModel.RplyViewModel.MessageBody, UnixTimeStamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Poster = user.UserName }; // add to reply, msg, and user repos await replyRepo.AddReplyToRepo(newRply); await messageRepo.AddReplytoMsg(newRply, msgId); user.AddToReplyHistory(newRply); var result = await userManager.UpdateAsync(user); return(RedirectToAction("Forum", new { chatRoomID = chatRoomID })); } else { ModelState.AddModelError(nameof(CreateReplyViewModel.MessageBody), "Invalid reply body"); return(RedirectToAction("Forum", new { chatRoomID = chatRoomID, forumViewModel = forumViewModel })); } }
public ActionResult Edit([Bind(Include = "Id,Question,Answer")] ForumViewModel model) { if (ModelState.IsValid) { FAQ forum; try { forum = db.forum.Single(s => s.Id == model.Id); if (forum == null) { return(HttpNotFound()); } forum.Answer = model.Answer; forum.Question = model.Question; db.SaveChanges(); ViewBag.AlertMessage = "changes has ended succesfully"; return(RedirectToAction("List")); } catch (Exception) { ViewBag.AlertMessage = "Something gone wrong. Try again please!"; return(RedirectToAction("List")); } } ViewBag.AlertMessage = "Something gone wrong. Try again please!"; return(RedirectToAction("List")); }
public IActionResult Forum(int?chatRoomID = null, ForumViewModel forumViewModel = null) //CreateMessageViewModel rejectedMsg = null, CreateReplyViewModel rejectedRply = null) { // allows for user to select which chat room they want ViewBag.BackgroundStyle = "parallaxEffect"; List <ChatRoom> chatRooms = chatRepo.ChatRoomList; ChatRoom selectChatRoom; if (chatRoomID != null) { selectChatRoom = chatRooms.Find(chat => chat.ChatRoomID == chatRoomID); } else { selectChatRoom = chatRooms.Count == 0 ? null : chatRooms[0]; } ViewBag.ChatRoomList = chatRooms; // for dropdown if (forumViewModel.MsgViewModel == null && forumViewModel.RplyViewModel == null && forumViewModel.SelectedChat == null) { // build forum view model ForumViewModel forumVM = new ForumViewModel(); forumVM.SelectedChat = selectChatRoom; return(View(forumVM)); } else { return(View(forumViewModel)); } }
public async Task <IActionResult> Index(string searchQuery) { ForumViewModel model = null;// = new ForumViewModel(); if (String.IsNullOrEmpty(searchQuery)) { model = new ForumViewModel() { Topics = await _topicRepo.GetAllAsync(), Comments = await _commentRepo.GetAllAsync(), Replays = await _replayRepo.GetAllAsync() }; } else { model = new ForumViewModel() { //Topics = await _topicRepo.GetFilteredDataAsync(searchQuery), //Topics = model.Topics.Where(t => t.Title.Contains(searchQuery)), Topics = _topicRepo.QueriedTopics(searchQuery), Comments = await _commentRepo.GetAllAsync(), Replays = await _replayRepo.GetAllAsync() }; } return(View(model)); }
public ActionResult Create(ForumViewModel post) { Forum forum = new Forum(); if (ModelState.IsValid) { forum.CreatedBy = "admin"; forum.CreatedDate = DateTime.Now; forum.ForumCategoryId = post.ForumCategoryId; forum.IsActive = true; forum.IsAnswered = false; forum.QuestionDescription = post.QuestionDescription; forum.QuestionTitle = post.QuestionTitle; forum.UpdatedBy = "admin"; forum.UpdatedDate = DateTime.Now; if (_forumService.CreateForum(forum)) { return(RedirectToActionPermanent("Index", "Forum")); } } List <ForumCategory> categoryList = _forumService.GetlAllForumCategories().ToList(); post.ForumCategoryList = new List <SelectListItem>(); foreach (var item in categoryList) { post.ForumCategoryList.Add(new SelectListItem { Text = item.ForumCategoryName, Value = item.ForumCategoryId.ToString() }); } return(View(post)); }
public ForumPage() { InitializeComponent(); NavigationPage.SetHasBackButton(this, true); BindingContext = model = new ForumViewModel(); }
public async Task <IActionResult> EditForum(ForumViewModel model) { try { var forum = forumService.GetForumModel(model.ForumId); if (userManager.GetUserId(User) == forum.UserId || User.IsInRole("Admin")) { forum.ForumName = model.ForumName; await forumService.EditForum(forum); } else { throw new Exception(); } } catch { ViewBag.ErrorTitle = "Editing Error"; ViewBag.ErrorMessage = "There was an issue editing your post. Please contact us for support."; return(View("Error")); } return(RedirectToAction("Index", "Home")); }
public ForumPage() { InitializeComponent(); BindingContext = model = new ForumViewModel(); this.Title = "Forum"; NavigationPage.SetHasNavigationBar(this, true); }
public IActionResult Index() { ForumViewModel viewModel = new ForumViewModel(); ForumLogic logic = new ForumLogic(); viewModel.Berichten = logic.AlleBerichten(); return(View(viewModel)); }
public ActionResult ForumPosts(int id) { ForumContainer forumcontainer = new ForumContainer(connectionstring); ForumViewModel forumViewModel = new ForumViewModel(forumcontainer.GetForumById(id)); return(View(forumViewModel)); }
public IActionResult CreateForum(ForumViewModel Onpost) { Forum forum = new Forum(connectionstring); string result = forum.CreateForum(Onpost.ForumTitel, Onpost.Desciption); ViewBag.Created = result; return(View()); }
// Constructor public MainPage() { InitializeComponent(); _viewModel = (ForumViewModel)Resources["viewModel"]; this.DataContext = _viewModel; _viewModel.Load(); }
public async Task <IActionResult> Forum(int id) { ForumViewModel vm = new ForumViewModel() { Forum = await _forumRepository.GetByIdWithTopics(id) }; return(View(vm)); }
// GET: Forum public IActionResult Index(string id) { ForumViewModel forum = new ForumViewModel(); forum.Topics = forumService.GetTopics(); forum.Posts = forumService.GetPosts(); return(View(forum)); }
// GET: Forum public async Task <IActionResult> Index() { ForumViewModel fvm = new ForumViewModel() { MessageList = await _context.Message.ToListAsync() }; return(View(fvm)); }
public IActionResult Topics() { var viewModel = new ForumViewModel(); var categories = this.categoriesService.GetAll <ForumCategoryViewModel>(); viewModel.Categories = categories; viewModel.TotalPosts = categories.Sum(x => x.PostsCount); return(this.View(viewModel)); }
public ForumPage(ForumViewModel model) { InitializeComponent(); Model = model; Model.Load(); ForumsListView.BindingContext = Model; ForumsListView.ItemTapped += ForumsListView_ItemTapped; }
public IActionResult Index() { var topics = service.ReadAllTopics(); //TODO make it a single service, using Include var users = service.ReadAllUsers(); var model = new ForumViewModel { Topics = topics, UserName = User.Identity.Name, Users = users }; return(View(model)); }
public IActionResult Details(int id) { var forumViewModel = new ForumViewModel() { post = _postRepository.GetPostById(id), Replies = _replyRepository.GetRepliesByParentId(id) }; return(View(forumViewModel)); }
public ActionResult Forum() { var usermanager = IdentityTools.NewUserManager(); var uid = usermanager.FindByName(User.Identity.Name); int ClassId = SrRepo.Get(s => s.UserId == uid.Id).ClassId; ForumViewModel fvm = new ForumViewModel(); fvm.Shares = ArRepo.GetAll(s => s.ClassId == ClassId && s.IsDeleted == false).OrderByDescending(a => a.CreatedDate).ToList(); fvm.UserId = uid.Id; return(View(fvm)); }
public ViewResult Index() { var data = _forumRepository.GetMainTopic(); var list = new ForumViewModel() { MainTopics = new List <Topics>(data.valueList) }; return(View(list)); }
public IActionResult Forum() { ViewData["Message"] = "Your contact page."; var viewModel = new ForumViewModel() { threadList = _context.Threads.Where(a => a.ThreadID > 0).ToList() }; return(View(viewModel)); }
public ForumViewModel BuildForum(Forum model) { var modelVm = new ForumViewModel() { Id = model.Id, Title = model.Title, Description = model.Description }; return(modelVm); }
public async Task Save(ForumViewModel model) { if (model.Id == 0) { await Create(model : model); } else { await Update(model : model); } }
public List <ForumStatusViewModel> GetAllForumsByPersonId(int personId) { List <ForumStatusViewModel> list = new List <ForumStatusViewModel>(); //Creates the dictionaries for the statuses and the forums, so we can insert data to the correct location Dictionary <int, ForumStatusViewModel> statusDict = new Dictionary <int, ForumStatusViewModel>(); Dictionary <int, ForumViewModel> forumDict = new Dictionary <int, ForumViewModel>(); //Runs the stored procedure DataProvider.ExecuteCmd( "Forum_SelectByPersonId", inputParamMapper : delegate(SqlParameterCollection paramCol) { paramCol.AddWithValue("@PersonId", personId); }, singleRecordMapper : delegate(IDataReader reader, short set) { //Switches between the sql select statements switch (set) { //Gets the list of statuses to show to the user case 0: ForumStatusViewModel sModel = new ForumStatusViewModel(); sModel.Forums = new List <ForumViewModel>(); int id = reader.GetSafeInt32(0); sModel.Description = reader.GetSafeString(1); statusDict.Add(id, sModel); list.Add(sModel); break; //Gets the list of forums and assigns them to a status case 1: ForumViewModel fModel = new ForumViewModel(); int index = 0; fModel.Id = reader.GetSafeInt32(index++); fModel.Name = reader.GetSafeString(index++); fModel.Description = reader.GetSafeString(index++); int statusId = reader.GetSafeInt32(index++); fModel.ModifiedDate = reader.GetSafeDateTime(index++); statusDict[statusId].Forums.Add(fModel); forumDict.Add(fModel.Id, fModel); break; //Gets the total amount of comments for each forum case 2: int fId = reader.GetSafeInt32(0); int total = reader.GetSafeInt32(1); forumDict[fId].TotalComments = total; break; } } ); return(list); }