Example #1
0
        public async Task <IActionResult> Post([FromBody] TopicLike model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!await MatchAppUserWithToken(model.SupportAppUserId))
            {
                return(Unauthorized());
            }

            if (!await _topicRepo.RecordExist("AppUser", model.SupportAppUserId))
            {
                return(NotFound());
            }

            if (!await _topicRepo.RecordExist("DailyTopic", model.DailyTopicId))
            {
                return(NotFound());
            }

            var topicLike = await this._topicRepo.GetTopicLike(model.SupportAppUserId, model.DailyTopicId);

            if (topicLike != null)
            {
                return(BadRequest("既にリアクションされています"));
            }

            _topicRepo.Add(model);
            if (await _topicRepo.SaveAll() > 0)
            {
                return(CreatedAtRoute("GetTopicLike", new { userId = model.SupportAppUserId, recordId = model.DailyTopicId }, _mapper.Map <TopicLikeForReturnDto>(model)));
            }
            return(BadRequest("Failed to post topic like"));
        }