public async Task <ActionResult <string> > AddPost([FromBody] AddPostViewModel value) { try { var post = new Post() { PostId = value.postId, Slug = value.Slug, MarkDown = value.MarkDown, Content = value.Content, CreateDate = DateTime.Now, Tags = value.Tags, Title = value.Title, UserId = this.User.Identity.Name }; var result = await _post.AddOrEdit(post); await _hubContext.Clients.All.SendAsync("News", "Kevin", "I posted an article"); return(Ok(new { result = result, Msg = "" })); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(Ok(new { result = false, Msg = ex.Message })); } }
public IActionResult AddPost(AddPostViewModel model, List <String> classTags) { try { if (ModelState.IsValid) { string classT = classTags != null?String.Join(",", classTags) : ""; string url = model.Title != null?String.Join(" ", model.Title) : "-"; Post post = new Post { Title = model.Title, Description = model.Description, Content = model.Content, Tags = classT, ApplicationUser = GetLoggedInUser(), IconUri = "https://image.freepik.com/free-vector/farmer-peasant-illustration-man-with-beard-spade-farmland_33099-575.jpg", IsDeleted = false, DateCreated = DateTime.Now, DateModified = DateTime.Now, PostUrl = url }; _postService.CreatePost(post); } } catch (Exception ex) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator." + ex); } return(RedirectToAction(nameof(Index))); }
public AddPostPage(AddPostViewModel model, IInternetConnectionChecker internetConnectionChecker) { InitializeComponent(); _model = model; _internetConnectionChecker = internetConnectionChecker; BindingContext = _model; }
public ActionResult Create(AddPostViewModel postModel) { if (ModelState.IsValid) { Category category = categoryService.GetCategoryByName(postModel.Category); var userId = User.Identity.GetUserId(); var user = this.userService.GetUserById(userId); var post = new Post() { Id = Guid.NewGuid(), Title = postModel.Title, ImageUrl = postModel.ImageUrl, Content = postModel.Content, Category = category, PostedBy = user }; this.postService.CreateNewPost(post.Title, post.ImageUrl, post.Category.CategoryName, post.Content, post.PostedBy); this.TempData["Notification"] = "You've uploaded successfully a new post"; } return(RedirectToAction("Index", "Post")); }
public string StatusUpdate(AddPostViewModel addPostViewModel) { string loggedInUser = User.Identity.Name; string result = _userDetailsRepository.AddPost(loggedInUser, addPostViewModel.post, addPostViewModel.privacy); return(result); }
public bool AddPost(AddPostViewModel addPostViewModel) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { var post = new Post { Id = addPostViewModel.Id, Body = addPostViewModel.Body, PublishedDate = addPostViewModel.PublishedDate, Title = addPostViewModel.Title, User = addPostViewModel.User, UserId = addPostViewModel.UserId }; context.Post.Add(post); context.SaveChanges(); dbContextTransaction.Commit(); return(true); } catch { dbContextTransaction.Rollback(); return(false); } } }
public void _Returns_View_WithModel( string cloud, string apiKey, string apiSecret, int postId) { //Arrange var model = new AddPostViewModel(); var mockedAuthProvider = new Mock <IAuthenticationProvider>(); var mockedPostService = new Mock <IPostService>(); var mockedViewModelFactory = new Mock <IViewModelFactory>(); mockedViewModelFactory.Setup(v => v.CreateAddPostViewModel(It.IsAny <Cloudinary>())).Returns(model); var mockedAcc = new CloudinaryDotNet.Account(cloud, apiKey, apiSecret); var mockedCloudinary = new Mock <Cloudinary>(mockedAcc); var postController = new PostController(mockedAuthProvider.Object, mockedPostService.Object, mockedViewModelFactory.Object, mockedCloudinary.Object); //Act var res = postController.Details(postId) as ViewResult; //Assert mockedPostService.Verify(s => s.GetPostById(postId), Times.Once); }
public AddPostPage() { InitializeComponent(); Post = new PostInsertModel(); BindingContext = _model = new AddPostViewModel(); }
public ActionResult AddPost(AddPostViewModel model) { model.CoverPhoto = this.WriteToFile(model.PhotoFile); _postService.Create(ModelMapper.ConvertToModel(model)); return(RedirectToAction(nameof(Index))); }
public virtual async Task <ActionResult> Add() { ViewData["CategoriesSelectList"] = new SelectList(await _postCategoryService.GetAll(), "Id", "Name"); var model = new AddPostViewModel(); return(View(model)); }
public ActionResult Update(AddPostViewModel postModel, string tags) { Post post = GetPost(postModel.Id); if (!IsAdmin) { return(RedirectToAction("Index")); } if (!ModelState.IsValid) { Post emptyPost = new Post(); return(View("edit", emptyPost)); } if (postModel.PostImageFile != null) { //upload a pic string fileName = Path.GetFileNameWithoutExtension(postModel.PostImageFile.FileName); string extension = Path.GetExtension(postModel.PostImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; postModel.PostImageUrl = "~/Images/Upload_Images/" + fileName; fileName = Path.Combine(Server.MapPath("~/Images/Upload_Images"), fileName); postModel.PostImageFile.SaveAs(fileName); post.PostImageUrl = postModel.PostImageUrl; Session["PostImage"] = postModel.PostImageFile; } //edit post.Title = postModel.Title; post.EditTime = DateTime.Now; post.Body = postModel.Body; post.Tags.Clear(); //to avoid null referenece exception tags = tags ?? string.Empty; //stringSplitOption : for removing empty array from splitting var tagNames = tags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var tagName in tagNames) { post.Tags.Add(GetTagFromDb(tagName)); } //Create if (postModel.Id == 0) { post.EditTime = null; post.Time = DateTime.Now; context.Posts.Add(post); } context.SaveChanges(); return(RedirectToAction("Details", new { id = post.Id })); }
public async Task <IActionResult> AddPost([FromBody] AddPostViewModel viewModel) { bool success = await _postService.AddPostAsync(viewModel.TopicId, viewModel.Message); return(Json(new { success, })); }
public IActionResult AddPost() { var post = new AddPostViewModel { User = testUser, UserId = testUser.Id }; return(View(post)); }
public virtual ActionResult Create() { var viewModel = new AddPostViewModel { AddedBy = _userManager.GetCurrentUser().UserName, CategoryList = _categoryService.GetAll() }; return(View(nameof(Create), viewModel)); }
public IActionResult AddPost(Guid forumId, Guid threadId) { var model = new AddPostViewModel { ThreadId = threadId, ForumId = forumId }; return(View(model)); }
public PostViewModel Add(AddPostViewModel viewModel) { var post = _mappingEngine.Map <Post>(viewModel); post.ViewNumber = 0; _posts.Add(post); _uow.SaveAllChanges(); return(Find(post.Id)); }
public ActionResult Create(AddPostViewModel post) { if (ModelState.IsValid) { postService.AddPost(Mapper.Map <Post>(post), post.UploadedImage); return(this.RedirectToAction(c => c.Index())); } return(View(Views.Create, post)); }
public async Task <IActionResult> StatusUpdate([FromForm] AddPostModel addPostModel) { AddPostViewModel addPostViewModel = new AddPostViewModel() { post = addPostModel.post, privacy = addPostModel.privacy }; string uri = $"{_configOptions.ApiBaseUrl}/api/UserDetailsApi/StatusUpdate"; string RegistrationStatus = await _httpHelper.PostAsync <AddPostViewModel, string>(uri, addPostViewModel); return(RedirectToAction("Index")); }
public async Task <IActionResult> AddPost(AddPostViewModel model) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; var success = await _postBll.AddPostAsync(model, userId); if (success) { ViewBag.ActionDone = "Post został dodany"; } return(base.View()); }
public virtual ActionResult Create(AddPostViewModel postVM) { if (!ModelState.IsValid) { return(View(nameof(Create), postVM)); } postVM.Body = postVM.Body.ToSafeHtml(); postVM.ExcerptText = postVM.ExcerptText.ToSafeHtml(); postVM.PostedByUserId = _userManager.GetCurrentUserId(); _postService.Add(postVM); return(RedirectToAction(nameof(Index))); }
public ActionResult AddPost(int id) { //Find the id of discussion to be posted in var discussion = _discussionService.GetDiscussionID(id); //Call on new model and get values outside of raw Post entity AddPostViewModel addPost = new AddPostViewModel(); addPost.DicussionName = discussion.Title; addPost.DiscussionId = discussion.Id; return(View(addPost)); }
public ActionResult AddPost() { using (var db = new DatabaseContext()) { ViewModels viewModel = new ViewModels(); AddPostViewModel addPost = new AddPostViewModel(); int userId = (User as ProjektIO.Auth.Principal).GetUserData().Id; Czlonkowie member = db.Czlonkowie.FirstOrDefault(p => p.IdUzytkownika == userId); addPost.Member = member; viewModel.AddPost = addPost; return(View(viewModel)); } }
public ActionResult Add(AddPostViewModel model) { if (ModelState.IsValid) { var userId = this.authenticationProvider.CurrentUserId; var post = this.postService.CreatePost(userId, model.Title, model.Description, model.PictureUrl, model.Category); return(RedirectToAction("Details", "Post", new { postId = post.PostId })); } model.Cloudinary = this.cloudinary; return(this.View(model)); }
public ActionResult Index() { var model = new AddPostViewModel() { Categories = Enumerable.Range(1, 5).Select(x => new SelectListItem { Value = x.ToString(), Text = "category " + x }), Post = new Post() }; return(View(model)); }
public IActionResult AddPost(AddPostViewModel model) { try { var post = _mapper.Map <Post>(model); _forumsRepository.InsertPost(post); _unitOfWork.Commit(); return(RedirectToAction(nameof(this.BrowseThreads), new { forumId = model.ForumId, pageIndex = 1, pageSize = 5 })); } catch { return(View()); } }
public virtual async Task <ActionResult> Add(AddPostViewModel postModel) { if (!ModelState.IsValid) { ViewData["CategoriesSelectList"] = new SelectList(await _postCategoryService.GetAll(), "Id", "Name"); return(View(postModel)); } var post = new DomainClasses.Post { PostedByUserId = User.Identity.GetUserId <int>() }; _mappingEngine.Map(postModel, post); if (postModel.Id.HasValue) { _postService.Edit(post); TempData["message"] = "پست مورد نظر با موفقیت ویرایش شد"; } else { _postService.Add(post); TempData["message"] = "پست جدید با موفقیت در سیستم ثبت شد"; } await _unitOfWork.SaveAllChangesAsync(); if (postModel.Id.HasValue) { LuceneIndex.ClearLucenePostIndexRecord(postModel.Id.Value); } LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel { PostId = post.Id, Title = post.Title, Image = post.Image, Description = post.Body.RemoveHtmlTags(), Category = await _postCategoryService.GetCategoryName(postModel.CategoryId.Value), SlugUrl = post.SlugUrl }); return(RedirectToAction(MVC.Post.Admin.ActionNames.Index)); }
public async Task <IActionResult> Create(AddPostViewModel model) { if (ModelState.IsValid) { var author = (await userManager.GetUserAsync(User)); var category = await this.categoryservice.FindCategoryAsync(model.CategoryId); var inspirator = await this.inspiratorService.FindInspiratorAsync(model.InspiratorId); await this.postsService.CreatePostAsync(author, category, inspirator, model.Quote); return(RedirectToAction(nameof(UserQuotes))); } return(View(model)); }
public IActionResult AddPost(AddPostViewModel post) { if (ModelState.IsValid) { post.PublishedDate = DateTime.Now; post.User = testUser; post.UserId = testUser.Id; if (_postService.AddPost(post)) { ViewBag.Message = "Post added successfully"; AspNetCoreBlogSample.Hubs.PostHub.FetchPost(); } } return(View()); }
public async Task <IActionResult> AddPost(AddPostViewModel model) { if (ModelState.IsValid) { var user = await userManager.FindByNameAsync(User.Identity.Name); var NewModel = new Post { Title = model.Title, Url = model.Url }; NewModel.User = user; redditDBService.AddPost(NewModel); } return(RedirectToAction("Index", "Home")); }
//GET: Forum/AddPost/{int} public ActionResult AddPost(int?ID) { if (ID == null) { return(View("Error")); } var db = new ApplicationDbContext(); var thread = db.Threads.Where(u => u.ThreadID == ID).FirstOrDefault(); var model = new AddPostViewModel { Thread = thread, ThreadID = (int)ID }; return(View(model)); }