public async Task SetPhotoState(UserId userId, PhotoId photoId, PhotoState photoState)
        {
            logWriter.LogInformation($"{nameof(SetPhotoState)}({nameof(userId)} = '{userId}', {nameof(photoId)} = '{photoId}', {nameof(photoState)} = '{photoState}'");

            var request = new UpdateItemRequest
            {
                TableName = tableName,
                Key       = new Dictionary <string, AttributeValue>
                {
                    { FieldMappings.PartitionKey, new AttributeValue(photoId.ToDbValue()) },
                    { FieldMappings.SortKey, new AttributeValue(photoId.ToDbValue()) }
                },
                UpdateExpression          = $"SET {FieldMappings.Photo.State} = :newstate",
                ExpressionAttributeValues = new Dictionary <string, AttributeValue>
                {
                    {
                        ":newstate", new AttributeValue
                        {
                            S = photoState.ToString()
                        }
                    }
                }
            };

            await dynamoDbCore.UpdateItem(request);
        }
        public Task UpdateLikeCount(PhotoModel photo, int count)
        {
            UpdateItemRequest setLikeCountForPhotoRequest = GetLikeCountUpdateRequest(Mappers.PhotoModel.ToDbKey(photo), count);

            var requests = photo.Hashtags
                           .Select(hashtag => GetLikeCountUpdateRequest(Mappers.Hashtag.ToDbKey(hashtag), count))
                           .Union(new[] { setLikeCountForPhotoRequest });

            return(Task.WhenAll(requests.Select(x => dynamoDbCore.UpdateItem(x))));
        }
Esempio n. 3
0
        public async Task <IEnumerable <OnlineProfile> > AddSocialProfile(OnlineProfile onlineProfile, UserId userId)
        {
            var user = await GetUserById(userId);

            var onlineProfiles  = user.OnlineProfiles?.ToList() ?? new List <OnlineProfile>();
            var existingProfile = onlineProfiles.FirstOrDefault(x =>
                                                                x.Type == onlineProfile.Type &&
                                                                x.Profile.Equals(onlineProfile.Profile, StringComparison.OrdinalIgnoreCase));

            if (existingProfile != null)
            {
                // if the online profile was found, just update it (might be casing differences)
                existingProfile.Profile = onlineProfile.Profile;
            }
            else
            {
                onlineProfiles.Add(onlineProfile);
            }

            user.OnlineProfiles = onlineProfiles;

            UpdateItemRequest request = new UpdateItemRequest
            {
                TableName = tableName,
                Key       = Mappers.UserModel.ToDbKey(user),
                ExpressionAttributeNames = new Dictionary <string, string>
                {
                    { "#OnlineProfiles", FieldMappings.User.OnlineProfiles }
                },
                ExpressionAttributeValues = new Dictionary <string, AttributeValue>
                {
                    { ":OnlineProfiles", Mappers.UserModel.ToDbItem(user)[FieldMappings.User.OnlineProfiles] }
                },
                UpdateExpression = "SET #OnlineProfiles = :OnlineProfiles"
            };

            await dynamoDbCore.UpdateItem(request);

            return(user.OnlineProfiles);
        }
Esempio n. 4
0
        private async Task UpdateCommentCountAndScore(PhotoModel photo, int countDelta, double scoreDelta)
        {
            var updateItemRequests = (new[]
            {
                GetCommentCountAndScoreUpdateRequest(Mappers.PhotoModel.ToDbKey(photo), countDelta, scoreDelta)
            })
                                     .Union(photo.Hashtags.Select(hashtag =>
                                                                  GetCommentCountUpdateRequest(Mappers.HashtagPhoto.ToDbKey(new HashtagPhoto {
                Hashtag = hashtag, Photo = photo
            }), countDelta)));

            await Task.WhenAll(updateItemRequests.Select(request => dynamoDbCore.UpdateItem(request)));
        }
        private async Task UpdateCommentCount(PhotoModel photo, int count)
        {
            if (count < 0)
            {
                count = 0;
            }
            var updateItemRequests = (new[]
            {
                GetCommentCountUpdateRequest(Mappers.PhotoModel.ToDbKey(photo), count)
            })
                                     .Union(photo.Hashtags.Select(hashtag =>
                                                                  GetCommentCountUpdateRequest(Mappers.HashtagPhoto.ToDbKey(new HashtagPhoto {
                Hashtag = hashtag, Photo = photo
            }), count)));

            await Task.WhenAll(updateItemRequests.Select(request => dynamoDbCore.UpdateItem(request)));
        }