Esempio n. 1
0
        public async Task <ActionResult <Response <DtoCommentary> > > GetCommentaryById([FromRoute] int idCommentary)
        {
            try
            {
                if (idCommentary == 0)
                {
                    return(BadRequest(new Response <string>()
                    {
                        Error = "IdCommentary can't be equal to 0", Succes = true
                    }));
                }
                var result = await BsCommentary.GetById <DtoCommentary>(idCommentary);

                if (result == null)
                {
                    return(NotFound(new Response <string>()
                    {
                        Error = "The Commentary doesn't exist", Succes = true
                    }));
                }
                return(Ok(new Response <DtoCommentary>()
                {
                    Error = "", Data = result, Succes = true
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new Response <string[]>()
                {
                    Error = e.Message, Data = e.StackTrace.Split("\r\n"), Succes = false
                }));
            }
        }
Esempio n. 2
0
 public async Task <ActionResult <Response <IEnumerable <DtoCommentary> > > > GetAllCommentary()
 {
     try
     {
         return(Ok(new Response <IEnumerable <DtoCommentary> >()
         {
             Error = "", Data = await BsCommentary.GetAll <DtoCommentary>(), Succes = true
         }));
     }
     catch (Exception e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, new Response <string[]>()
         {
             Error = e.Message, Data = e.StackTrace.Split("\r\n"), Succes = false
         }));
     }
 }
Esempio n. 3
0
 public async Task <ActionResult <Response <DtoCommentary> > > AddCommentary([FromBody] DtoCommentaryAdd commentary)
 {
     try
     {
         if (commentary == null)
         {
             return(BadRequest(new Response <string>()
             {
                 Error = "The Commentary can't be null", Succes = true
             }));
         }
         return(Ok(new Response <DtoCommentary>()
         {
             Error = "", Data = await BsCommentary.Add <DtoCommentary, DtoCommentaryAdd>(commentary), Succes = true
         }));
     }
     catch (Exception e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, new Response <string[]>()
         {
             Error = e.Message, Data = e.StackTrace.Split("\r\n"), Succes = false
         }));
     }
 }