Exemplo n.º 1
0
        public async Task <bool> Edit(Summary.TemplateRevision revision, Guid templateId)
        {
            var meta = await _metaFactory.Create();

            var edited = PublicTemplate.Events.Edited.fromRevision(revision, meta);
            var state  = await _dexie.GetTemplateState(templateId);

            return(await _transact(templateId, PublicTemplate.decideEdit(edited, templateId, state)));
        }
Exemplo n.º 2
0
        public async Task <bool> Collect(Tuple <Guid, int> exampleRevisionId, FSharpOption <Guid> deckId) // highTODO this needs serious fixing
        {
            var meta = await _metaFactory.Create();

            var exampleState = await _dexie.GetExampleState(exampleRevisionId.Item1);

            var exampleRevision = Domain.Example.getRevision(exampleRevisionId.Item1, exampleRevisionId.Item2, exampleState).ResultValue;
            var templateState   = await _dexie.GetTemplateState(exampleRevision.TemplateRevisionId.Item1);

            var templateRevision = toTemplateRevision(await _dexie.GetTemplateInstance(exampleRevision.TemplateRevisionId));
            var pointers         = PublicTemplate.getCardTemplatePointers(templateRevision, exampleRevision.FieldValues).ResultValue;
            var user             = await _userProvider.ForceSummary();

            var cardSetting = user.CardSettings.Single(x => x.IsDefault);
            var deckIds     = deckId.IsSome()
        ? SetModule.Singleton(deckId.Value)
        : (await _dexie.GetViewDecks()).Where(x => x.IsDefault).Select(x => x.Id).Pipe(SetModule.OfSeq);
            var cards      = pointers.Select(p => Stack.initCard(_clock.GetCurrentInstant(), cardSetting.Id, cardSetting.NewCardsStartingEaseFactor, p)).ToFList();
            var stackId    = Guid.NewGuid();
            var created    = Stack.init(stackId, meta, exampleRevision.TemplateRevisionId.Item1, exampleRevision.TemplateRevisionId.Item2, deckIds, exampleRevision.Title, exampleRevision.FieldValues, cards);
            var stackState = await _dexie.GetStackState(stackId);

            return(await _transact(stackId, Stack.decideCreate(created, templateState, stackState)));
        }