private async Task <AppUser> UpdateStorageWithUserPayload(GoogleJsonWebSignature.Payload googleAuthPayload)
        {
            var user = (await _appUserStorage.ReadAll(u => u.EmailAddress.ToLower() == googleAuthPayload.Email.ToLower())).SingleOrDefault();

            if (user == null)
            {
                user = new AppUser
                {
                    EmailAddress     = googleAuthPayload.Email,
                    FirstName        = googleAuthPayload.GivenName,
                    LastName         = googleAuthPayload.FamilyName,
                    LastLoggedInDate = _dateTimeService.GetEasternNow(),
                    CreateDate       = _dateTimeService.GetEasternNow(),
                    UpdateDate       = _dateTimeService.GetEasternNow()
                };

                user.Id = await _appUserStorage.Create(user);
            }
            else
            {
                user.LastLoggedInDate = _dateTimeService.GetEasternNow();

                await _appUserStorage.Update(user);
            }

            return(user);
        }
Exemple #2
0
        public async Task <IEnumerable <RecipeViewModel> > GetAll()
        {
            var getAllRecipesTask  = _recipeStorage.ReadAll();
            var getAllAppUsersTask = _appUserStorage.ReadAll();

            await Task.WhenAll(getAllRecipesTask, getAllAppUsersTask);

            var(recipes, appUsers) = (getAllRecipesTask.Result, getAllAppUsersTask.Result);

            return(recipes.Select(r => CreateRecipeViewModel(r, appUsers.Single(u => u.Id == r.UpdatedById))));
        }