public async Task <IActionResult> CreatePost(CreatePostVM model) { if (!ModelState.IsValid) { _toastNotification.AddErrorToastMessage(_localizer["Cannot create post with an empty message"]); return(Redirect(model.PostBackUrl)); } try { var userId = _userManager.GetUserId(User); var selectedVendor = await _vendorService.GetVendorAsync(userId, model.VendorTitle); await _postsService.CreatePost(model.Text, selectedVendor, model.Image); } catch { _toastNotification.AddErrorToastMessage("Something unexpected happened. Cannot create a post."); return(Redirect(model.PostBackUrl)); } model.Text = ""; return(Redirect(model.PostBackUrl)); }
public void CreateNewPost(CreatePostVM newPost) { Post createPost = _mapper.Map <Post>(newPost); dbContext.Posts.Add(createPost); dbContext.SaveChanges(); }
public async Task <IActionResult> Create(CreatePostVM salePostModel) { if (this.HasAlert) { this.SetAlertModel(); } if (!this.ModelState.IsValid) { this.AddAlert(false, "An error has occured!"); //this.LoadListSneakersDropdowns(); return(this.View(salePostModel)); } var post = _mapper.Map <SalePost>(salePostModel); post.UserId = this.userManager.GetUserId(this.User); post.Sneaker.Slug = SlugGenerator.GenerateSlug(post.Sneaker.Name); post.Sneaker.PosterImageLink = await FileManager.SaveFile(this.hostingEnvironment, salePostModel.Sneaker.PosterImage); var rating = _mapper.Map <Rating>(salePostModel.Sneaker.Rating); rating.RatedById = this.userManager.GetUserId(this.User); rating.RatedOn = DateTime.Now; post.Sneaker.SneakerRatings.Add(new SneakerRating { Rating = rating }); foreach (var keyword in salePostModel.Sneaker.KeywordsString.Trim().Split(",")) { post.Sneaker.Keywords.Add(new Keyword { Name = keyword.Trim() }); } try { await this.salePostService.Create(post); } catch (DbUpdateException e) when(e.InnerException is SqlException sqlEx && (sqlEx.Number == 2601 || sqlEx.Number == 2627)) { this.AddAlert(false, "Cannot insert duplicate sneaker!"); //TODO => //this.LoadListSneakersDropdowns(); return(this.View(salePostModel)); } this.AddAlert(true, "Successfully added post!"); return(this.RedirectToAction("Index", new PaginationVM { Page = 1, PageSize = 20 })); }
public async Task <IActionResult> CreatePost(CreatePostVM createPostVM) { string userId = _userManager.GetUserId(User); var user = await _userManager.FindByIdAsync(userId); var post = BuildPost(createPostVM, user); await _postService.AddPost(post); return(RedirectToAction("Index", "Post", new { id = post.Id })); }
// GET: Admin/Post public ActionResult Create() { CreatePostVM model = new CreatePostVM() { Categories = _categoryRepository.GetActive(), AppUsers = _appUserRepository.GetDefault(x => x.Role != Role.Member) }; return(View(model)); }
private Post BuildPost(CreatePostVM createPostVM, ApplicationUser user) { var forum = _forumService.GetById(createPostVM.ForumId); return(new Post { Title = createPostVM.Title, Content = createPostVM.Content, CreatedAt = DateTime.Now, Author = user, Forum = forum }); }
public IActionResult Create(int id) { var forum = _forumService.GetById(id); var model = new CreatePostVM() { ForumName = forum.Title, ForumId = forum.Id, ForumImageUrl = forum.ImageUrl, AuthorName = User.Identity.Name }; return(View(model)); }
public async Task <ActionResult <Post> > PostPost(CreatePostVM vm) { Post post = new Post { Text = vm.Text, AuditionId = vm.AuditionId, LikesCount = vm.Likes, PhotoId = vm.PhotoId }; post = await postService.Create(post); return(CreatedAtAction("GetPost", new { id = post.Id }, post)); }
private CreatePostVM initPostModel() { var model = new CreatePostVM(); model.Movie = new CreateMovieVM(); model.Movie.AvailableGenres = new List <SelectListItem>(); var availableGenres = _genrerepo.FindAll(); foreach (var g in availableGenres) { model.Movie.AvailableGenres.Add(new SelectListItem { Text = g.Name, Value = g.GenreId.ToString() }); } return(model); }
public IActionResult Create(CreatePostVM createPostModel) { if (!ModelState.IsValid) { return(View(createPostModel)); } var postModel = new PostModel() { AuthorUser = _userRepo.GetById(User.Id()), Title = createPostModel.Title, Body = createPostModel.Body, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; _postRepo.Create(postModel); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> CreatePost(CreatePostVM model) { var author = await currentUser.GetCurrentUserAsync(); var post = new Post() { Title = model.Title, Content = model.Content, Author = author, CreatedDate = DateTime.Now, Likes = 0 }; await db.Posts.AddAsync(post); await db.SaveChangesAsync(); return(RedirectToAction("LatestPosts", "Post")); }
public IActionResult Create(CreatePostVM model) { if (!ModelState.IsValid) { var return_model = initPostModel(); return(View(return_model)); } Post post = _mapper.Map <Post>(model); post.Owner = (ApplicationUser)_userManager.GetUserAsync(User).Result; post.DateCreated = DateTime.Now; post.Movie.Ratings.First().DateRated = DateTime.Now; post.Movie.Ratings.First().Rater = (ApplicationUser)_userManager.GetUserAsync(User).Result; if (model.Movie.Poster != null) { post.Movie.PosterPath = _posterservice.UploadImage(model.Movie.Poster); } else { post.Movie.PosterPath = "82edbb4a-e688-4d7d-9ce8-06356a837ca9_noposter.jpg"; } var textToCheck = post.Movie.Title + " " + post.Movie.LongDescription + " " + post.Movie.SortDescription; var isPorn = _pornDetectorService.IsPorn(post.Movie.PosterPath, textToCheck); if (isPorn) { var return_model = initPostModel(); ViewData["PornMessage"] = "You cannot upload p**n content!"; return(View(return_model)); } post.IsNew = true; _postrepo.Create(post); return(RedirectToAction(nameof(Index))); }
public async Task <IViewComponentResult> InvokeAsync(CreatePostVM model) { return(View(model)); }
public bool SubmitPost(CreatePostVM newPost) { _postService.CreateNewPost(newPost); _messageHub.Clients.All.SendAsync("sendToClient", newPost); return(true); }