public async Task <IActionResult> GetAllBook(int userId) { BookDto bookDto = new BookDto(); var books = await bookRepository.GetAllAsync(userId); if (books != null && books.Count > 0) { bookDto.Status = EntityStatus.Suceess; bookDto.Books = books; } else { var ex = new SkyWalkerException($"获取所有数据失败userId:{userId}"); throw ex; } return(Ok(bookDto)); }
public async Task <IActionResult> GetAlllStory(int bookId) { StoryDto storyDto = new StoryDto(); var stories = await storyRepository.GetAllStoryAsync(bookId); if (stories != null && stories.Count > 0) { storyDto.Status = EntityStatus.Suceess; storyDto.Stories = stories; } else { var ex = new SkyWalkerException($"获取所有故事出错bookId:{bookId}"); throw ex; } return(Ok(stories)); }
public async Task <IActionResult> GetStory(int storyId) { var story = await storyRepository.GetStoryAsync(storyId); StoryDto storyDto = new StoryDto(); if (story != null) { storyDto.Status = EntityStatus.Suceess; storyDto.Stories = new List <Story> { story }; } else { var ex = new SkyWalkerException($"获取故事出错storyId:{storyId}"); } return(Ok(story)); }
public async Task <IActionResult> Get(int id) { BookDto bookDto = new BookDto(); var book = await bookRepository.GetAsync(id); if (book != null) { bookDto.Status = EntityStatus.Suceess; bookDto.Books = new List <Book>() { book }; return(Ok(bookDto)); } else { var ex = new SkyWalkerException($"错误的书籍id:{id}"); throw ex; } }
public async Task <IActionResult> GetUserAsync() { UserDto userDto = new UserDto(); //var user = await dbContext.AppUsers.SingleOrDefaultAsync(x => x.Id == id); var user = await userRepository.GetAsync(this.Identity.UserId); if (user == null) { userDto.Status = EntityStatus.Fail; var ex = new SkyWalkerException($"错误的用户id:{this.Identity.UserId}"); throw ex; } else { userDto.Status = EntityStatus.Suceess; userDto.User = user; } return(Json(userDto)); // return Json(userDto); }