Exemple #1
0
        public IHttpActionResult Post(ArticleRequestModel model)
        {
            var newArticle = this.articleService.AddArticle(model.Title, model.Content, model.Category, model.Tags);
            var result     =
                this.articleService.GetArticleById(newArticle.Id).ProjectTo <ArticleResponseModel>().FirstOrDefault();

            return(this.Ok(result));
        }
Exemple #2
0
        public async Task <IActionResult> UpdateArticle(string id, [FromBody] ArticleRequestModel model)
        {
            try
            {
                var result = await _articleService.UpdateArticle(id, model);

                return(Ok(result));
            }
            catch (System.Exception ex)
            {
                return(UnprocessableEntity($"{"Hata Oluştu !" + ex.Message}"));
            }
        }
        public async Task <int> Create([FromForm] ArticleRequestModel articleRequestModel)
        {
            var userId    = this.User.GetId();
            var articleId = await this.articleService.CreateArticle(articleRequestModel, userId);

            var galleryObjectMapper = new GalleryMapperObject
            {
                ArticleId = articleId
            };

            await this.galleryService.ObtainMultipleFiles(articleRequestModel.Gallery, galleryObjectMapper);

            return(articleId);
        }
        public async Task <TableDataModel> LoadDataAsync(ArticleRequestModel model)
        {
            string conditions = "where IsDeleted=0 ";//未删除的

            if (!model.Key.IsNullOrWhiteSpace())
            {
                conditions += "and Title like '%@Key%' ";
            }
            var list = (await _repository.GetListPagedAsync(model.Page, model.Limit, conditions, "Id desc", model)).ToList();

            return(new TableDataModel
            {
                count = await _repository.RecordCountAsync(conditions, model),
                data = _mapper.Map <List <ArticleListModel> >(list),
            });
        }
Exemple #5
0
        public async Task <Article> UpdateArticle(string id, ArticleRequestModel model)
        {
            var article = await GetArticleById(id);

            await ValidationArticle(model);

            article.UserId     = model.UserId;
            article.UpdateDate = DateTime.Now;
            article.Status     = (byte)StatusType.Active;

            article.Description = model.Description;
            article.CategoryId  = model.CategoryId;
            article.MainTitle   = model.MainTitle;
            article.Title       = model.Title;

            await Update(article);

            return(article);
        }
Exemple #6
0
        public async Task <int> CreateArticle(ArticleRequestModel articleRequestModel, string userId)
        {
            var article = new Article
            {
                Title     = articleRequestModel.Title,
                Body      = articleRequestModel.Body,
                CreatedOn = articleRequestModel.CreatedOn,
                TagsJson  = articleRequestModel.TagsJson,
                UserId    = userId
            };

            this.personalBlogDbContext
            .Article
            .Add(article);

            await this.personalBlogDbContext.SaveChangesAsync();

            return(article.Id);
        }
Exemple #7
0
        public async Task <Article> CreateArticle(ArticleRequestModel model)
        {
            var article = new Article();

            await ValidationArticle(model);

            article.Id         = ObjectId.GenerateNewId().ToString();
            article.UserId     = model.UserId;
            article.CreateDate = DateTime.Now;
            article.Status     = (byte)StatusType.Active;

            article.Description = model.Description;
            article.CategoryId  = model.CategoryId;
            article.MainTitle   = model.MainTitle;
            article.Title       = model.Title;

            await Insert(article);

            return(article);
        }
Exemple #8
0
        public async Task <bool> ValidationArticle(ArticleRequestModel model)
        {
            var customer = await _userService.GetUserById(model.UserId);

            if (customer == null)
            {
                throw new NotificationException("Kullanıcı bilgisi bulunamadı.");
            }
            else if (customer.UserType == (byte)UserType.Reader)
            {
                throw new NotificationException("Yazar olmayan kullanıcı makale girdisi yapamaz.");
            }

            var category = await _categoryService.GetCategoryById(model.CategoryId);

            if (customer == null)
            {
                throw new NotificationException("Kategori bilgisi bulunamadı.");
            }
            return(true);
        }
        public IHttpActionResult Post(ArticleRequestModel article)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            var currentUserId = this.User.Identity.GetUserId();

            var articleToAdd = new Article
            {
                AuthorId    = currentUserId,
                Category    = this.categories.GetByName(article.Category),
                Content     = article.Content,
                DateCreated = DateTime.Now,
                Title       = article.Title,
                Tags        = this.tags.GetCollection(article.Tags)
            };

            this.articlesService.Add(articleToAdd);

            return(this.Ok());
        }
Exemple #10
0
 public async Task <string> LoadData([FromQuery] ArticleRequestModel model)
 {
     return(JsonHelper.ObjectToJSON(await _service.LoadDataAsync(model)));
 }
        public IHttpActionResult Post(ArticleRequestModel model)
        {
            var newArticle = this.articleService.AddArticle(model.Title, model.Content, model.Category, model.Tags);
            var result =
                this.articleService.GetArticleById(newArticle.Id).ProjectTo<ArticleResponseModel>().FirstOrDefault();

            return this.Ok(result);
        }