src/fursvp.data/Firestore/EventMapper.cs
/// <summary>
/// Converts from Dictionary to Event.
/// </summary>
/// <param name="dictionary">The dictionary object that will be converted to Event.</param>
/// <returns>The Event object on success, or null when dictionary is null.</returns>
Converts from Dictionary to Event.
Converts from Dictionary to Event .
public Event FromDictionary(Dictionary<string, object> dictionary)
        {
            if (dictionary == null)
            {
                return null;
            }
            var result = new Event
            {
                Id = Guid.Parse((string)dictionary["Id"]),
                Version = Convert.ToInt32((long)dictionary["Version"]),
                StartsAtUtc = ((Timestamp)dictionary["StartsAtUtc"]).ToDateTime(),
                EndsAtUtc = ((Timestamp)dictionary["EndsAtUtc"]).ToDateTime(),
                TimeZoneId = (string)dictionary["TimeZoneId"],
                Name = (string)dictionary["Name"],
                OtherDetails = (string)dictionary["OtherDetails"],
                Location = (string)dictionary["Location"],
                RsvpOpen = (bool)dictionary["RsvpOpen"],
                IsPublished = (bool)dictionary["IsPublished"],
            };
            foreach (var r in ((List<object>)dictionary["Form"]).Cast<Dictionary<string, object>>())
            {
                var form = new FormPrompt
                {
                    Id = Guid.Parse((string)r["Id"]),
                    Behavior = (string)r["Behavior"],
                    Prompt = (string)r["Prompt"],
                    Required = r.TryGetValue("Required", out object required) ? (bool)required : false,
                    SortOrder = r.TryGetValue("SortOrder", out object sortOrder) ? Convert.ToInt32((long)sortOrder) : 0,
                };
                if (r["Options"] is List<object> options)
                {
                    foreach (var option in options.Cast<string>())
                    {
                        form.Options.Add(option);
                    }
                }
                result.Form.Add(form);
            }
            foreach (var m in ((List<object>)dictionary["Members"]).Cast<Dictionary<string, object>>()) 
            {
                var member = new Member
                {
                    Id = Guid.Parse((string)m["Id"]),
                    EmailAddress = (string)m["EmailAddress"],
                    Name = (string)m["Name"],
                    IsAttending = (bool)m["IsAttending"],
                    IsOrganizer = (bool)m["IsOrganizer"],
                    IsAuthor = (bool)m["IsAuthor"],
                    RsvpedAtUtc = m.TryGetValue("RsvpedAtUtc", out var rsvpedAt) ? ((Timestamp)rsvpedAt).ToDateTime() : DateTime.MinValue,
                };
                foreach (var r in ((List<object>)m["Responses"]).Cast<Dictionary<string, object>>())
                {
                    var formResponses = new FormResponses
                    {
                        PromptId = Guid.Parse((string)r["PromptId"])
                    };
                    if (r["Responses"] is List<object> responses)
                    {
                        foreach (var response in responses.Cast<string>())
                        {
                            formResponses.Responses.Add(response);
                        }
                    }
                    member.Responses.Add(formResponses);
                }
                result.Members.Add(member);
            }
            if (dictionary["RsvpClosesAtUtc"] is Timestamp rsvpClosesAt)
            {
                result.RsvpClosesAtUtc = rsvpClosesAt.ToDateTime();
            }
            return result;
        }
public Event FromDictionary ( Dictionary < string , object > dictionary ) { if ( dictionary == null ) { return null ; } var result = new Event { Id = Guid . Parse ( ( string ) dictionary [ " " ] ) , Version = Convert . ToInt32 ( ( long ) dictionary [ " " ] ) , StartsAtUtc = ( ( Timestamp ) dictionary [ " " ] ) . ToDateTime ( ) , EndsAtUtc = ( ( Timestamp ) dictionary [ " " ] ) . ToDateTime ( ) , TimeZoneId = ( string ) dictionary [ " " ] , Name = ( string ) dictionary [ " " ] , OtherDetails = ( string ) dictionary [ " " ] , Location = ( string ) dictionary [ " " ] , RsvpOpen = ( bool ) dictionary [ " " ] , IsPublished = ( bool ) dictionary [ " " ] , } ; foreach ( var r in ( ( List < object > ) dictionary [ " " ] ) . Cast < Dictionary < string , object > > ( ) ) { var form = new FormPrompt { Id = Guid . Parse ( ( string ) r [ " " ] ) , Behavior = ( string ) r [ " " ] , Prompt = ( string ) r [ " " ] , Required = r . TryGetValue ( " " , out object required ) ? ( bool ) required : false , SortOrder = r . TryGetValue ( " " , out object sortOrder ) ? Convert . ToInt32 ( ( long ) sortOrder ) : 0 , } ; if ( r [ " " ] is List < object > options ) { foreach ( var option in options . Cast < string > ( ) ) { form . Options . Add ( option ) ; } } result . Form . Add ( form ) ; } foreach ( var m in ( ( List < object > ) dictionary [ " " ] ) . Cast < Dictionary < string , object > > ( ) ) { var member = new Member { Id = Guid . Parse ( ( string ) m [ " " ] ) , EmailAddress = ( string ) m [ " " ] , Name = ( string ) m [ " " ] , IsAttending = ( bool ) m [ " " ] , IsOrganizer = ( bool ) m [ " " ] , IsAuthor = ( bool ) m [ " " ] , RsvpedAtUtc = m . TryGetValue ( " " , out var rsvpedAt ) ? ( ( Timestamp ) rsvpedAt ) . ToDateTime ( ) : DateTime . MinValue , } ; foreach ( var r in ( ( List < object > ) m [ " " ] ) . Cast < Dictionary < string , object > > ( ) ) { var formResponses = new FormResponses { PromptId = Guid . Parse ( ( string ) r [ " " ] ) } ; if ( r [ " " ] is List < object > responses ) { foreach ( var response in responses . Cast < string > ( ) ) { formResponses . Responses . Add ( response ) ; } } member . Responses . Add ( formResponses ) ; } result . Members . Add ( member ) ; } if ( dictionary [ " " ] is Timestamp rsvpClosesAt ) { result . RsvpClosesAtUtc = rsvpClosesAt . ToDateTime ( ) ; } return result ; }
Converts from Dictionary to Event.
Converts from Dictionary to Event .
The Event object on success, or null when dictionary is null.
The Event object on success or null when dictionary is null .
dictionary
Dictionary<string, object>
The dictionary object that will be converted to Event.
The dictionary object that will be converted to Event .