예제 #1
0
        public async Task <IActionResult> Post([FromBody] NewsFormModel model, [FromServices] IMapper mapper)
        {
            var command = new CreateNewsCommand(CurrentUser);

            mapper.Map(model, command);
            var newsId = await Mediator.Send(command);

            return(Created(await GetNewsById(newsId)));
        }
예제 #2
0
        public async Task <IActionResult> Put(int id, [FromBody] NewsFormModel model, [FromServices] IMapper mapper)
        {
            var news = await GetNewsById(id);

            if (news == null)
            {
                return(NotFound());
            }

            if (!HasRights(UserRights.EditNews) && news.AuthorId != CurrentUser.Id)
            {
                return(Forbid());
            }

            var updateCommand = new UpdateNewsCommand(news);

            mapper.Map(model, updateCommand);
            await Mediator.Send(updateCommand);

            return(Updated(await GetNewsById(id)));
        }