コード例 #1
0
 public ActionResult <Blog> Get(int id)
 {
     try
     {
         return(Ok(_bservice.GetById(id)));
     }
     catch (System.Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #2
0
 public ActionResult <Blog> Get(int id)
 {
     try
     {
         return(Ok(_service.GetById(id)));
     }
     catch (Exception err)
     {
         return(BadRequest(err.Message));
     }
 }
コード例 #3
0
ファイル: BlogsController.cs プロジェクト: NikolaCop/Blogger
 [HttpGet("{blogsId}")] //Get By ID
 public ActionResult <Blog> GetById(string blogsId)
 {
     try
     {
         return(Ok(_service.GetById(blogsId)));
     }
     catch (System.Exception err)
     {
         return(BadRequest(err.Message));
     }
 }
コード例 #4
0
 public ActionResult <Blog> GetById(int id)
 {
     try
     {
         Blog found = _service.GetById(id);
         return(Ok(found));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #5
0
        public async Task <ActionResult <IEnumerable <Blog> > > GetById(int id)
        {
            try
            {
                //good way to handle private bool on return, get user email and pass to serv
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                return(Ok(_serv.GetById(userInfo?.Email, id)));
            }
            catch (Exception error)
            {
                return(BadRequest(error.Message));
            }
        }
コード例 #6
0
        public async Task GetByIdShouldWorkCorrectly()
        {
            var db = GetDatabase();
            var blogsRepository = new EfDeletableEntityRepository <Blog>(db);

            var service = new BlogsService(blogsRepository);

            var blog2 = new Blog()
            {
                Id   = 2,
                Name = "Name",
            };

            await db.Blogs.AddAsync(blog2);

            await db.SaveChangesAsync();

            AutoMapperConfig.RegisterMappings(typeof(BlogDetailsViewModel).Assembly);

            var lol = service.GetById <BlogDetailsViewModel>(2);

            Assert.Equal(2, lol.Id);
        }