public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var jwtUser = context.HttpContext.User; if (!jwtUser.HasClaim(c => c.Type == JwtRegisteredClaimNames.Sub)) { InvalidateRequest(context, "Invalid token for request", _logger, 401); } String username = context.HttpContext.User.Claims.FirstOrDefault(c => c.Type == JwtRegisteredClaimNames.Sub).Value; String slug = context.ActionArguments["slug"] as String; Article article = await _articleService.GetArticle(slug, username); if (article.Author.Username != username) { InvalidateRequest(context, "You are not authorized to edit this article", _logger, 403); return; } UpdateArticleHolder updateArticleHolder = context.ActionArguments["updateArticle"] as UpdateArticleHolder; UpdateArticle updateArticle = updateArticleHolder.Article; if (null == updateArticle.Title && null == updateArticle.Description && null == updateArticle.Body) { InvalidateRequest(context, "Nothing to update", _logger, 422); return; } return; }
public async Task <IActionResult> Put(Guid id, UpdateArticle command) { command.SetId(id); await _busPublisher.SendAsync(command); return(Accepted()); }
// GET: Article/Edit/8 public ActionResult Edit(int id) { UpdateArticle ViewModel = new UpdateArticle(); string url = "articledata/findarticle/" + id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { //Put data into article data transfer object ArticleDto SelectedArticle = response.Content.ReadAsAsync <ArticleDto>().Result; ViewModel.article = SelectedArticle; //get information about countries this article could also include url = "countrydata/getcountries"; response = client.GetAsync(url).Result; IEnumerable <CountryDto> PotentialCountries = response.Content.ReadAsAsync <IEnumerable <CountryDto> >().Result; ViewModel.allcountries = PotentialCountries; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public async Task <SystemResponse> UpdateAsync(string accessToken, UpdateArticle article) { SystemResponse systemResponse = new SystemResponse(); var data = JsonConvert.SerializeObject(article); var body = new StringContent(data, Encoding.UTF8, "application/json"); client.DefaultRequestHeaders.Add("access_token", accessToken); var response = await client.PutAsync(apiUrl + "update", body); switch (response.StatusCode) { case HttpStatusCode.Unauthorized: systemResponse = SystemResponse.AccessDenied; break; case HttpStatusCode.NotFound: systemResponse = SystemResponse.NotFound; break; case HttpStatusCode.OK: systemResponse = SystemResponse.Success; break; default: break; } return(systemResponse); }
public async Task <IActionResult> Update(int id, ArticleUpdateViewModel model) { if (ModelState.IsValid) { var article = new UpdateArticle { Id = id, Title = model.Title, Content = model.Content }; if (model.Picture != null) { using (var memoryStream = new MemoryStream()) { await model.Picture.CopyToAsync(memoryStream); article.Picture = memoryStream.ToArray(); } } var accessToken = HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.UserData)?.Value; var result = await _articleService.UpdateAsync(accessToken, article); if (result == SystemResponse.Success) { return(RedirectToAction("GetDetails", new { id = id })); } } return(View(model)); }
//Accessible only for user that is login //[Authorize] public ActionResult Update(int?id) { if (id == null) { //If no id value has been presented, will return a BadRequest return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } string query = "Select * from Articles where ArticleID=@id"; //Debug.WriteLine(query); //Debug.WriteLine("Article ID of: " + id); SqlParameter parameter = new SqlParameter("@id", id); Article selectedarticle = db.Articles.SqlQuery(query, parameter).First(); //Query to get all the Authors string query2 = "Select * from Authors"; //Sql Execute for 2nd Query List <Author> authors = db.Authors.SqlQuery(query2).ToList(); var UpdateArticle = new UpdateArticle(); //Add list of authors and an article in a model view UpdateArticle.authors = authors; UpdateArticle.article = selectedarticle; if (selectedarticle == null) { //if article is not found in the database return(HttpNotFound()); } return(View(UpdateArticle)); }
public async Task <Article> UpdateAsync(int articleId, UpdateArticle article) { ThrowHelper.ThrowIfLessThanOne(articleId, nameof(articleId)); ThrowHelper.ThrowIfNull(article, nameof(article)); var request = new { article }; return(await ApiConnection.ExecutePutAsync <object, Article>($"{Route}/{articleId}", request).ConfigureAwait(false)); }
public void Put(UpdateArticle dto) { Article article = new Article { Title = dto.Title, Content = dto.Content, Content_Type = dto.Content_Type, }; DapperHelper.Update(article); }
// GET: Article/Create public ActionResult Create() { UpdateArticle ViewModel = new UpdateArticle(); //get information about countries this article could also include string url = "countrydata/getcountries"; HttpResponseMessage response = client.GetAsync(url).Result; IEnumerable <CountryDto> PotentialCountries = response.Content.ReadAsAsync <IEnumerable <CountryDto> >().Result; ViewModel.allcountries = PotentialCountries; return(View(ViewModel)); }
internal override void UpdateArticle(int articleId, UpdateArticle articleUpdates) { ArticleDAO article = _articles.Where(e => e.Id == articleId).Single(); if (null != articleUpdates.Title) { article.Title = articleUpdates.Title; article.Slug = SlugUtil.CreateSlug(articleUpdates.Title); } if (null != articleUpdates.Description) { article.Description = articleUpdates.Description; } if (null != articleUpdates.Body) { article.Body = articleUpdates.Body; } article.UpdatedAt = DateTime.Now; _articles.Update(article); }
public override async Task <Article> UpdateArticle(string authedUsername, String articleSlug, UpdateArticle updateArticle) { var transaction = _context.Database.BeginTransaction(); try { ArticleDAO articleDao = await _articleRepository.GetArticleBySlug(articleSlug); _articleRepository.UpdateArticle(articleDao.Id, updateArticle); _context.SaveChanges(); Article article = await CreateArticleFromDAO(articleDao, authedUsername); transaction.Commit(); return(article); } catch (Exception ex) { transaction.Rollback(); throw ex; } }
public async Task <IActionResult> Update(Guid articleId, [FromBody] UpdateArticle command) { await _articleService.UpdateAsync(articleId, command.Title, command.Lead, command.Content); return(NoContent()); }
public async Task <IActionResult> UpdateArticle(int id, UpdateArticle command) { command.ArticleId = id; return(Ok(await _mediator.Send(command))); }
public async Task <Unit> UpdateArticleAsync([FromBody] UpdateArticle updateArticle) { return(await _mediator.Send(updateArticle)); }
public abstract Task <Article> UpdateArticle(String authedUsername, String articleSlug, UpdateArticle updateArticle);
internal abstract void UpdateArticle(int articleId, UpdateArticle article);
public UpdateArticleHolder(UpdateArticle article) { Article = article; }