Esempio n. 1
0
 public ForumsPage()
 {
     BindingContext = ForumsViewModel.GetInstance();
     // calling simulation method
     ViewModel.UpdateForumsList();
     InitializeComponent();
 }
Esempio n. 2
0
 /// <summary>
 /// Gets the view model for all the messages in a forum.
 /// </summary>
 /// <param name="forum">The forum.</param>
 /// <param name="messages">The messages.</param>
 /// <returns></returns>
 /// <exception cref="CustomException"></exception>
 public AllMessagesViewModel GetViewModel(Forums forum, List <Messages> messages)
 {
     try {
         ForumsViewModel          fvm  = GetViewModel(forum);
         List <MessagesViewModel> mvm  = GetViewModel(messages);
         AllMessagesViewModel     amvm = new AllMessagesViewModel();
         amvm.mvm   = mvm;
         amvm.forum = forum;
         return(amvm);
     }
     catch (Exception ex) {
         throw new CustomException(ex.Message);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Gets the view model for a forum.
        /// </summary>
        /// <param name="forum">The forum.</param>
        /// <returns></returns>
        /// <exception cref="CustomException"></exception>
        public ForumsViewModel GetViewModel(Forums forum)
        {
            try {
                ForumsViewModel fvm = new ForumsViewModel();
                fvm.ForumId  = forum.ForumId;
                fvm.Category = forum.Category;
                fvm.OwnerId  = forum.OwnerId;

                return(fvm);
            }
            catch (Exception ex) {
                throw new CustomException(ex.Message);
            }
        }
        //
        // GET: /Discussions/EditForum(id = 0)

        public ActionResult EditForum(int id = 0)
        {
            this.logger.Info("Entering: " + System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName + ": " + System.Reflection.MethodBase.GetCurrentMethod().Name + " --> " + User.Identity.Name);
            try {
                //get the forum to be edited
                Forums forum = new Forums();
                using (var client = new HttpClient()) {
                    client.BaseAddress = new Uri(this.apiMethodsUrl);
                    client.DefaultRequestHeaders.Accept.Add(
                        new MediaTypeWithQualityHeaderValue("application/json")
                        );
                    HttpResponseMessage response = client.GetAsync("api/discussions/GetForumById/?id=" + id).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        var f = response.Content.ReadAsAsync <Forums>().Result;
                        if (f != null)
                        {
                            forum.ForumId  = f.ForumId;
                            forum.Category = f.Category;
                            forum.OwnerId  = f.OwnerId;
                        }
                        else
                        {
                            throw new CustomException("Could not complete the operation!");
                        }
                    }
                    else
                    {
                        throw new CustomException("Could not complete the operation!");
                    }
                }

                ForumsViewModel fvm = this.viewModelFactory.GetViewModel(forum);
                return(View(fvm));
            }
            catch (CustomException ce) {
                this.logger.Trace(ce, "Username: "******"Operation could not be completed! Try again.";
                return(View("Error"));
            }
            catch (Exception ex) {
                this.logger.Trace(ex, "Username: "******"Operation could not be completed!";
                return(View("Error"));
            }
        }
        public ActionResult CreateForum(ForumsViewModel forumViewModel)
        {
            this.logger.Info("Entering: " + System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName + ": " + System.Reflection.MethodBase.GetCurrentMethod().Name + " --> " + User.Identity.Name);
            try {
                var _userId      = Session["UserId"];
                var _sessionUser = Convert.ToInt32(_userId);

                ForumDTO dto = new ForumDTO {
                    ForumId  = forumViewModel.ForumId,
                    Category = forumViewModel.Category,
                    OwnerId  = _sessionUser
                };

                //add new forum
                using (var client = new HttpClient()) {
                    client.BaseAddress = new Uri(this.apiMethodsUrl);
                    client.DefaultRequestHeaders.Accept.Add(
                        new MediaTypeWithQualityHeaderValue("application/json")
                        );
                    //add to db
                    HttpResponseMessage response = client.PostAsJsonAsync("api/discussions/AddForum/?forum=", dto).Result;
                    if (!response.IsSuccessStatusCode)
                    {
                        throw new CustomException("Could not complete the operation!");
                    }
                }

                return(RedirectToAction("Forum"));
            }
            catch (CustomException ce) {
                this.logger.Trace(ce, "Username: "******"Operation could not be completed! Try again.\n" + ce.Message;
                return(View("Error"));
            }
            catch (Exception ex) {
                this.logger.Trace(ex, "Username: "******"Operation could not be completed!";
                return(View("Error"));
            }
        }
        public ActionResult EditForum(ForumsViewModel forumViewModel)
        {
            this.logger.Info("Entering: " + System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName + ": " + System.Reflection.MethodBase.GetCurrentMethod().Name + " --> " + User.Identity.Name);
            try {
                //create the course dto to be passed to the api services
                ForumDTO dto = new ForumDTO {
                    ForumId  = forumViewModel.ForumId,
                    Category = forumViewModel.Category,
                    OwnerId  = forumViewModel.OwnerId
                };

                //edit the forum
                using (var client = new HttpClient()) {
                    client.BaseAddress = new Uri(this.apiMethodsUrl);
                    client.DefaultRequestHeaders.Accept.Add(
                        new MediaTypeWithQualityHeaderValue("application/json")
                        );
                    HttpResponseMessage response = client.PutAsJsonAsync("api/discussions/UpdateForum/?id=" + forumViewModel.ForumId, dto).Result;
                    if (!response.IsSuccessStatusCode)
                    {
                        throw new CustomException("Could not complete the operation!");
                    }
                }

                return(RedirectToAction("Forum"));
            }
            catch (CustomException ce) {
                this.logger.Trace(ce, "Username: "******"Operation could not be completed! Try again.";
                return(View("Error"));
            }
            catch (Exception ex) {
                this.logger.Trace(ex, "Username: "******"Operation could not be completed!";
                return(View("Error"));
            }
        }
Esempio n. 7
0
 public void Setup()
 {
     _pageService = new Mock <IPageService>();
     _viewModel   = ForumsViewModel.GetInstance();
 }
 public ForumDetailPage()
 {
     BindingContext = ForumsViewModel.GetInstance().SelectedForum;
     InitializeComponent();
 }
Esempio n. 9
0
 public IActionResult Logout()
 {
     var model = new ForumsViewModel();
     model.IsLoggedIn = User.Identity.IsAuthenticated;
     return View(model);
 }