public async Task <IActionResult> UpdateOpinion(int schoolId, int opinionId, OpinionForUpdateDto opinionForUpdateDto) { var school = await database.SchoolRepository.Get <School>(schoolId); var opinion = school.Opinions.FirstOrDefault(o => o.Id == opinionId); int currentUserId = int.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); if (opinion == null) { throw new EntityNotFoundException("Opinia"); } if (currentUserId != opinion.UserId) { return(this.Forbidden("Nie możesz aktualizować nie swojej opinii")); } opinion = mapper.Map <OpinionForUpdateDto, Opinion>(opinionForUpdateDto, opinion); if (await schoolService.UpdateOpinion(school, opinion)) { await notificationSystem.PushNotificationToUsersByFollows(StaticExpressions.OpinionUpdatedForOwner(opinion.User.UserName), school); await notificationSystem.PushNotificationToUsersByFollows(StaticExpressions.OpinionUpdated(opinion.User.UserName, school.Name), school); return(NoContent()); } return(BadRequest("Nie udało się zaktualizować opinii")); }