Example #1
0
        public RedirectToRouteResult MakeAPost(ViewModelPost viewModelPost, string post)
        {
            var    user       = (User)Session["User"];
            var    newPost    = new Post();
            string path       = "";
            var    profilePic = viewModelPost.Picture;

            if (profilePic != null)
            {
                string pic = System.IO.Path.GetFileName(profilePic.FileName);
                path = System.IO.Path.Combine(
                    Server.MapPath("~/Image/ProfilePic"), pic);
                // file is uploaded
                profilePic.SaveAs(path);

                newPost.PostPicture = viewModelPost.Picture.FileName;
                newPost.UserPost    = post;
            }
            else
            {
                newPost             = new Post();
                newPost.PostPicture = "a";
                newPost.UserPost    = post;
            }
            //save path to  database
            postManager.MakeAPost(newPost, user.Id);
            return(RedirectToAction("Index", "NewsFeed"));
        }
Example #2
0
        public IActionResult CreateNewPost(ViewModelPost newPost)
        {
            if (ModelState.IsValid)
            {
                AddNewPostToDb(newPost);

                return(RedirectToAction("OliviasBubble"));
            }
            else
            {
                return(View("Error"));
            }
        }
Example #3
0
        //******************************************************
        //              Create new post
        //******************************************************
        public IActionResult CreateNewPost()
        {
            var viewModel = new ViewModelPost();

            var categoriesDropdown = new List <SelectListItem>();
            var categoriesDb       = GetCategoriesFromDb();

            CreateCategoriesDropDown(categoriesDb, categoriesDropdown);

            viewModel.Categories = categoriesDropdown;

            return(View(viewModel));
        }
Example #4
0
 public void AddNewPostToDb(ViewModelPost newPost)
 {
     _context.Posts.Add(newPost.CurrentPost);
     _context.SaveChanges();
 }