Exemplo n.º 1
0
        public async Task <IActionResult> DeleteQuest(string id)
        {
            // Check References
            List <AikaChapterDetail> chapterDetails = await _chapterDetailDbAccess.GetChapterDetailsByQuestId(id);

            if (chapterDetails.Count > 0)
            {
                string usedInChapterDetails = string.Join(", ", chapterDetails.Select(p => p.Name));
                return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CanNotDeleteQuestUsedInChapterDetail", usedInChapterDetails].Value));
            }

            List <KirjaPage> kirjaPages = await _kirjaPageDbAccess.GetPagesByQuest(id);

            if (kirjaPages.Count > 0)
            {
                string mentionedInPages = string.Join(", ", kirjaPages.Select(p => p.Name));
                return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CanNotDeleteQuestMentionedInKirjaPage", mentionedInPages].Value));
            }

            List <TaleDialog> taleDialogs = await _taleDbAccess.GetDialogsObjectIsReferenced(id);

            taleDialogs = taleDialogs.Where(t => t.RelatedObjectId != id).ToList();
            if (taleDialogs.Count > 0)
            {
                List <KortistoNpc> npcs = await _kortistoNpcDbAccess.ResolveFlexFieldObjectNames(taleDialogs.Select(t => t.RelatedObjectId).ToList());

                string referencedInDialogs = string.Join(", ", npcs.Select(n => n.Name));
                return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CanNotDeleteQuestReferencedInTaleDialog", referencedInDialogs].Value));
            }

            List <KortistoNpc> referencedInDailyRoutines = await _kortistoNpcDbAccess.GetNpcsObjectIsReferencedInDailyRoutine(id);

            if (referencedInDailyRoutines.Count > 0)
            {
                string usedInDailyRoutines = string.Join(", ", referencedInDailyRoutines.Select(m => m.Name));
                return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CanNotDeleteQuestUsedInDailyRoutine", usedInDailyRoutines].Value));
            }

            // Delete Quest
            AikaQuest deletedQuest = await _questDbAccess.GetQuestById(id);

            await _questDbAccess.DeleteQuest(deletedQuest);

            // Delete Marker
            await _kartaMapDbAccess.DeleteMarkersOfQuest(id);

            // Timeline Entry
            await _timelineService.AddTimelineEntry(TimelineEvent.AikaQuestDeleted, deletedQuest.Name);

            return(Ok(id));
        }