Beispiel #1
0
        /// <summary>
        /// Create user
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="jwtHash"></param>
        /// <param name="phoneno"></param>
        /// <param name="realname"></param>
        /// <param name="avatar"></param>
        /// <returns></returns>
        public async Task <User> Create(Pkuid uid, string jwtHash, string phoneno, string realname = "", string avatar = "")
        {
            await client.ClearCollectionAsync(User._URI_COL);

            var user = new User()
            {
                userId   = uid.ToString(),
                pk       = uid.PK,
                jwtHash  = jwtHash,
                phoneno  = phoneno,
                name     = realname,
                realname = realname,
                nickname = realname,
                avatar   = avatar,
                aliasId  = uid.PkIdx + "-" + F.NewShortGuid(),

                currencies = DefCurrencies,
            };

            try
            {
                var res = await client.CreateDocumentAsync(User._URI_COL, user, new RequestOptions
                {
                    PartitionKey = new PartitionKey(uid.PK)
                });

                Console.WriteLine(String.Format("Create User / RU: {0}", res.RequestCharge));
            }
            catch (DocumentClientException e)
            {
                if (e.StatusCode == HttpStatusCode.Conflict)
                {
                    Console.WriteLine("Conflict!! data:{0}", user.ToJson());
                }
                else
                {
                    Console.WriteLine("==CreateDocumentAsync Unknown Exception================");
                    Console.WriteLine(e.Message);
                }

                throw e;
            }

            return(user);
        }