コード例 #1
0
        /// <summary>
        /// Creates new answerset with answers.
        /// </summary>
        /// <param name="answerSet">Answer-set data</param>
        public async Task <SelectionAnswerSet> Create(SelectionAnswerSet answerSet)
        {
            answerSet.Type = AnswerSetType.Selection;

            this.selectionAnswerSetRepository.Insert(answerSet);

            await this.unitOfWork.SaveAsync();

            return(answerSet);
        }
コード例 #2
0
        /// <summary>
        /// Updates existed answerset with new default answer strings.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="selectionAnswerSetId">The selection answer set identifier.</param>
        /// <param name="answerSet">The answer set.</param>
        /// <returns></returns>
        public async Task <ServiceActionResult <SelectionAnswerSetUpdateResult, SelectionAnswerSet> > Update(
            int customerId,
            Guid selectionAnswerSetId,
            SelectionAnswerSet answerSet
            )
        {
            var dbEntity = await Get(customerId, selectionAnswerSetId);

            if (dbEntity == null)
            {
                return
                    (new ServiceActionResult <SelectionAnswerSetUpdateResult, SelectionAnswerSet>(
                         SelectionAnswerSetUpdateResult.NotFound));
            }

            if (answerSet.SelectionAnswerChoices.Any(
                    a => !a.IsNew && dbEntity.SelectionAnswerChoices.All(ac => ac.Id != a.Id)))
            {
                return
                    (new ServiceActionResult <SelectionAnswerSetUpdateResult, SelectionAnswerSet>(
                         SelectionAnswerSetUpdateResult.IncorrectAnswerId));
            }

            foreach (var answerEntity in dbEntity.SelectionAnswerChoices.ToList())
            {
                if (answerSet.SelectionAnswerChoices.All(a => a.Id != answerEntity.Id))
                {
                    this.selectionAnswerChoiceRepository.Delete(answerEntity);
                }
            }

            foreach (var answer in answerSet.SelectionAnswerChoices)
            {
                dbEntity.AddOrUpdateAnswerChoice(answer);
            }

            dbEntity.IsMultipleChoice = answerSet.IsMultipleChoice;
            dbEntity.Name             = answerSet.Name;
            dbEntity.Tags.UpdateWith(answerSet.Tags);

            this.selectionAnswerSetRepository.Update(dbEntity);
            await this.unitOfWork.SaveAsync();

            return
                (new ServiceActionResult <SelectionAnswerSetUpdateResult, SelectionAnswerSet>(
                     SelectionAnswerSetUpdateResult.Success, dbEntity));
        }
コード例 #3
0
        /// <summary>
        /// Includes new localized string to answer choice of answer set or updates existed.
        /// </summary>
        /// <param name="answerSet"></param>
        /// <param name="answerChoiceId"></param>
        /// <param name="answerChoiceString"></param>
        public static bool AddOrUpdateLocalizedAnswerString(this SelectionAnswerSet answerSet, Guid answerChoiceId,
                                                            SelectionAnswerChoiceString answerChoiceString)
        {
            if (answerChoiceString == null)
            {
                throw new ArgumentNullException("answerChoiceString");
            }

            var answerChoiceEntity = answerSet.SelectionAnswerChoices.FirstOrDefault(a => a.Id == answerChoiceId);

            if (answerChoiceEntity == null)
            {
                return(false);
            }

            answerChoiceEntity.AddOrUpdateLocalizedString(answerChoiceString);

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Includes new or updates existed answer in answer set.
        /// </summary>
        public static void AddOrUpdateAnswerChoice(this SelectionAnswerSet answerSet, SelectionAnswerChoice answerChoice)
        {
            if (answerChoice == null)
            {
                throw new ArgumentNullException("answerChoice");
            }

            var answerChoiceEntity =
                answerSet.SelectionAnswerChoices.FirstOrDefault(
                    a => !answerChoice.Id.IsEmpty() && a.Id == answerChoice.Id);

            if (answerChoiceEntity == null)
            {
                answerSet.SelectionAnswerChoices.Add(answerChoice);
            }
            else
            {
                answerChoiceEntity.UpdateWith(answerChoice);
            }
        }
コード例 #5
0
        /// <summary>
        /// Updates cached tags and selection answer set and removes unused tags from db.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="selectionAnswerSet">The selection answer set.</param>
        /// <returns></returns>
        private async Task UpdateCachedLists(int customerId, SelectionAnswerSet selectionAnswerSet)
        {
            await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <SelectionAnswerSet, SearchEntryDto>(selectionAnswerSet));

            await tagsSearchCacheHelper.AddOrUpdateTags(customerId, selectionAnswerSet.Tags.Select(t => t.Name).ToList());

            foreach (var selectionAnswerChoice in selectionAnswerSet.SelectionAnswerChoices)
            {
                foreach (var localizedString in selectionAnswerChoice.LocalizedStrings)
                {
                    if (localizedString.AudioFileMedia != null && localizedString.AudioFileMedia.Tags != null)
                    {
                        var tagsToUpdate = localizedString.AudioFileMedia.Tags.Select(t => t.Name).ToList();
                        await tagsSearchCacheHelper.AddOrUpdateTags(customerId, tagsToUpdate);
                    }
                }
            }

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);
        }