コード例 #1
0
ファイル: ArticlesController.cs プロジェクト: kevmcivor/kpmg
        public async Task <IActionResult> UpdateArticleAsync([FromBody] ArticleUpdateDto newsArticleUpdateDTO)
        {
            if (newsArticleUpdateDTO == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var article = _mapper.Map <Article>(newsArticleUpdateDTO);
                article.Author = _mapper.Map <Author>(User);

                await _repository.Update(article);
            }
            catch (Exception ex)
            {
                //log exception
                return(BadRequest());
            }

            return(NoContent());
        }
コード例 #2
0
ファイル: ArticlesController.cs プロジェクト: umon/ArticleApi
        public async Task <IActionResult> Put(int id, ArticleUpdateDto model)
        {
            if (id != model.Id)
            {
                return(BadRequest());
            }

            var article = await articleRepository.GetById(model.Id);

            if (article == null)
            {
                return(NotFound());
            }

            mapper.Map(model, article);
            article.UpdatedDate = DateTime.Now;

            articleRepository.Update(article);

            if (await articleRepository.SaveChanges())
            {
                return(Ok(article));
            }

            return(StatusCode(304));
        }
コード例 #3
0
        public ActionResult UpdateArticle(int id, ArticleUpdateDto articleUpdateDto)
        {
            var articleModelFromRepo = _repository.GetArticleById(id);

            var processedData = new ArticleCreateDto
            {
                Image         = articleUpdateDto.Image,
                Content       = WebUtility.HtmlEncode(articleUpdateDto.Content),
                Name          = articleUpdateDto.Name,
                ContentIntro  = articleUpdateDto.ContentIntro,
                AuthorImg     = articleModelFromRepo.AuthorImg,
                AuthorName    = articleModelFromRepo.AuthorName,
                DateofPublish = articleModelFromRepo.DateofPublish,
                AuthorId      = articleModelFromRepo.AuthorId
            };

            if (articleModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(processedData, articleModelFromRepo);
            _repository.UpdateArticle(articleModelFromRepo);
            _repository.SaveChanges();

            return(Ok(articleModelFromRepo));
        }
コード例 #4
0
        public async Task <ArticleDto> UpdateAsync(ArticleUpdateDto articleUpdateDto)
        {
            var article = await _bus.Send(new GetArticleByIdQuery(articleUpdateDto.Id));

            var articleToUpdate = new Article
            {
                Id      = article.Id,
                Content = articleUpdateDto.Content,
                Tokens  = _articleSimilarityService.Tokenize(articleUpdateDto.Content),

                CreatedTs = article.CreatedTs
            };

            var articleUpdated = await _bus.Send(new UpdateArticleCommand { Article = articleToUpdate });

            await _bus.Publish(new ArticleUpdatedEvent
            {
                ArticleOld = article,
                ArticleNew = articleUpdated
            });

            return(new ArticleDto
            {
                Id = articleUpdated.Id,
                Content = articleUpdated.Content,
                CreatedTs = articleUpdated.CreatedTs,
                UpdatedTs = articleUpdated.UpdatedTs,

                DuplicateIds = await _articleSimilarityService.FindDuplicatesAsync(articleUpdated)
            });
        }
コード例 #5
0
ファイル: ArticlesController.cs プロジェクト: slon2k/kpma-2
        public async Task <IActionResult> PutArticle(int id, ArticleUpdateDto articleUpdateDto)
        {
            var article = await _context.Articles.FindAsync(id);

            if (article == null)
            {
                return(NotFound());
            }

            _context.Entry(article).State = EntityState.Modified;

            _mapper.Map(articleUpdateDto, article);

            try
            {
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #6
0
 public bool UpdateArticle(ArticleUpdateDto form)
 {
     try
     {
         article = articleContext.Article.Where(x => x.Id == form.Id).FirstOrDefault();
         if (article != null)
         {
             article.CategoryId            = form.CategoryId;
             article.Content               = form.Content;
             article.Title                 = form.Title;
             article.LastModifiedIpAddress = _accessor.HttpContext.Connection.RemoteIpAddress.ToString();
             article.LastModifiedDateTime  = System.DateTime.Now;
             articleContext.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (System.Exception)
     {
         return(false);
     }
 }
コード例 #7
0
        public async Task UpdateArticle(ArticleUpdateDto updateDto)
        {
            var initialArticle = await _repository.GetById(updateDto.Id, a => a.Topic, a => a.Writer, a => a.Writer.User);

            var updatedArticle = _mapper.Map(updateDto, initialArticle);

            await _repository.Update(updatedArticle);
        }
        private Article MapToArticle(ArticleUpdateDto articleUpdateDto)
        {
            var articleDto = articleUpdateDto.ArticleDto;
            var writerDto  = articleUpdateDto.WriterDto;
            var article    = _mapper.Map <Article>(articleDto);

            article.Writer = _writerBll.FindWriter(writerDto.Name, writerDto.Password);
            return(article);
        }
コード例 #9
0
        public async Task <IResult> Update(ArticleUpdateDto articleUpdateDto, string modifiedByName)
        {
            var article = _mapper.Map <Article>(articleUpdateDto);

            article.ModifiedByName = modifiedByName;
            await _unitOfWork.Articles.UpdateAsync(article).ContinueWith(t => _unitOfWork.SaveAsync());

            return(new Result(resultStatus: ResultStatus.Success, $"{articleUpdateDto.Title} başlıklı makale güncellenmiştir."));
        }
コード例 #10
0
        public IResult Update(ArticleUpdateDto articleUpdateDto, string modifeidByName)
        {
            var article = _mapper.Map <Article>(articleUpdateDto);

            article.ModifiedByName = modifeidByName;
            article.ModifiedDate   = DateTime.Now;
            _unitOfWork.Articles.Update(article);
            _unitOfWork.Save();
            return(new Result(ResultStatus.Success, $"{articleUpdateDto.Title} başlıklı makale başarı ile güncellenmiştir"));
        }
コード例 #11
0
        public async Task <IResult> Update(ArticleUpdateDto articleUpdateDto, string modifiedByName)
        {
            var article = _mapper.Map <Article>(articleUpdateDto);

            article.ModifiedByName = modifiedByName;
            await _unitOfWork.Articles.UpdateAsync(article);

            await _unitOfWork.SaveAsync();

            return(new Result(ResultStatus.Success, $"{articleUpdateDto.Title} Article successfully updated."));
        }
コード例 #12
0
        public async Task <IResult> Update(ArticleUpdateDto articleUpdateDto, string modifiedByName)
        {
            var article = _mapper.Map <Article>(articleUpdateDto);

            article.ModifiedByName = modifiedByName;

            await _unitOfWork.Articles.UpdateAsync(article);//.ContinueWith(t=>_unitOfWork.SaveAsync());Hemen ardından save işlemi yapılması için kullandık

            await _unitOfWork.SaveAsync();

            return(new Result(ResultStatus.Success, $"{article.Title} başlıklı makale başarıyla güncellenmiştir"));
        }
コード例 #13
0
        public async Task <IResult> UpdateAsync(ArticleUpdateDto articleUpdateDto, string modifiedByName)
        {
            var oldArticle = await UnitOfWork.Articles.GetAsync(a => a.Id == articleUpdateDto.Id);

            var article = Mapper.Map <ArticleUpdateDto, Article>(articleUpdateDto, oldArticle); // İkisini beraber tek bir class üzerinde kullanmak istediğimizi belirtiyoruz, ArticleUpdateDto'nun sahip olmadığı değerler oldArticle üzerinden geliyorlar

            article.ModifiedByName = modifiedByName;
            await UnitOfWork.Articles.UpdateAsync(article);

            await UnitOfWork.SaveAsync();

            return(new Result(ResultStatus.Success, Messages.Article.Update(article.Title)));
        }
コード例 #14
0
        public async Task <IResult> Update(ArticleUpdateDto articleUpdateDto, string modifiedByName)
        {
            var oldArticle = await UnitOfWork.Articles.GetAsync(a => a.Id == articleUpdateDto.Id);

            var article = Mapper.Map <ArticleUpdateDto, Article>(articleUpdateDto, oldArticle);

            article.ModiefiedByName = modifiedByName;
            await UnitOfWork.Articles.UpdateAsync(article);

            await UnitOfWork.SaveAsync();

            return(new Result(ResultStatus.Succes, $"{articleUpdateDto.Title} başlıklı makale başarıyla güncellendi"));
        }
コード例 #15
0
        public async Task <IResult> UpdateAsync(ArticleUpdateDto articleUpdateDto, string modifiedByName)
        {
            var oldArticle = await UnitOfWork.Articles.GetAsync(a => a.Id == articleUpdateDto.Id);

            var article = Mapper.Map <ArticleUpdateDto, Article>(articleUpdateDto, oldArticle);

            article.ModifiedByName = modifiedByName;
            await UnitOfWork.Articles.UpdateAsync(article);

            await UnitOfWork.SaveAsync();

            return(new Result(ResultStatus.Success, Messages.Article.Update(article.Title)));
        }
コード例 #16
0
        public async Task <IActionResult> UpdateArticle(int id, ArticleUpdateDto article)
        {
            var art = await _repository.GetArticle(id);

            if (art == null)
            {
                return(NotFound(art));
            }
            _mapper.Map(article, art);
            await _repository.EditArticle(art);


            return(NoContent());
        }
コード例 #17
0
        public ActionResult updateArticle(int id, ArticleUpdateDto articleUpdateDto)
        {
            var article = _articleRepo.GetArticleById(id);

            if (article == null)
            {
                return(NotFound());
            }
            var articleMapped = _mapper.Map(articleUpdateDto, article);

            _articleRepo.UpdateArticle(article);
            _articleRepo.SaveChanges();
            return(NoContent());
        }
コード例 #18
0
        public async Task <IDataResult <ArticleDto> > Update(ArticleUpdateDto articleUpdateDto, string modifiedByName)
        {
            var article = _mapper.Map <Article>(articleUpdateDto);

            article.ModifiedByName = modifiedByName;
            var updatedArticle = await _unitOfWork.Article.UpdateAsync(article);

            await _unitOfWork.SaveAsync();

            return(new DataResult <ArticleDto>(ResultStatus.Success, new ArticleDto
            {
                Article = updatedArticle,
                ResultStatus = ResultStatus.Success
            }));
        }
        public bool DeleteArticle(ArticleDto todetele, WriterDto writer)
        {
            Utils.SendObject(Constants.DeleteArticleCommand, _stream);
            var response         = Utils.ReadObject <string>(_stream);
            var articleUpdateDto = new ArticleUpdateDto
            {
                ArticleDto = todetele,
                WriterDto  = writer
            };

            Utils.SendObject(articleUpdateDto, _stream);
            var finalResponse = Utils.ReadObject <string>(_stream);

            return(finalResponse == Constants.Success);
        }
コード例 #20
0
        public async Task <ActionResult> UpdateArticle(ArticleUpdateDto article)
        {
            var articleInDb = await _context.Articles.SingleOrDefaultAsync(a => a.Id == article.Id);

            if (articleInDb == null)
            {
                return(BadRequest("Article doesn't exist"));
            }
            var articleUpdated = _mapper.Map(article, articleInDb);

            _context.Articles.Update(articleUpdated);
            await _context.SaveChangesAsync();

            return(Ok("Update successful."));
        }
コード例 #21
0
        public ActionResult UpdateArticle(int id, ArticleUpdateDto articleUpdateDto)
        {
            var articleModel = _repository.GetArticleById(id);

            if (articleModel == null)
            {
                return(NotFound());
            }

            _mapper.Map(articleUpdateDto, articleModel);

            _repository.UpdateArticle(articleModel);
            _repository.SaveChanges();

            return(NoContent());
        }
コード例 #22
0
 public async Task <IActionResult> UpdateArticle([FromBody] ArticleUpdateDto form)
 {
     try
     {
         bool retval = _uow.Article.UpdateArticle(form);
         if (retval == true)
         {
             return(Json("Article is updated"));
         }
         return(Json("Article is not updated"));
     }
     catch (Exception e)
     {
         return(Json("This is a problem: " + e));
     }
 }
コード例 #23
0
        public async Task <IDataResult <ArticleDto> > Update(ArticleUpdateDto articleUpdateDto, string modifiedByName)
        {
            var article = _mapper.Map <Article>(articleUpdateDto);

            article.ModifiedByName = modifiedByName;
            var storedArticle = await _unitOfWork.Articles.UpdateAsync(article);

            await _unitOfWork.SaveAsync();

            return(new DataResult <ArticleDto>(ResultStatus.Success, $"{articleUpdateDto.Title} başlıklı makale başarıyla güncellenmiştir.", new ArticleDto
            {
                Article = storedArticle,
                ResultStatus = ResultStatus.Success,
                Message = $"{articleUpdateDto.Title} başlıklı makale başarıyla güncellenmiştir."
            }));
        }
        public bool UpdateArticle(ArticleDto updated, ArticleDto original, WriterDto writer)
        {
            Utils.SendObject(Constants.UpdateArticleCommand, _stream);
            var response = Utils.ReadObject <string>(_stream);

            updated.Id = original.Id;
            var articleUpdateDto = new ArticleUpdateDto
            {
                ArticleDto = updated,
                WriterDto  = writer
            };

            Utils.SendObject(articleUpdateDto, _stream);
            var finalResponse = Utils.ReadObject <string>(_stream);

            return(finalResponse == Constants.Success);
        }
コード例 #25
0
        public async Task UpdateArticle_ReturnsOk()
        {
            // Arrange
            var articleDto = new ArticleUpdateDto
            {
                Content = "string"
            };
            var body = GetBody(articleDto);

            // Act
            var result = await _client.PutAsync($"/articles/{ArticleId}", body);

            var article = await result.GetDataAsync <ArticleDto>();

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            Assert.That(article.Id, Is.Not.Null);
        }
コード例 #26
0
        public async Task <IDataResult <ArticleDto> > UpdateAsync(ArticleUpdateDto articleUpdateDto, string modifiedByName)
        {
            var oldArticle = await UnitOfWork.Articles.GetAsync(a => a.Id == articleUpdateDto.Id);

            var article = Mapper.Map <ArticleUpdateDto, Article>(articleUpdateDto, oldArticle);

            article.ModifiedByName = modifiedByName;
            var updatedArticle = await UnitOfWork.Articles.UpdateAsync(article);

            await UnitOfWork.SaveAsync();

            return(new DataResult <ArticleDto>(ResultStatus.Success, Messages.Article.Update(updatedArticle.Title), new ArticleDto
            {
                Article = updatedArticle,
                ResultStatus = ResultStatus.Success,
                Message = Messages.Article.Update(updatedArticle.Title)
            }));
        }
コード例 #27
0
        public IActionResult Update(int id, [FromForm] ArticleUpdateDto articleDto)
        {
            if (id != articleDto.Id)
            {
                return(BadRequest("geçersiz id"));
            }

            var article = _mapper.Map <Article>(articleDto);

            article.LastEditDate = DateTime.Now;

            var result = _articleService.Update(article);

            if (result.Succes)
            {
                return(Ok(_mapper.Map <ArticleDto>(result.Data)));
            }
            return(BadRequest(result.Message));
        }
コード例 #28
0
        public async Task <Response <NoDataDto> > Update(ArticleUpdateDto articleUpdateDto)
        {
            Article article = await _repository.GetByIdAsync(articleUpdateDto.Id);

            if (article == null)
            {
                return(Response <NoDataDto> .Fail("Makale bulunamadı", 400));
            }
            article.Title          = articleUpdateDto.Title;
            article.ContentSummary = articleUpdateDto.ContentSummary;
            article.Content        = articleUpdateDto.Content;
            article.CategoryId     = articleUpdateDto.CategoryId;

            _repository.Update(article);
            if (_unitOfWork.Save())
            {
                return(Response <NoDataDto> .Success(200));
            }
            return(Response <NoDataDto> .Fail("Kayıt sırasında bir hata oluştu. Tekrar deneyiniz.", 500));
        }
コード例 #29
0
        public async Task <IActionResult> Edit(ArticleUpdateDto articleUpdateDto, IFormFile fileImg)
        {
            if (ModelState.IsValid)
            {
                if (fileImg != null)
                {
                    string imgExtension = Path.GetExtension(fileImg.FileName);
                    string imgName      = Guid.NewGuid() + imgExtension;
                    string imgPath      = Path.Combine(Directory.GetCurrentDirectory(), $"wwwroot/uploads/img/{imgName}");
                    using var streamImg = new FileStream(imgPath, FileMode.Create);
                    await fileImg.CopyToAsync(streamImg);

                    articleUpdateDto.Thumbnail = $"/uploads/img/{imgName}";
                }
                await _articleService.Update(articleUpdateDto, "Hasan Erdal");

                return(RedirectToAction("Index"));
            }
            var categories = await _categoryService.GetAllByNonDeleteAndActive();

            ViewBag.CategoryList = categories.Data.Categories;
            return(View(articleUpdateDto));
        }
コード例 #30
0
        public async Task <ArticleDto> UpdateAsync(ArticleUpdateDto dto)
        {
            if (dto.Id == Guid.Empty)
            {
                throw new ArticleException(ArticleErrorCodes.ArticleIdCannotBeNull, "Article Id field is mandatory.", dto);
            }

            var entity = await _articleRepository.GetByIdAsync(dto.Id);

            if (entity == null)
            {
                throw new ArticleException(ArticleErrorCodes.ArticleCouldNotBeFound, "Article could not be found.", dto);
            }

            entity.Title      = dto.Title;
            entity.Body       = dto.Body;
            entity.CategoryId = dto.CategoryId;

            entity = await _articleRepository.UpdateAsync(entity);

            // article-tag update
            //var existTagIds = entity.Tags.Select(x => x.Id).ToList();
            //var insertedTagIds = dto.TagIds.Except(existTagIds).ToList();
            //var deletedTagIds = existTagIds.Except(dto.TagIds).ToList();

            //foreach(var t in insertedTagIds)
            //{
            //    // insert article-tag
            //}

            //foreach(var t in deletedTagIds)
            //{
            //    // delete article-tags
            //}

            return(entity.Adapt <ArticleDto>());
        }