예제 #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var identity = ClientPrincipalBuilder.BuildFromHttpRequest(req);

            var task = await req.ParseRequestBodyAsync <TaskViewModel>();

            task.Id = Guid.NewGuid();

            var userId   = identity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
            var userName = identity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;

            task.User = new TaskViewModel.UserDescriptor
            {
                UserId   = string.IsNullOrWhiteSpace(userId) ? "Dev-alberto" : userId,
                UserName = string.IsNullOrWhiteSpace(userName) ? "albx" : userName
            };

            var entity = task.ToTaskEntity();

            await Store.AddNewTask(entity);

            return(new OkObjectResult(task));
        }
예제 #2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var identity = ClientPrincipalBuilder.BuildFromHttpRequest(req);
            var userId   = identity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

            if (string.IsNullOrWhiteSpace(userId))
            {
                userId = "Dev-alberto";
            }

            var entities = await Store.GetAllTasks(userId);

            var tasks = entities.Select(t => t.ToTaskViewModel());

            return(new OkObjectResult(tasks));
        }