Exemplo n.º 1
0
 public async Task <IActionResult> NewPost(PostViewModel model)
 {
     if (ModelState.IsValid)
     {
         await _ipost.AddPost(new Post()
         {
             UserId = signInManager.UserManager.GetUserAsync(User).Id.ToString(),
             Body   = model.Body,
             Title  = model.Title
         });
     }
     return(RedirectToAction("index", "home"));
 }
Exemplo n.º 2
0
 public async Task <IActionResult> UploadNewPost(IFormFile pic, string tags, string description, string title, string url)
 {
     if (pic != null)
     {
         var filename = Path.Combine(_he.WebRootPath, Path.GetFileName(pic.FileName));
         pic.CopyTo(new FileStream(filename, FileMode.Create));
         await _postService.AddPost(title, tags, description, "/" + Path.GetFileName(pic.FileName));
     }
     else if (url != null)
     {
         await _postService.AddPost(title, tags, description, url);
     }
     return(RedirectToAction("Index", "Gallery"));
 }
Exemplo n.º 3
0
        public ActionResult Add(PostViewModel postModel)
        {
            if (ModelState.IsValid)
            {
                var tags = _tagRepository.GetTagEntities(postModel.Tags.Split(',').ToList());
                _tagRepository.AddTags(tags);
                var postEntity = postModel.ToPostEntity(_tagRepository);
                postEntity.PostAddedDate  = DateTime.Now;
                postEntity.PostEditedDate = postEntity.PostAddedDate;
                postEntity.OwnerUserID    = GetUserId();

                if (string.IsNullOrEmpty(postEntity.PostUrl))
                {
                    postEntity.PostUrl = UniqueUrlHelper.FindUniqueUrl(_postRepository, postEntity.PostTitle, ItemEntryType);
                }

                var biltyPostUrl = BitlyUrlService.GetBiltyPostUrl(SettingsRepository, postEntity.PostUrl);
                if (biltyPostUrl != null)
                {
                    postEntity.BitlyUrl       = biltyPostUrl;
                    postEntity.BitlySourceUrl = postEntity.PostUrl;
                }

                var postId = _postRepository.AddPost(postEntity);

                if (postId > 0)
                {
                    return(RedirectToAction("Edit", new { postID = postId, newlyAdded = true }));
                }
            }
            postModel.Title          = SettingsRepository.BlogName;
            postModel.SharingEnabled = SettingsRepository.BlogSocialSharing;

            return(View(postModel));
        }
Exemplo n.º 4
0
        public IActionResult AddPost([FromForm] PostModel model)
        {
            var file     = HttpContext.Request.Form.Files.FirstOrDefault();
            var formData = Request.Form["formdata"];
            var pModel   = JsonConvert.DeserializeObject <PostModel>(formData);

            if (file != null)
            {
                var dir = Path.Combine(_env.WebRootPath, "Resource");

                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                var fileName = Guid.NewGuid().ToString() + "" + file.FileName + "" + Path.GetFileName(file.FileName);
                var filePath = Path.Combine(dir, fileName);
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    file.CopyToAsync(stream).GetAwaiter().GetResult();
                    stream.FlushAsync().GetAwaiter().GetResult();
                }

                pModel.ImageURL = fileName;
            }

            ipost.AddPost(pModel);
            return(Ok(HttpStatusCode.OK));
        }
Exemplo n.º 5
0
        public ActionResult Add(PostViewModel postModel)
        {
            if (ModelState.IsValid)
            {
                var postEntity = postModel.ToPostEntity(_tagRepository);
                postEntity.PostAddedDate  = DateTime.Now;
                postEntity.PostEditedDate = postEntity.PostAddedDate;
                postEntity.OwnerUserID    = GetUserId();

                if (string.IsNullOrEmpty(postEntity.PostUrl))
                {
                    postEntity.PostUrl = UniqueUrlHelper.FindUniqueUrl(_postRepository, postEntity.PostTitle, ItemEntryType);
                }

                var pageID = _postRepository.AddPost(postEntity);

                if (pageID > 0)
                {
                    return(RedirectToAction("Edit", new { postID = pageID, newlyAdded = true }));
                }
            }
            postModel.Title          = SettingsRepository.BlogName;
            postModel.SharingEnabled = SettingsRepository.BlogSocialSharing;

            return(View(postModel));
        }
Exemplo n.º 6
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 }));
        }
 public bool AddPost(PostAddRequest request)
 {
     try
     {
         post.AddPost(request);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 8
0
        public async Task <ActionResult> AddPost(PostViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var post = await _post.AddPost(model);

            if (post != null)
            {
                return(RedirectToAction("GetPostBySlug", new { slug = post.Slug }));
            }
            return(View(model));
        }
        public async Task <IActionResult> AddPost(NewPostModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = _userManager.GetUserId(User);
                var user   = _userManager.FindByIdAsync(userId).Result;
                var post   = BuildPost(model, user);
                model.ForumName = post.Forum.Title;
                post.User.Rating++;
                await _postService.AddPost(post);

                return(RedirectToAction("Index", "Post", new { id = post.Id }));
            }
            return(Create(model.ForumId));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> AddPost(NewPostModel model)
        {
            var userId = _userManager.GetUserId(User);
            //_userManager is a built in service. From
            // Microsoft.AspNetCore.Identity; - Provides API to interact with Users in
            //Data store.
            //User is a built in Object that contains Current User info.
            var user = await _userManager.FindByIdAsync(userId);

            var post = BuildPost(model, user);

            await _postService.AddPost(post);

            await _userService.UpdateUserRating(userId, typeof(Post));

            return(RedirectToAction("Index", "Post", new { postId = post.Id }));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> AddPost(NewPostModel model)
        {
            var userId   = _userManager.GetUserId(User);
            var user     = _userManager.FindByIdAsync(userId).Result;
            var forum    = _forumService.GetById(model.ForumId);
            var imageUri = "";

            if (model.PostImageUpload != null && model.PostImageUpload.Length != 0)
            {
                //var blockBlob = UploadForumImage(model.ImageUpload);
                //imageUri = blockBlob.Uri.AbsoluteUri;
                string pathRoot       = _environment.WebRootPath;
                string path_to_Images = pathRoot + "\\Images\\posts\\" + model.PostImageUpload.FileName;

                using (var stream = new FileStream(path_to_Images, FileMode.Create))
                {
                    await model.PostImageUpload.CopyToAsync(stream);
                }

                imageUri = "/Images/posts/" + model.PostImageUpload.FileName;
            }

            Post post = new Post
            {
                Title    = model.Title,
                Content  = model.Content,
                Created  = DateTime.Now,
                User     = user,
                Forum    = forum,
                ImageUrl = imageUri
            };

            await _postService.AddPost(post);// Block The Current Thread Untill the task is Complete

            await _userService.IncrementUserRating(userId, typeof(Post));

            return(RedirectToAction("Index", "Post", new { post.Id }));
        }
Exemplo n.º 12
0
 public static int AddPost(PostInfo Model)
 {
     CacheHelper.Remove(cacheKey);
     return(dal.AddPost(Model));
 }
Exemplo n.º 13
0
        public async Task <IActionResult> Edit(Post post)
        {
            await _post.AddPost(post);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 14
0
 public void AddPost(Post post)
 {
     ipost.AddPost(post);
 }
Exemplo n.º 15
0
 public int AddPost(PostModel post)
 {
     return(ipost.AddPost(post));
 }