Пример #1
0
        public async Task <ActionResult <RatedItemViewModel> > PostAsync([FromBody] RatedItemBaseViewModel ratedItem)
        {
            if (!ModelState.IsValid)
            {
                return(UnprocessableEntity());
            }

            var entity = RatedItemMapper.FromViewModel(ratedItem);

            _rateContext.Add(entity);
            await _rateContext.SaveChangesAsync();

            return(RatedItemMapper.ToViewModel(entity));
        }
Пример #2
0
        public async Task <ActionResult <RatedItemViewModel> > PutAsync([FromRoute] int id, [FromBody] RatedItemBaseViewModel ratedItem)
        {
            if (!ModelState.IsValid)
            {
                return(UnprocessableEntity());
            }

            var entity = await _rateContext.RatedItems.FindAsync(id);

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

            RatedItemMapper.FromViewModel(ratedItem, entity);

            await _rateContext.SaveChangesAsync();

            return(RatedItemMapper.ToViewModel(entity));
        }