Esempio n. 1
0
        public async Task <ActionResult <Guid> > PostArticle([FromBody] CreateArticleViewModel createArticle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var tags = createArticle.Tags.Trim();

            var article = new Article()
            {
                BriefContent      = createArticle.FullContent.Length > 200 ? createArticle.FullContent.Substring(0, 200) + "..." : "",
                CategoryArticleId = Guid.Empty, //No category
                CreatedByName     = createArticle.CreatedBy,
                CreatedDate       = DateTime.Now,
                Ext           = tags,
                FullContent   = createArticle.FullContent,
                Image         = createArticle.Image,
                IsDeleted     = false,
                IsHot         = false,
                IsVisible     = true,
                Title         = createArticle.Title,
                UpdatedByName = createArticle.CreatedBy,
                UpdatedDate   = DateTime.Now
            };

            return(Ok(await _articleService.CreateArticle(article)));
        }
Esempio n. 2
0
        public async Task TestGetByIdMethod()
        {
            MapperInitializer.InitializeMapper();
            var context           = ApplicationDbContextInMemoryFactory.InitializeContext();
            var articleRepository = new EfDeletableEntityRepository <Article>(context);

            var articlesService = new ArticlesService(articleRepository);

            var articlesId = new List <int>();

            var inputModel = new CreateArticleViewModel
            {
                ImgUrl  = $"TT{2}{2 * 2}asd",
                Content = $"Ten{2}{2 * 2}",
                Title   = $"Article{2}",
            };
            var id = await articlesService.CreateAsync(inputModel, "2");

            var articleId = articleRepository.All().First(x => x.Id == id);

            var article = articlesService.GetById <IndexArticleViewModel>(id);

            Assert.True(article != null);

            Assert.True(article.Id == id);
        }
