示例#1
0
        public async Task <IActionResult> DeletePage(string id)
        {
            List <KirjaPage> kirjaPages = await _pageDbAccess.GetPagesByPage(id);

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

            List <KartaMapMarkerQueryResult> kartaMaps = await _kartaMapDbAccess.GetAllMapsKirjaPageIsMarkedIn(id);

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

            KirjaPage page = await _pageDbAccess.GetPageById(id);

            await _pageDbAccess.DeletePage(page);

            _logger.LogInformation("Page was deleted.");

            if (page.UplodadedImages != null)
            {
                DeleteUnusedImages(page.UplodadedImages);
            }

            await _timelineService.AddTimelineEntry(TimelineEvent.KirjaPageDeleted, page.Name);

            return(Ok(id));
        }
示例#2
0
        /// <summary>
        /// Syncs the page name to markers after an update
        /// </summary>
        /// <param name="id">Id of the page</param>
        /// <param name="pageName">New page name</param>
        /// <returns>Task</returns>
        private async Task SyncPageNameToMarkers(string id, string pageName)
        {
            List <KartaMapMarkerQueryResult> markerResult = await _kartaMapDbAccess.GetAllMapsKirjaPageIsMarkedIn(id);

            foreach (KartaMapMarkerQueryResult curMapQueryResult in markerResult)
            {
                KartaMap map = await _kartaMapDbAccess.GetMapById(curMapQueryResult.MapId);

                foreach (KirjaPageMapMarker curMarker in map.KirjaPageMarker)
                {
                    if (curMarker.PageId == id)
                    {
                        curMarker.PageName = pageName;
                    }
                }
                await _kartaMapDbAccess.UpdateMap(map);
            }
        }
示例#3
0
        public async Task <IActionResult> GetMapsByKirjaPageId(string pageId)
        {
            List <KartaMapMarkerQueryResult> markerQueryResult = await _mapDbAccess.GetAllMapsKirjaPageIsMarkedIn(pageId);

            return(Ok(markerQueryResult));
        }