Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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.")));
        }
Ejemplo n.º 4
0
        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());
        }
Ejemplo n.º 5
0
        // 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));
        }
Ejemplo n.º 6
0
        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
                }));
            }
        }
Ejemplo n.º 7
0
 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"));
 }
Ejemplo n.º 8
0
        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));
            }
        }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 12
0
        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"));
        }
Ejemplo n.º 13
0
 public ForumPage()
 {
     InitializeComponent();
     BindingContext = model = new ForumViewModel();
     this.Title     = "Forum";
     NavigationPage.SetHasNavigationBar(this, true);
 }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 16
0
        public IActionResult CreateForum(ForumViewModel Onpost)
        {
            Forum  forum  = new Forum(connectionstring);
            string result = forum.CreateForum(Onpost.ForumTitel, Onpost.Desciption);

            ViewBag.Created = result;
            return(View());
        }
Ejemplo n.º 17
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            _viewModel       = (ForumViewModel)Resources["viewModel"];
            this.DataContext = _viewModel;

            _viewModel.Load();
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Forum(int id)
        {
            ForumViewModel vm = new ForumViewModel()
            {
                Forum = await _forumRepository.GetByIdWithTopics(id)
            };

            return(View(vm));
        }
Ejemplo n.º 19
0
        // GET: Forum
        public IActionResult Index(string id)
        {
            ForumViewModel forum = new ForumViewModel();

            forum.Topics = forumService.GetTopics();
            forum.Posts  = forumService.GetPosts();

            return(View(forum));
        }
Ejemplo n.º 20
0
        // GET: Forum
        public async Task <IActionResult> Index()
        {
            ForumViewModel fvm = new ForumViewModel()
            {
                MessageList = await _context.Message.ToListAsync()
            };

            return(View(fvm));
        }
Ejemplo n.º 21
0
        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));
        }
Ejemplo n.º 22
0
        public ForumPage(ForumViewModel model)
        {
            InitializeComponent();

            Model = model;
            Model.Load();

            ForumsListView.BindingContext = Model;
            ForumsListView.ItemTapped    += ForumsListView_ItemTapped;
        }
Ejemplo n.º 23
0
        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));
        }
Ejemplo n.º 24
0
        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));
        }
Ejemplo n.º 26
0
        public ViewResult Index()
        {
            var data = _forumRepository.GetMainTopic();

            var list = new ForumViewModel()
            {
                MainTopics = new List <Topics>(data.valueList)
            };

            return(View(list));
        }
Ejemplo n.º 27
0
        public IActionResult Forum()
        {
            ViewData["Message"] = "Your contact page.";

            var viewModel = new ForumViewModel()
            {
                threadList = _context.Threads.Where(a => a.ThreadID > 0).ToList()
            };

            return(View(viewModel));
        }
Ejemplo n.º 28
0
        public ForumViewModel BuildForum(Forum model)
        {
            var modelVm = new ForumViewModel()
            {
                Id          = model.Id,
                Title       = model.Title,
                Description = model.Description
            };

            return(modelVm);
        }
Ejemplo n.º 29
0
 public async Task Save(ForumViewModel model)
 {
     if (model.Id == 0)
     {
         await Create(model : model);
     }
     else
     {
         await Update(model : model);
     }
 }
Ejemplo n.º 30
0
        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);
        }