Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
868 B
4
Indexable
Never
IRepository.cs

public Task<string> GetDescription(string title);

Repository.cs

   public async Task<string> GetDescription(string title){
       try{
           var blogDescrition = await _context.Blogs.Where(x=>x.BlogTitle==title)
           .Select(x=>x.BlogDescription).FirstOrDefaultAsync();
           if(blogDescrition==null){
               return null;
           }
           else{
                return blogDescrition;
           }
        }
        catch(Exception ex){
               return ex.Message;
        }
    }

BlogController.cs

      [HttpGet("GetDetails")]
       public async Task<ActionResult<string>> GetDetails([FromQuery]string title){
           var b=await _blogRepository.GetDescription(title);
           if(b==null){
               return NotFound("Errorrrr");

           }else{
               return Ok(b);
           }
       }
Leave a Comment