public IActionResult AddPost() { var model = new AddPostVM(); model.Categories = _postsRepository.GetAllCategories(); //var model = _postsRepository.GetAllPosts(); return(View(model)); }
//Add new category public void AddNewCategory(AddPostVM viewModel) { _context.Category.Add(new Category { CategoryName = viewModel.NewCategory }); _context.SaveChanges(); }
// GET: Admin/Post public ActionResult Create() { AddPostVM model = new AddPostVM() { Categories = _categoryRepo.GetActive(), AppUsers = _appUserRepo.GetDefault(x => x.Role != Role.Member) }; return(View(model)); }
// GET: Admin/Post public ActionResult Create() { AddPostVM addPostVM = new AddPostVM() { Categories = _categoryService.GetActive(), AppUsers = _appUserService.GetDefault(x => x.Role != Entity.Entities.Role.Member) }; return(View(addPostVM)); }
public int AddPost(AddPostVM model) { if (ModelState.IsValid) { return(lessonOperation.AddPost(model)); } else { return(0); } }
/// <summary> /// Maps an AddPost view model to a Post entity /// </summary> /// <param name="postToAdd"></param> /// <returns></returns> public static Post AddPostToVM(AddPostVM postToAdd) { Post post = new Post { PostCreator = postToAdd.PostCreator, PostDetails = postToAdd.PostDetails, PostTitle = postToAdd.PostTitle, CreationDate = postToAdd.Time, }; post.PostCategories = ReturnPostCategories(postToAdd.CategoriesId, post.PostId); return(post); }
/// <summary> /// Helper method to generate the selectite, for the category dropdown box /// </summary> /// <returns></returns> public async Task <AddPostVM> CreateAddPostVM() { var post = new AddPostVM(); var tags = await _Categoryservices.GetPostCategory(); var selsectList = new List <SelectListItem>(); foreach (var item in tags) { selsectList.Add(new SelectListItem { Value = item.CategoryId, Text = item.CategoryName }); } post.Categories = selsectList; return(post); }
public IActionResult AddPost(AddPostVM viewModel, string command) { if (command.Equals("submit2")) { _postsRepository.AddNewCategory(viewModel); return(RedirectToAction("addpost", "admin")); } else { if (!ModelState.IsValid) { return(View(viewModel)); } _postsRepository.AddPost(viewModel, "Administrator"); return(RedirectToAction("index", "home")); } }
public int AddPost(AddPostVM model) { User fromUser = Services.User.FirstOrDefault(x => x.ID == model.FromID && x.AccountType == (int)EnumUserType.Teacher); Lesson lesson = Services.Lesson.FirstOrDefault(x => x.ID == model.LessonID); if (fromUser != null && lesson != null) { LessonTeacherPost _model = new LessonTeacherPost(); _model.AddDate = DateTime.Now; _model.Description = model.Description; _model.LessonID = model.LessonID; _model.Title = model.Title; Services.LessonTeacherPost.Insert(_model); return(1); } else { return(0); } }
public async Task <IActionResult> AddPost(AddPostVM model) { if (!ModelState.IsValid) { var post = await CreateAddPostVM(); return(View(post)); } else { var user = await _userManager.GetUserAsync(HttpContext.User); var postToAdd = PostMappers.AddPostToVM(model); var imagepath = _imageProcessorService.ImageUpload(model); postToAdd.ImagePath = imagepath; postToAdd.PostCreator = user; await _postService.AddPost(postToAdd); return(RedirectToAction("Index", new { postToAdd.PostId })); } }
//Skriv till db public void AddPost(AddPostVM viewModel, string postedBy) { if (viewModel.Link != null) { viewModel.Link = viewModel.Link.Replace("watch?v=", "embed/"); viewModel.Link = viewModel.Link + "?rel=0&fs=0&showinfo=0"; } //var user = _context.Users. _context.Posts.Add(new Post { Title = viewModel.Title, Text = viewModel.Text, Link = viewModel.Link, TimePosted = DateTime.Now.AddHours(2), Category = viewModel.Category, PostedBy = viewModel.PostedBy, Tags = viewModel.Tags, Image = viewModel.Image }); _context.SaveChanges(); }
public async Task <IActionResult> Add(AddPostVM model, IFormFile file) { var user = await userManager.FindByNameAsync(User.Identity.Name); if (file != null) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img", file.FileName); using (var fs = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(fs); model.ImageUrl = file.FileName; } } if (ModelState.IsValid) { Post p = new Post { PostName = model.Name, PostTitle = model.Title, PostDescription = model.Description, UserId = user.Id, PostDate = DateTime.Now, ImageUrl = model.ImageUrl }; context.Posts.Add(p); await context.SaveChangesAsync(); return(Redirect("/")); } return(View(model)); }