Exemplo n.º 1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "GetMovieList/{id}")] HttpRequest req,
            int?id,
            ILogger log)
        {
            //TODO: get this from ClaimsPrincipal
            var userid = "1";

            if (id == null)
            {
                return(new BadRequestObjectResult("Must Provide Id."));
            }

            var       listRepository  = new MovieListRepository(ConnectionStringRepository.GetSqlAzureConnectionString("SQLConnectionString"));
            var       movieRepository = new MovieRepository(ConnectionStringRepository.GetSqlAzureConnectionString("SQLConnectionString"));
            MovieList data            = await listRepository.GetAsync(userid, id.Value);

            if (data == null)
            {
                return(new BadRequestObjectResult("Invalid Id Provided."));
            }

            data.Movies = await movieRepository.GetByListIdAsync(data.Id);

            return(new OkObjectResult(data));
        }
Exemplo n.º 2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            //TODO: get this from ClaimsPrincipal
            var userid = "1";

            var repository = new MovieListRepository(ConnectionStringRepository.GetSqlAzureConnectionString("SQLConnectionString"));

            try
            {
                var movieLists = await repository.GetAsync(userid);

                return(new OkObjectResult(movieLists));
            }
            catch (Exception e)
            {
                return(new BadRequestObjectResult(e.Message));
            }
        }