public PhotoLikeRecord FromDbItem(Dictionary <string, AttributeValue> input) { return(new PhotoLikeRecord { UserId = input.GetValue(FieldMappings.PhotoLike.UserId, value => UserId.FromDbValue(value)), PhotoId = input.GetValue(FieldMappings.PartitionKey, value => PhotoId.FromDbValue(value)), CreatedTime = input.GetDateTimeOffset(FieldMappings.PhotoLike.CreatedTime) }); }
public PhotoModel FromDbItem(Dictionary <string, AttributeValue> input) { PhotoId photoId = input.TryGetValue(FieldMappings.Photo.PhotoId, out var photoIdValue) ? PhotoId.FromDbValue(photoIdValue.S) : (PhotoId)Guid.Empty; var result = new PhotoModel { CreatedTime = input.GetDateTimeOffset(FieldMappings.Photo.CreatedTime), PhotoId = photoId, ObjectKey = input.GetString(FieldMappings.Photo.ObjectKey), State = input.GetValue(FieldMappings.Photo.State, value => (PhotoState)Enum.Parse(typeof(PhotoState), value)), UserId = input.GetValue(FieldMappings.Photo.UserId, value => UserId.FromDbValue(value)), UserName = input.GetString(FieldMappings.Photo.UserName), LikeCount = input.GetInt32(FieldMappings.Photo.LikeCount), CommentCount = input.GetInt32(FieldMappings.Photo.CommentCount), Hashtags = input.GetList(FieldMappings.Photo.Hashtags, value => new HashtagModel { PhotoId = photoId, Hashtag = value }) }; if (input.TryGetValue(FieldMappings.Photo.RawText, out var rawCommentValue)) { result.RawText = rawCommentValue.S; } if (input.TryGetValue(FieldMappings.Photo.Score, out var scoreValue)) { result.Score = double.Parse(scoreValue.N); } if (input.TryGetValue(FieldMappings.Photo.Sizes, out var sizeValues)) { result.Sizes = sizeValues.L.Select(value => { int width; int height; if (!value.M.TryGetValue("Width", out var widthValue) || !int.TryParse(widthValue.S, out width)) { throw new Exception($"Failed to parse '{widthValue.S}' as a Size Width"); } if (!value.M.TryGetValue("Height", out var heightValue) || !int.TryParse(heightValue.S, out height)) { throw new Exception($"Failed to parse '{heightValue.S}' as a Size Height"); } return(new Size(width, height)); }); } return(result); }
public PhotoComment FromDbItem(Dictionary <string, AttributeValue> input) { return(new PhotoComment { UserId = input.GetValue(FieldMappings.PhotoComment.UserId, value => UserId.FromDbValue(value)), PhotoId = input.GetValue(FieldMappings.PhotoComment.PhotoId, value => PhotoId.FromDbValue(value)), UserName = input.GetString(FieldMappings.PhotoComment.UserName), CreatedTime = input.GetDateTimeOffset(FieldMappings.PhotoComment.CreatedTime), Text = input.GetString(FieldMappings.PhotoComment.Text) }); }
public UserModel FromDbItem(Dictionary <string, AttributeValue> input) { var result = new UserModel { CreatedTime = DateTimeOffset.ParseExact(input[FieldMappings.User.CreatedTime].S, new[] { Constants.DateTimeFormat, Constants.DateTimeFormatWithMilliseconds }, null, DateTimeStyles.None), Email = input[FieldMappings.User.Email].S, Id = UserId.FromDbValue(input[FieldMappings.User.Id].S), Name = input[FieldMappings.User.Name].S }; if (input.TryGetValue(FieldMappings.User.OnlineProfiles, out var onlineProfiles)) { result.OnlineProfiles = onlineProfiles.L.Select(x => new OnlineProfile { Profile = x.M["Profile"].S, Type = Enum.TryParse <OnlineProfileType>(x.M["Type"].S, out var profileType) ? profileType : OnlineProfileType.Undefined });