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")); }
public IActionResult CreateNewPost(ViewModelPost newPost) { if (ModelState.IsValid) { AddNewPostToDb(newPost); return(RedirectToAction("OliviasBubble")); } else { return(View("Error")); } }
//****************************************************** // 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)); }
public void AddNewPostToDb(ViewModelPost newPost) { _context.Posts.Add(newPost.CurrentPost); _context.SaveChanges(); }