public void Update(UpdateTopicDto updateTopicDto) { Topic topicForUpdate = DbSet.Find(updateTopicDto.TopicId); topicForUpdate.Title = updateTopicDto.Title; topicForUpdate.DateUpdate = DateTime.Now; }
public IActionResult UpdateTopic(UpdateTopicDto updateTopicDto) { var result = this._topicService.UpdateTopic(updateTopicDto); if (result.ResultType == ResultType.UnAuthorized) { return(Unauthorized()); } if (result.ResultType == ResultType.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public async Task UpdateTopic(string userId, int topicId, UpdateTopicDto updateTopicDto) { var topic = await _context.Topics.FindAsync(topicId); if (topic == null || !topic.UserId.Equals(userId) || topic.IsDeleted) { throw new KeyNotFoundException("Topic not found"); } var category = await _context.Categories.FindAsync(updateTopicDto.CategoryId); if (category == null) { throw new ArgumentException("Invalid Category"); } topic.Content = updateTopicDto.Content; topic.CategoryId = updateTopicDto.CategoryId; await Do(() => _context.Entry(topic).State = EntityState.Modified); }
public IResult UpdateTopic(UpdateTopicDto updateTopicDto) { var user = _authService.GetAuthenticatedUser().Result.Data; var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist(), IsTopicExist(updateTopicDto.TopicId), IsTopicBelongToUser(user.Id, updateTopicDto.TopicId)); if (errorResult != null) { return(errorResult); } var topic = _uow.Topics.Get(x => x.Id == updateTopicDto.TopicId); topic.Content = updateTopicDto.Content; topic.Title = updateTopicDto.Title; _uow.Topics.Update(topic); _uow.Commit(); return(new SuccessResult(Message.TopicUpdated)); }
public async Task <ResponseTopicDto> UpdateTopicAsync(Guid boardId, Guid topicId, UpdateTopicDto topic) { var existingTopic = await _topicRepository.GetTopicAsync(topicId); var updatedEntity = _mapper.Map(topic, existingTopic); var returnedEntity = await _topicRepository.UpdateTopicAsync(updatedEntity); var responseDto = _mapper.Map <Topic, ResponseTopicDto>(returnedEntity); return(responseDto); }
public async Task <IActionResult> UpdateTopic(int id, UpdateTopicDto updateTopicDto) { return(await Do(async() => await _topicService.UpdateTopic(User.Identity.GetUserId(), id, updateTopicDto))); }
//[Produces("application/json", "application/xml", "application/vnd.restwall.hateoas+json")] public async Task <ActionResult <ResponseTopicDto> > UpdateTopicAsync(Guid boardId, Guid topicId, [FromBody] UpdateTopicDto topic, [FromHeader(Name = "Accept")] string mediaType) { if (!MediaTypeHeaderValue.TryParse(mediaType, out MediaTypeHeaderValue parsedMediaType)) { return(BadRequest()); } if (!await _topicService.TopicExistsAsync(topicId)) { return(NotFound()); } var topicDto = await _topicService.UpdateTopicAsync(boardId, topicId, topic); if (topicDto == null) { return(NotFound()); } var includeLinks = parsedMediaType.SubTypeWithoutSuffix.EndsWith("hateoas", StringComparison.InvariantCultureIgnoreCase); if (includeLinks) { IEnumerable <LinkDto> links = new List <LinkDto>(); links = CreateTopicLinks(topicDto.BoardId, topicDto.Id); var topicWithLinks = _mapper.Map <ResponseTopicLinksDto>(topicDto); topicWithLinks.Links = links; return(Ok(topicWithLinks)); } return(Ok(topicDto)); }
public void UpdateTopic(UpdateTopicDto updateTopicDto) { _topicRepo.Update(updateTopicDto); _topicRepo.SaveChanges(); }
public ActionResult <TopicDto> UpdateTopic(Guid personId, Guid projectId, Guid topicId, [FromBody] UpdateTopicDto dto) { try { if (!ModelState.IsValid) { return(BadRequest()); } if (!_db.Person.BelongsToUser(personId, HttpContext)) { return(Forbid()); } if (_db.Participation.GetRole(personId, projectId)?.KnowledgeBaseWrite != true) { return(Forbid()); } var topic = _db.Topic .FindByCondition(x => x.Id == topicId && x.ProjectId == projectId) .SingleOrDefault(); if (topic == null) { return(BadRequest()); } topic.Name = dto.Name; _db.Topic.Update(topic); _db.Save(); var updatedTopic = _db.Topic .FindByCondition(x => x.Id == topicId) .SingleOrDefault(); return(Ok(_mapper.Map <TopicDto>(updatedTopic))); } catch (Exception e) { _logger.LogError($"ERROR in UpdateTopic: {e.Message}"); return(StatusCode(500, "Internal server error")); } }