Ejemplo n.º 1
0
        public IActionResult Register(NewsDetailViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                MergeToModelStateTransfers(vm);
                TempData.Put(TEMP_NEWS_DETAIL_KEY, vm);
                return(RedirectToAction(nameof(Detail)));
            }

            var condition = _mapper.MapToNewsPutCondition(vm);

            SetPutConditionBase(condition);

            var result = _service.Register(condition);

            if (result.Succeeded)
            {
                vm.NewsId         = result.NewsId;
                TempLastUpdatedAt = result.LastUpdatedAt;
            }
            else
            {
                SetMessages(vm, result);
                TempData.Put(TEMP_NEWS_DETAIL_KEY, vm);
                return(RedirectToAction(nameof(Detail)));
            }

            SetMessages(vm, result);

            TempData.Put(TEMP_NEWS_DETAIL_KEY, vm);
            return(RedirectToAction(nameof(Detail), new { newsId = vm.NewsId }));
        }