Example #1
0
        public async Task UpdateAsync(ArticleUpdateModel model)
        {
            MultipartFormDataContent formData = new MultipartFormDataContent();

            if (model.Image != null)
            {
                var bytes = await System.IO.File.ReadAllBytesAsync(model.Image.FileName);

                ByteArrayContent byteContent = new ByteArrayContent(bytes);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue(model.Image.ContentType);

                formData.Add(byteContent, nameof(ArticleAddModel.Image), model.Image.FileName);
            }

            var user = _httpContextAccessor.HttpContext.Session.GetObject <UserViewModel>(null);

            model.UserId = user.UserId;
            formData.Add(new StringContent(model.ArticleId.ToString()), nameof(ArticleUpdateModel.ArticleId));

            formData.Add(new StringContent(model.UserId.ToString()), nameof(ArticleAddModel.UserId));

            formData.Add(new StringContent(model.ShortDescription), nameof(ArticleAddModel.ShortDescription));

            formData.Add(new StringContent(model.Description), nameof(ArticleAddModel.Description));

            formData.Add(new StringContent(model.Title), nameof(ArticleAddModel.Title));

            // _httpClient.DefaultRequestHeaders.Authorization= new AuthenticationHeaderValue("Bearer",_httpContextAccessor.HttpContext.Session.GetString("token"));

            await _httpClient.PutAsync($"{model.ArticleId}", formData);
        }
