コード例 #1
0
        public IActionResult AddPost()
        {
            var model = new AddPostVM();

            model.Categories = _postsRepository.GetAllCategories();
            //var model = _postsRepository.GetAllPosts();
            return(View(model));
        }
コード例 #2
0
 //Add new category
 public void AddNewCategory(AddPostVM viewModel)
 {
     _context.Category.Add(new Category
     {
         CategoryName = viewModel.NewCategory
     });
     _context.SaveChanges();
 }
コード例 #3
0
        // GET: Admin/Post
        public ActionResult Create()
        {
            AddPostVM model = new AddPostVM()
            {
                Categories = _categoryRepo.GetActive(),
                AppUsers   = _appUserRepo.GetDefault(x => x.Role != Role.Member)
            };

            return(View(model));
        }
コード例 #4
0
        // 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));
        }
コード例 #5
0
 public int AddPost(AddPostVM model)
 {
     if (ModelState.IsValid)
     {
         return(lessonOperation.AddPost(model));
     }
     else
     {
         return(0);
     }
 }
コード例 #6
0
ファイル: PostMappers.cs プロジェクト: lexTutor/BLOGITWebApp
        /// <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);
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
 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"));
     }
 }
コード例 #9
0
        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);
            }
        }
コード例 #10
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 }));
            }
        }
コード例 #11
0
        //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&amp;fs=0&amp;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();
        }
コード例 #12
0
        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));
        }