コード例 #1
0
ファイル: StatusController.cs プロジェクト: mosaddik/Bitbook
        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"));
        }
コード例 #2
0
        public IActionResult CreateNewPost(ViewModelPost newPost)
        {
            if (ModelState.IsValid)
            {
                AddNewPostToDb(newPost);

                return(RedirectToAction("OliviasBubble"));
            }
            else
            {
                return(View("Error"));
            }
        }
コード例 #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));
        }
コード例 #4
0
 public void AddNewPostToDb(ViewModelPost newPost)
 {
     _context.Posts.Add(newPost.CurrentPost);
     _context.SaveChanges();
 }