public async Task <IActionResult?> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "dinners/menuitem/remove")] HttpRequest req ) { var(authenticationStatus, authenticationResponse) = await req.HttpContext.AuthenticateAzureFunctionAsync(); if (!authenticationStatus) { return(authenticationResponse); } var menuItem = await req.GetBodyAs <DinnerAddRemoveMenuItemCommandModel>(); if (!_authz.Authorize(req.HttpContext.User.GetNameIdentifierId() !, menuItem.FamilyId, Resources.Dinner, Actions.Update)) { return(new UnauthorizedResult()); } _logger.LogInformation($"Adding dish: {menuItem.DishId} to date: {menuItem.Date}"); var dinner = await _dinnerService.GetAsync(menuItem.FamilyId, menuItem.Date); dinner.RemoveMenuItem(new MenuItem(menuItem.DishId)); await _dinnerRepository.SaveAsync(dinner); return(new OkResult()); }
public async Task <IActionResult?> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "dinners/family/{familyId}/dates/{fromDate}/{toDate}")] HttpRequest req, string familyId, string fromDate, string toDate ) { var(authenticationStatus, authenticationResponse) = await req.HttpContext.AuthenticateAzureFunctionAsync(); if (!authenticationStatus) { return(authenticationResponse); } if (!_authz.Authorize(req.HttpContext.User.GetNameIdentifierId() !, familyId, Resources.Dinner, Actions.Read)) { return(new UnauthorizedResult()); } var pattern = LocalDatePattern.Iso; var parsedId = Guid.Parse(familyId); var dinners = _dinnerService.GetAsync(parsedId, pattern.Parse(fromDate).GetValueOrThrow(), pattern.Parse(toDate).GetValueOrThrow()).Select(_mapper.Map <DinnersQueryModel>); return(new OkObjectResult(dinners)); }