예제 #1
0
        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));
        }
예제 #2
0
        public void CreateNewPost(CreatePostVM newPost)
        {
            Post createPost = _mapper.Map <Post>(newPost);

            dbContext.Posts.Add(createPost);
            dbContext.SaveChanges();
        }
예제 #3
0
        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
            }));
        }
예제 #4
0
        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 }));
        }
예제 #5
0
        // GET: Admin/Post
        public ActionResult Create()
        {
            CreatePostVM model = new CreatePostVM()
            {
                Categories = _categoryRepository.GetActive(),
                AppUsers   = _appUserRepository.GetDefault(x => x.Role != Role.Member)
            };

            return(View(model));
        }
예제 #6
0
        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
            });
        }
예제 #7
0
        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));
        }
예제 #8
0
        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));
        }
예제 #9
0
        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);
        }
예제 #10
0
        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)));
        }
예제 #11
0
        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"));
        }
예제 #12
0
        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)));
        }
예제 #13
0
 public async Task <IViewComponentResult> InvokeAsync(CreatePostVM model)
 {
     return(View(model));
 }
예제 #14
0
 public bool SubmitPost(CreatePostVM newPost)
 {
     _postService.CreateNewPost(newPost);
     _messageHub.Clients.All.SendAsync("sendToClient", newPost);
     return(true);
 }