Example #2
0
        public async Task <IActionResult> UpdateArticle(int id, [FromBody] ArticleUpdateModel model)
        {
            var command  = new UpdateArticleCommand(model.Content, model.Description, model.ImageUrl, model.Language, model.Title, model.Type, model.AuthorId, id);
            var response = await _mediator.Send(command);

            return(response.ToActionResult());
        }
        public HttpResponseMessage UpdateArticle(string Id, [FromBody] ArticleUpdateModel UpdateInfo)
        {
            ApiResultViewModel result = new ApiResultViewModel();

            if (!ModelState.IsValid)
            {
                result.Result  = false;
                result.Status  = ResponseCode.Fail.ToString();
                result.Message = AllShared.GetModelStateError(ModelState);
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }

            if (UpdateInfo == null)
            {
                result.Result  = false;
                result.Status  = ResponseCode.Fail.ToString();
                result.Message = "無修改資料相關參數";
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }

            //取得使用者ID
            string UserID = JWTShared.GetUserID(Request.Headers.Authorization.Parameter);

            ArticleViewModel ArticleViewModel = articleRepository.GetArticle(Id, UserID);

            if (UpdateInfo.Title == null)
            {
                UpdateInfo.Title = ArticleViewModel.Title;
            }
            if (UpdateInfo.Content == null)
            {
                UpdateInfo.Content = ArticleViewModel.Content;
            }

            if (ArticleViewModel == null)
            {
                result.Result  = false;
                result.Status  = ResponseCode.Fail.ToString();
                result.Message = "查無此文章資料!!!";
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }

            bool IsSuccess = articleRepository.UpdateArticle(Id, UserID, UpdateInfo);

            if (IsSuccess)
            {
                result.Result  = true;
                result.Status  = ResponseCode.Success.ToString();
                result.Message = "修改成功!!!";
            }
            else
            {
                result.Result  = false;
                result.Status  = ResponseCode.Fail.ToString();
                result.Message = "修改文章資料發生錯誤!!!";
            }

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Example #4
0
        public async Task <IActionResult> UpdateArticleAsync(int id)
        {
            Article UpdateArticle = await ArticleOperations.Get(id);

            ArticleUpdateModel updateArticle = new ArticleUpdateModel(UpdateArticle);

            return(View(updateArticle));
        }
        public async Task <IActionResult> Update(ArticleUpdateModel model)
        {
            if (ModelState.IsValid)
            {
                await _blogApiService.UpdateAsync(model);

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Example #6
0
        public bool UpdateArticle(string ArticleID, string UID, ArticleUpdateModel ArticleModel)
        {
            //查詢資料用的過濾器
            FilterDefinition <ArticleModel> filters = Builders <ArticleModel> .Filter.Eq("ArticleID", ArticleID) & Builders <ArticleModel> .Filter.Eq("UID", UID);

            //更新資料用的定義
            UpdateDefinition <ArticleModel> updates = Builders <ArticleModel> .Update.Set("Title", ArticleModel.Title)
                                                      .Set("Content", ArticleModel.Content);

            return(mongoContext.UpdateOne <ArticleModel>(filters, updates));
        }
        public static async void Update(ArticleUpdateModel model)
        {
            string encodedHeader;

            if (model.HeaderImage != null)
            {
                encodedHeader = FileEncoder.EncodeImage(model.HeaderImage);
            }
            else
            {
                encodedHeader = model.HeaderImageString;
            }

            Article article = new Article(model.ArticleId, model.Title, model.Author, model.Summary, model.Tag, encodedHeader, model.Content);


            var stringContent            = new StringContent(JsonConvert.SerializeObject(article), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await ApiClient.PutAsync($"article", stringContent);
        }
Example #8
0
        public async Task <IResultModel> Update(ArticleUpdateModel model)
        {
            var entity = await _repository.GetAsync(model.Id);

            if (entity == null)
            {
                return(ResultModel.NotExists);
            }

            _mapper.Map(model, entity);

            //if (await _repository.Exists(entity))
            //{
            //return ResultModel.HasExists;
            //}

            var result = await _repository.UpdateAsync(entity);

            return(ResultModel.Result(result));
        }
Example #9
0
        public async Task <IActionResult> Update(int id, [FromForm] ArticleUpdateModel articleUpdateModel)

        {
            if (id != articleUpdateModel.ArticleId)
            {
                return(BadRequest("invalid id"));
            }
            var uploadModel = await UploadFileAsync(articleUpdateModel.Image, "image/jpeg");

            if (uploadModel.UploadState == UploadState.Success)
            {
                var updatedBlog = await _articleService.FindByIdAsync(articleUpdateModel.ArticleId);

                updatedBlog.ShortDescription = articleUpdateModel.ShortDescription;
                updatedBlog.Title            = articleUpdateModel.Title;
                updatedBlog.Description      = articleUpdateModel.Description;
                updatedBlog.ImagePath        = uploadModel.NewName;


                await _articleService.UpdateAsync(updatedBlog);

                return(NoContent());
            }
            else if (uploadModel.UploadState == UploadState.NotExist)
            {
                var updatedBlog = await _articleService.FindByIdAsync(articleUpdateModel.ArticleId);

                updatedBlog.ShortDescription = articleUpdateModel.ShortDescription;
                updatedBlog.Title            = articleUpdateModel.Title;
                updatedBlog.Description      = articleUpdateModel.Description;

                await _articleService.UpdateAsync(updatedBlog);

                return(NoContent());
            }
            else
            {
                return(BadRequest(uploadModel.ErrorMessage));
            }
        }
Example #10
0
        public async Task <IActionResult> Edit(Guid id, ArticleUpdateModel item)
        {
            ViewBag.Domain = _configuration["Domain"];
            if (id != item.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _articleFacade.Update(item);
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(View(item));
                }
                return(RedirectToAction(nameof(Index), new { area = "Admin" }));
            }

            return(RedirectToAction(nameof(Index), new { area = "Admin" }));
        }
Example #11
0
        public async Task <IActionResult> UpdateArticle(int id, [FromBody] ArticleUpdateModel model)
        {
            await _articleService.UpdateArticle(id, _mapper.Map <ArticleDTO>(model), Request.GetToken());

            return(NoContent());
        }
Example #12
0
 public Task <IResultModel> Update(ArticleUpdateModel model)
 {
     return(_service.Update(model));
 }
Example #13
0
        public IActionResult Update(ArticleUpdateModel article)
        {
            ArticleOperations.Update(article);

            return(RedirectToAction("Index"));
        }