public async Task <ActionResult> Put([FromBody] CircleTopicUpdateDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var circleTopicFromRepo = await this._repo.GetCircleTopic(model.Id); if (circleTopicFromRepo == null) { return(NotFound()); } if (!await MatchAppUserWithToken((int)circleTopicFromRepo.AppUserId)) { return(Unauthorized()); } _mapper.Map(model, circleTopicFromRepo); try { await _repo.SaveAll(); } catch (System.Exception ex) { return(BadRequest("Failed to update attraction: " + ex.Message)); } return(Ok()); }
public async Task <ActionResult> Post([FromBody] CircleTopicUpdateDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!await this.MatchAppUserWithToken(model.AppUserId) || !await _repo.IsMember(model.AppUserId, model.CircleId)) { return(Unauthorized()); } var newTopic = this._mapper.Map <CircleTopic>(model); _repo.Add(newTopic); await _repo.SaveAll(); await _notificationRepo.AddNotification(NotificationEnum.NewCircleTopicCreated, model.AppUserId, newTopic); await _repo.SaveAll(); return(CreatedAtRoute("GetCircleTopic", new { id = newTopic.Id }, _mapper.Map <CircleTopicForReturnDto>(await _repo.GetCircleTopic(newTopic.Id)))); }