Esempio n. 3
0
        public async Task <ActionResult> Create(CreateArticleViewModel createArticle)
        {
            createArticle.AppUserId = (await UserManager.GetUserAsync(User)).Id;
            await Mediator.Send(createArticle);

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 4
0
        public async Task <int> CreateAsync(CreateArticleViewModel input, string userId)
        {
            if (string.IsNullOrEmpty(input.ImgUrl) || string.IsNullOrWhiteSpace(input.ImgUrl))
            {
                throw new ArgumentNullException(NullOrEmptyImgURLErrorMessage);
            }
            if (string.IsNullOrEmpty(input.Title) || string.IsNullOrWhiteSpace(input.Title))
            {
                throw new ArgumentNullException(NullOrEmptyTitleErrorMessage);
            }
            if (string.IsNullOrEmpty(input.Content) || string.IsNullOrWhiteSpace(input.Content))
            {
                throw new ArgumentNullException(NullOrEmptyContentErrorMessage);
            }

            var article = new Article
            {
                ImgUrl  = input.ImgUrl,
                Title   = input.Title,
                Content = input.Content,
                UserId  = userId,
            };

            await this.articleRepository.AddAsync(article);

            await this.articleRepository.SaveChangesAsync();

            return(article.Id);
        }
Esempio n. 5
0
        public async Task <IActionResult> CreateArticle(CreateArticleViewModel viewModel)
        {
            if (viewModel.CreateArticleData.Title == null ||
                viewModel.CreateArticleData.Content == null ||
                viewModel.CreateArticleData.AuthorEmail == null ||
                viewModel.CreateArticleData.AuthorNickname == null ||
                viewModel.CreateArticleData.Tags == null)
            {
                _articleSubmitMessage = "Can't submit article, invalid input...";

                ViewData["Message"] = _articleSubmitMessage;

                return(View());
            }

            await _articleService.AddArticle(viewModel.CreateArticleData);

            var emailViewModel = new EmailViewModel
            {
                To      = viewModel.CreateArticleData.AuthorEmail,
                IsHtml  = false,
                Subject = "Article added...",
                Content = $"Hi { viewModel.CreateArticleData.AuthorNickname }, " +
                          $"we've sent you this confirmation email so that we can verify it's you"
            };

            await emailViewModel.SendEmail(_configuration);

            _articleSubmitMessage = "Article was submitted successfuly";

            ViewData["Message"] = _articleSubmitMessage;

            return(View());
        }
Esempio n. 6
0
        public CreateArticleViewModel CreateArticleViewModel_Edit(Article article)
        {
            var model = new CreateArticleViewModel();

            if (article != null)
            {
                //model.Author = await _userRepository.Get(article.AuthorId);
                //model.Category = new CategoryViewModel(article.Category);
                //Category c = _categoryRepository.Get(article.CategoryId);
                model.Category = article.CategoryId;
                model.Content  = article.Content;
                //model.Created = article.Created ?? DateTime.Now;
                //model.Edited = article.Edited ?? DateTime.Now;
                model.Id      = article.Id;
                model.IsDraft = article.IsDraft == 1 ? true : false;
                //model.Likes = article.Likes;
                model.PublishEndDate   = article.PublishEndDate ?? DateTime.Now;
                model.PublishStartDate = article.PublishStartDate ?? DateTime.Now.AddYears(5);
                model.Title            = article.Title;
                model.Tags             = string.Join(",", article.ArticleTags.Select(at => at.Tag.Name).ToArray());
                //model.Attachments = article.Attachments.Select(t => new AttachmentViewModel(t, _actionContextAccessor)).ToList();
                model.Attachments = article.Attachments.Select(t => new AttachmentViewModel(t, _httpContextAccessor)).ToList();
                model.SefName     = article.SefName;
            }

            return(model);
        }
Esempio n. 7
0
        public async Task <IActionResult> CreateNewAsync(
            CreateArticleViewModel viewModel,
            CancellationToken cancellationToken)
        {
            var draft = _newsFactory.CreateArticleDraft();

            _mapper.Map(viewModel, draft);

            var validationResult = draft.Validate();

            if (!validationResult.IsValid)
            {
                foreach (var error in validationResult.Errors)
                {
                    ModelState.AddModelError(error.Summary, error.Details);
                }

                return(BadRequest(ModelState));
            }

            var createdArticle = await _articlesService.PublishArticleAsync(draft, cancellationToken);

            return(CreatedAtRoute(
                       RouteNames.GetByIdRoute,
                       new { articleId = createdArticle.Id },
                       createdArticle));
        }
Esempio n. 8
0
        public ActionResult Create(CreateArticleViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var userId  = User.Identity.GetUserId();
            var author  = _context.Authors.GetAuthorByUserId(userId);
            var article = new Article();

            article.Id        = Guid.NewGuid().ToString();
            article.Title     = model.Title;
            article.TopicId   = model.TopicId;
            article.Content   = model.Content;
            article.AuthorId  = author.Id;
            article.CreatedAt = DateTime.Now;
            article.UpdatedAt = DateTime.Now;

            var thumnail = FileController.SaveFile(model.ArticlesImage);

            article.Thumbnail = thumnail.Path;
            _context.Articles.Add(article);
            _context.Complete();
            return(RedirectToAction("Index"));
        }
Esempio n. 9
0
        public ActionResult Create([Bind("Id,Title,Content,IsDraft,PublishStartDate,PublishEndDate,SefName,Category,Tags")] CreateArticleViewModel model)
        {
            try
            {
                //ModelState.Remove("Category.Name");
                //ModelState.Remove("Category.SefName");
                if (ModelState.IsValid)
                {
                    string currentUser = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
                    var    article     = _articleFactory.CreateArticleFromViewModel_Create(model, currentUser);

                    var id = _articleRepository.Add(article, model.Tags, currentUser);
                    if (article.IsDraft == 0)
                    {
                        //KbVaultLuceneHelper.AddArticleToIndex(article);
                        _lucene.AddArticleToIndex(article);
                    }

                    //vrati se
                    //ShowOperationMessage(UIResources.ArticleCreatePageCreateSuccessMessage);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ModelState.AddModelError("Exception", ex.Message);
            }

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(CreateArticleViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            int newArticleId = ArticleService.Create(model);

            //images
            if (model.Images != null)
            {
                int existingImages = 0;

                var imageUrls = await this.ImageService.UploadImages(model.Images.ToList(), existingImages,
                                                                     GlobalConstants.ARTICLE_IMAGE_PATH_TEMPLATE, newArticleId);

                this.ArticleService.AddImageUrls(newArticleId, imageUrls);
            }
            //videos
            if (model.Videos != null)
            {
                int existingVideos = 0;

                var videoUrls = await this.VideoService.UploadVideos(model.Videos.ToList(), existingVideos,
                                                                     GlobalConstants.ARTICLE_VIDEO_PATH_TEMPLATE, newArticleId);

                this.ArticleService.AddVideoUrls(newArticleId, videoUrls);
            }

            return(View());
        }
Esempio n. 11
0
 public PartialViewResult AddKeyword(CreateArticleViewModel model)
 {
     try
     {
         if (!string.IsNullOrEmpty(model.Keyword))
         {
             var keyword = model.Keyword.ToLower().Trim();
             if (!string.IsNullOrEmpty(keyword) && !model.Keywords.Contains(keyword))
             {
                 model.Keywords.Add(keyword);
             }
             else
             {
                 ModelState.AddModelError("Keyword", "Ключовата дума вече е добавена към тази статия");
             }
         }
         else
         {
             ModelState.AddModelError("Keyword", "Невалидна стойност за ключова дума");
         }
     }
     catch (Exception ex)
     {
         //todo: save error in db
     }
     model.Keyword = null;
     return(PartialView("_AllKeywords", model));
 }
Esempio n. 12
0
        public async Task TestGetArticlesByPageMethod()
        {
            var context           = ApplicationDbContextInMemoryFactory.InitializeContext();
            var articleRepository = new EfDeletableEntityRepository <Article>(context);

            var articlesService = new ArticlesService(articleRepository);


            for (int i = 0; i < 10; i++)
            {
                var inputModel = new CreateArticleViewModel
                {
                    ImgUrl  = $"TT{i}{i * 2}asd",
                    Content = $"Ten{i}{i * 2}",
                    Title   = $"Article{i}",
                };
                await articlesService.CreateAsync(inputModel, i.ToString());
            }
            var result1 = articlesService.GetArticlesByPage <IndexArticleViewModel>(5, 5);
            var result2 = articlesService.GetArticlesByPage <IndexArticleViewModel>(5, 0);

            Assert.Equal(5, result2.Count());

            Assert.Equal(5, result1.Count());
        }
Esempio n. 13
0
        public ViewResult CreateArticle(int ArtId = 0)
        {
            CreateArticleViewModel model = new CreateArticleViewModel();

            if (ArtId != 0)
            {
                Article article = repos.Articles.FirstOrDefault(a => a.PageId == ArtId);
                if (article != null)
                {
                    model.Name      = article.Title;
                    model.Content   = article.Content;
                    model.ArticleID = article.PageId;
                    model.Author    = article.Author;
                }
            }

            if (model.ArticleID != 0 && model.Author != CurrentUser)
            {
                return(View("Error", new List <string>()
                {
                    "Вы не обладаете правами на редактирование данной статьи."
                }));
            }
            return(View(model));
        }
Esempio n. 14
0
        public int Create(CreateArticleViewModel model)
        {
            var article = Mapper.Map <Article>(model);

            this.db.Articles.Add(article);
            this.db.SaveChanges();
            return(article.Id);
        }
Esempio n. 15
0
        public ActionResult Create()
        {
            var model = new CreateArticleViewModel
            {
                Topics = _context.Topics.GetAll().ToList()
            };

            return(View(model));
        }
        public IActionResult CreateArticle()
        {
            var model = new CreateArticleViewModel
            {
                Authors = this.CreateAuthorsSelectListItem()
            };

            return(View(model));
        }
Esempio n. 17
0
        public IActionResult CreateArticle()
        {
            var viewModel = new CreateArticleViewModel()
            {
                Cloudinary = this.cloudinaryService.GetCloudinaryInstance()
            };

            return(this.View(viewModel));
        }
Esempio n. 18
0
        public ActionResult Create()
        {
            var categories = CategorySelectList();
            var model      = new CreateArticleViewModel
            {
                CategoriesList = categories.ToList()
            };

            return(View(model));
        }
Esempio n. 19
0
        // GET: Blog/Create
        public ActionResult CreateArticle()
        {
            var keywords = this.keywordsService.GetAll().ToList();

            var model = new CreateArticleViewModel()
            {
                AllKeywords = keywords.Select(x => x.Content).ToList()
            };

            return(View(model));
        }
Esempio n. 20
0
        //2408
        public CreateArticleViewModel CreateArticleViewModelWithDefaultValues()
        {
            var model = new CreateArticleViewModel
            {
                PublishStartDate = DateTime.Now.Date,
                PublishEndDate   = DateTime.Now.AddYears(5).Date,
                //Categories = _context.Categories.ToList()
            };

            return(model);
        }
Esempio n. 21
0
        public IActionResult Create(CreateArticleViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            this.articles.Create(model.Title, model.Content, User.Identity.Name);

            return(RedirectToAction(nameof(All)));
        }
 public ActionResult CreateArticle(CreateArticleViewModel createArticleViewModel)
 {
     if (ModelState.IsValid)
     {
         var userId = Guid.Parse(Session["loginUserId"].ToString());
         new ArticleBLL().CreateArticle(createArticleViewModel.Titile, createArticleViewModel.Content, createArticleViewModel.CategoryIds, userId);
         return(RedirectToAction("ArticleList"));
     }
     ModelState.AddModelError("", "failed");
     return(View(createArticleViewModel));
 }
Esempio n. 23
0
        public IActionResult CreateArticle(CreateArticleViewModel createArticleViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(createArticleViewModel));
            }

            this.BlogService.CreateArticle(createArticleViewModel);

            return(RedirectToAction("Success", "Home", new { area = "" }));
        }
Esempio n. 24
0
        public async Task <ActionResult> CreateArticle(CreateArticleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userid = Guid.Parse(Session["userid"].ToString());
                await new ArticleManager().CreateArticle(model.Title, model.Content, model.CategoryIds, userid);
                return(RedirectToAction("ArticleList"));
            }

            ModelState.AddModelError("", "添加失败");
            return(View());
        }
        public async Task <ArticleViewModel> Create(CreateArticleViewModel model, string hashUser)
        {
            var user = await _user.GetByHash(hashUser);

            var data = new Article();

            data.IdUser        = user.Id;
            data.PublishedDate = DateTime.Now;
            data.Text          = model.Text;
            data.Title         = model.Title;

            return(_mapper.Map <ArticleViewModel>(await _article.Add(data)));
        }
