public ActionResult <Blog> Get(int id) { try { return(Ok(_bservice.GetById(id))); } catch (System.Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Blog> Get(int id) { try { return(Ok(_service.GetById(id))); } catch (Exception err) { return(BadRequest(err.Message)); } }
[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)); } }
public ActionResult <Blog> GetById(int id) { try { Blog found = _service.GetById(id); return(Ok(found)); } catch (Exception e) { return(BadRequest(e.Message)); } }
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)); } }
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); }