PhotoSharingApp.AppService.Shared.Models.DocumentDB.UserDocument.ToContract C# (CSharp) Method

ToContract() public method

Creates a UserContract from this document
public ToContract ( ) : UserContract
return PhotoSharingApp.Portable.DataContracts.UserContract
        public UserContract ToContract()
        {
            return new UserContract
            {
                UserId = Id,
                ProfilePhotoUrl = ProfilePhotoUrl,
                ProfilePhotoId = ProfilePhotoId,
                GoldBalance = GoldBalance,
                RegistrationReference = RegistrationReference,
                UserCreated = CreatedAt.Date,
                UserModified = ModifiedAt.Date
            };
        }
    }

Usage Example

コード例 #1
0
        /// <summary>
        /// Inserts a new user record in the database.
        /// </summary>
        /// <param name="registrationReference">The Azure Mobile Service user id.</param>
        /// <returns>Updated user object.</returns>
        public async Task<UserContract> CreateUser(string registrationReference)
        {
            //Create the new user document with default values and starting gold balance.
            var userDocument = new UserDocument
            {
                GoldBalance = 0,
                RegistrationReference = registrationReference,
                CreatedAt = new DateDocument
                {
                    Date = DateTime.UtcNow
                },
                ModifiedAt = new DateDocument
                {
                    Date = DateTime.UtcNow
                },
                GoldGiven = 0
            };

            var createdUserId =
                (await _documentClient.CreateDocumentAsync(DocumentCollectionUri, userDocument)).Resource.Id;

            // Handle gold balance changes and create transaction record
            await ExecuteGoldTransactionSproc(createdUserId, SystemUserId, _newUserGoldBalance,
                GoldTransactionType.WelcomeGoldTransaction);

            userDocument.Id = createdUserId;
            userDocument.GoldBalance = _newUserGoldBalance;

            return userDocument.ToContract();
        }