コード例 #1
0
        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);
        }
コード例 #2
0
        public async Task Update(string id, RecipePostPutModel model, string executedById, bool isAdmin)
        {
            var originalRecipe = await _recipeStorage.Read(id);

            if (originalRecipe == null)
            {
                throw new KeyNotFoundException();
            }

            if (!isAdmin && originalRecipe.CreatedById != executedById)
            {
                throw new Exception("You cannot update someone else's recipe");
            }

            originalRecipe.Description  = model.Description;
            originalRecipe.Ingredients  = model.Ingredients;
            originalRecipe.Instructions = model.Instructions;
            originalRecipe.Name         = model.Name;
            originalRecipe.UpdatedById  = executedById;
            originalRecipe.UpdateDate   = _dateTimeService.GetEasternNow();

            await _recipeStorage.Update(originalRecipe);
        }