예제 #1
0
        public async Task <CoreTypes.Family?> EditFamily(CoreTypes.Family family)
        {
            var familyDoc = Dto.serializeFamily(family);
            var result    = await _cosmos.UpsertFamily(familyDoc);

            var resultFamily = Dto.deserializeFamily(result);

            return(resultFamily.IsOk ? resultFamily.ResultValue : null);
        }
예제 #2
0
        public async Task <Document <Family> > UpsertFamily(Document <Family> family)
        {
            HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);
            string userEmailString = CurrentUserEmail(HttpContext);
            var    userEmail       = EmailAddressModule.tryParse(userEmailString).Value;
            var    tryDeserialize  = Dto.deserializeFamily(family);

            if (tryDeserialize.IsError)
            {
                throw new InvalidOperationException($"The family document is not formatted properly: {tryDeserialize.ErrorValue}");
            }
            if (!tryDeserialize.ResultValue.Members.Contains(userEmail))
            {
                throw new InvalidOperationException("The current user must be a member of the family.");
            }
            // Could overwrite someone else's shopping list if you guessed the ID and
            // etag correctly
            var result = await _connector.UpsertFamily(family);

            return(result);
        }
예제 #3
0
        public async Task <CoreTypes.Family[]> MemberOf()
        {
            var result = await _cosmos.MemberOf("");

            return(result.Select(i => Dto.deserializeFamily(i)).Where(i => i.IsOk).Select(i => i.ResultValue).ToArray());
        }