示例#1
0
        public async Task <IActionResult> OnGetAsync(Guid id)
        {
            var aphorism = await _aphorismsService.GetAphorism(id);

            if (aphorism == null)
            {
                return(NotFound($"Unable to load aphorism with ID '{id}'."));
            }

            Input.Aphorism = aphorism.Value;
            Input.Culture  = aphorism.Culture;
            Input.Id       = aphorism.Id;

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (user.Id != aphorism.UserId)
            {
                return(Forbid());
            }


            return(Page());
        }
        public async Task <IActionResult> GetAphorism(Guid id, string subject)
        {
            var aphorism = await _aphorismsService.GetAphorism(id);

            if (aphorism != null)
            {
                if (!string.IsNullOrEmpty(subject))
                {
                    aphorism.Subject = subject;
                }

                return(Ok(_mapper.Map <AphorismDto>(aphorism)));
            }
            else
            {
                return(NotFound());
            }
        }