Esempio n. 26
0
        public async Task <ActionResult> CreateArticle(CreateArticleViewModel model)
        {
            var userId = Guid.Parse(Session["userId"].ToString());//获取用户id

            if (ModelState.IsValid)
            {
                await new ArticleManager().CreateArticle(model.Title, model.Content, model.CategoryIds, userId);
                return(RedirectToAction(nameof(ArticleList)));
            }
            ModelState.AddModelError("", "添加失败");
            ViewBag.CategoryIds = await new ArticleManager().GetAllCategories(userId);
            return(View(model));//添加失败把数据返回
        }
Esempio n. 27
0
        public IActionResult CreateArticle(CreateArticleViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(viewModel));
            }

            Article articleModel = mapper.Map <Article>(viewModel);

            this.BlogService.CreateArticle(articleModel);

            return(RedirectToAction("Success", "Home", new { area = "" }));
        }
        public IActionResult CreateArticle(CreateArticleViewModel vm)
        {
            var article2 = _articuloTipoManager.Get();

            if (ModelState.IsValid)
            {
                var article = new Articulo
                {
                    IdTipo      = vm.TypeId,
                    NroSerie    = vm.SerialNumber,
                    IdLote      = vm.LotId,
                    Descripcion = vm.Description,
                    Precio      = vm.Price
                };

                _articuloManager.Save(article);

                return(RedirectToAction("Index", new { lotId = article.IdLote }));
            }
            else
            {
                var typeList = new List <SelectListItem>();

                foreach (var item in article2)
                {
                    typeList.Add(new SelectListItem {
                        Text = item.Descripcion, Value = item.Id.ToString()
                    });
                }
                vm.Types = typeList;

                return(View(vm));
            }

            //if (ModelState.IsValid)
            //{
            //    var article = new Articulo
            //    {
            //        IdTipo = vm.TypeId,
            //        NroSerie = vm.SerialNumber,
            //        IdLote = vm.LotId,
            //        Descripcion = vm.Description,
            //        Precio = vm.Price
            //    };

            //    _articuloManager.Save(article);

            //    return RedirectToAction("Index", new { lotId = article.IdLote });
            //}
            //return View(vm);
        }
        public IActionResult CreateArticle(int LotId, int ArticleId)
        {
            var article  = _loteManager.Get();
            var article2 = _articuloTipoManager.Get();
            var article3 = _articuloManager.Get();


            if (article.Any(x => x.Id == LotId))
            {
                var model = new CreateArticleViewModel();

                model.LotId = LotId;
                var typeList = new List <SelectListItem>();

                foreach (var item in article2)
                {
                    typeList.Add(new SelectListItem {
                        Text = item.Descripcion, Value = item.Id.ToString()
                    });
                }
                model.Types = typeList;

                if (ArticleId != 0)
                {
                    var item = article3.FirstOrDefault(x => x.Id == ArticleId);

                    if (article3 != null)
                    {
                        model.Price        = item.Precio;
                        model.SerialNumber = item.NumeroSerie;
                        model.Description  = item.Descripcion;
                        model.TypeId       = item.Tipo.Id;
                    }
                    else
                    {
                        return(RedirectToAction("Index", new { LotId = LotId }));
                    }
                }
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index", new { LotId = LotId }));
            }
            //return View(new CreateArticleViewModel()
            //{
            //    Types = _articuloTipoManager.Get().Select(x => new SelectListItem { Text = x.Descripcion, Value = x.Id.ToString() }).ToList()
            //});
        }
Esempio n. 30
0
        public ActionResult Edits(String id)
        {
            var article = _context.Articles.Get(id);
            var model   = new CreateArticleViewModel
            {
                Id        = article.Id,
                Title     = article.Title,
                Content   = article.Content,
                TopicId   = article.TopicId,
                ImageName = article.Thumbnail,
                Topics    = _context.Topics.GetAll().ToList()
            };

            return(View(model));
        }