Beispiel #1
0
        public async Task <IActionResult> FlagMarkerAsImplemented(string mapId, string markerId, MarkerType markerType)
        {
            // Check Data
            KartaMap map = await _mapDbAccess.GetMapById(mapId);

            if (map == null)
            {
                return(StatusCode((int)HttpStatusCode.NotFound));
            }

            // Flag Marker as implemented
            if (markerType == MarkerType.Npc && map.NpcMarker != null)
            {
                NpcMapMarker marker = map.NpcMarker.First(m => m.Id == markerId);
                marker.IsImplemented = true;
                await _markerSnapshotDbAccess.SaveNpcMarkerSnapshot(marker);

                await _mapDbAccess.UpdateMap(map);
            }
            else if (markerType == MarkerType.Item && map.ItemMarker != null)
            {
                ItemMapMarker marker = map.ItemMarker.First(m => m.Id == markerId);
                marker.IsImplemented = true;
                await _markerSnapshotDbAccess.SaveItemMarkerSnapshot(marker);

                await _mapDbAccess.UpdateMap(map);
            }
            else if (markerType == MarkerType.MapChange && map.MapChangeMarker != null)
            {
                MapChangeMapMarker marker = map.MapChangeMarker.First(m => m.Id == markerId);
                marker.IsImplemented = true;
                await _markerSnapshotDbAccess.SaveMapChangeMarkerSnapshot(marker);

                await _mapDbAccess.UpdateMap(map);
            }
            else if (markerType == MarkerType.Quest && map.MapChangeMarker != null)
            {
                QuestMapMarker marker = map.QuestMarker.First(m => m.Id == markerId);
                marker.IsImplemented = true;
                await _markerSnapshotDbAccess.SaveQuestMarkerSnapshot(marker);

                await _mapDbAccess.UpdateMap(map);
            }
            else if (markerType == MarkerType.Note && map.NoteMarker != null)
            {
                NoteMapMarker marker = map.NoteMarker.First(m => m.Id == markerId);
                marker.IsImplemented = true;
                await _markerSnapshotDbAccess.SaveNoteMarkerSnapshot(marker);

                await _mapDbAccess.UpdateMap(map);
            }

            // Add Timeline entry
            await _timelineService.AddTimelineEntry(TimelineEvent.ImplementedMarker, mapId, markerId, markerType.ToString(), map.Name);

            return(Ok());
        }
Beispiel #2
0
        public async Task <IActionResult> SaveMapMarker(string id, [FromBody] SaveMarkerRequest markerRequest)
        {
            if ((!User.IsInRole(RoleNames.Kirja) && markerRequest.KirjaMarker != null) ||
                (!User.IsInRole(RoleNames.Kortisto) && markerRequest.NpcMarker != null) ||
                (!User.IsInRole(RoleNames.Styr) && markerRequest.ItemMarker != null) ||
                (!User.IsInRole(RoleNames.Aika) && markerRequest.QuestMarker != null))
            {
                return(StatusCode((int)HttpStatusCode.Unauthorized));
            }

            string   markerId   = string.Empty;
            string   markerType = string.Empty;
            KartaMap map        = await _mapDbAccess.GetMapById(id);

            if (markerRequest.KirjaMarker != null)
            {
                if (map.KirjaPageMarker == null)
                {
                    map.KirjaPageMarker = new List <KirjaPageMapMarker>();
                }

                markerId   = markerRequest.KirjaMarker.Id;
                markerType = MarkerType.KirjaPage.ToString();

                KirjaPageMapMarker existingMarker = map.KirjaPageMarker.FirstOrDefault(m => m.Id == markerRequest.KirjaMarker.Id);
                if (existingMarker != null)
                {
                    CopyBaseMarkerAttributes(existingMarker, markerRequest.KirjaMarker);
                    existingMarker.IsImplemented = false;
                }
                else
                {
                    map.KirjaPageMarker.Add(markerRequest.KirjaMarker);
                }
            }
            else if (markerRequest.NpcMarker != null)
            {
                if (map.NpcMarker == null)
                {
                    map.NpcMarker = new List <NpcMapMarker>();
                }

                markerId   = markerRequest.NpcMarker.Id;
                markerType = MarkerType.Npc.ToString();

                NpcMapMarker existingMarker = map.NpcMarker.FirstOrDefault(m => m.Id == markerRequest.NpcMarker.Id);
                if (existingMarker != null)
                {
                    CopyBaseMarkerAttributes(existingMarker, markerRequest.NpcMarker);
                    existingMarker.IsImplemented = false;
                }
                else
                {
                    map.NpcMarker.Add(markerRequest.NpcMarker);
                }
            }
            else if (markerRequest.ItemMarker != null)
            {
                if (map.ItemMarker == null)
                {
                    map.ItemMarker = new List <ItemMapMarker>();
                }

                markerId   = markerRequest.ItemMarker.Id;
                markerType = MarkerType.Item.ToString();

                ItemMapMarker existingMarker = map.ItemMarker.FirstOrDefault(m => m.Id == markerRequest.ItemMarker.Id);
                if (existingMarker != null)
                {
                    CopyBaseMarkerAttributes(existingMarker, markerRequest.ItemMarker);
                    existingMarker.IsImplemented = false;
                }
                else
                {
                    map.ItemMarker.Add(markerRequest.ItemMarker);
                }
            }
            else if (markerRequest.QuestMarker != null)
            {
                if (map.QuestMarker == null)
                {
                    map.QuestMarker = new List <QuestMapMarker>();
                }

                markerId   = markerRequest.QuestMarker.Id;
                markerType = MarkerType.Quest.ToString();

                QuestMapMarker existingMarker = map.QuestMarker.FirstOrDefault(m => m.Id == markerRequest.QuestMarker.Id);
                if (existingMarker != null)
                {
                    CopyBaseMarkerAttributes(existingMarker, markerRequest.QuestMarker);
                    existingMarker.Name          = markerRequest.QuestMarker.Name;
                    existingMarker.IsImplemented = false;
                }
                else
                {
                    map.QuestMarker.Add(markerRequest.QuestMarker);
                }
            }
            else if (markerRequest.MapChangeMarker != null)
            {
                if (map.MapChangeMarker == null)
                {
                    map.MapChangeMarker = new List <MapChangeMapMarker>();
                }

                markerId   = markerRequest.MapChangeMarker.Id;
                markerType = MarkerType.MapChange.ToString();

                MapChangeMapMarker existingMarker = map.MapChangeMarker.FirstOrDefault(m => m.Id == markerRequest.MapChangeMarker.Id);
                if (existingMarker != null)
                {
                    CopyBaseMarkerAttributes(existingMarker, markerRequest.MapChangeMarker);
                    existingMarker.IsImplemented = false;
                }
                else
                {
                    map.MapChangeMarker.Add(markerRequest.MapChangeMarker);
                }
            }
            else if (markerRequest.NoteMarker != null)
            {
                if (map.NoteMarker == null)
                {
                    map.NoteMarker = new List <NoteMapMarker>();
                }

                markerId   = markerRequest.NoteMarker.Id;
                markerType = MarkerType.Note.ToString();

                NoteMapMarker existingMarker = map.NoteMarker.FirstOrDefault(m => m.Id == markerRequest.NoteMarker.Id);
                if (existingMarker != null)
                {
                    CopyBaseMarkerAttributes(existingMarker, markerRequest.NoteMarker);
                    existingMarker.Name          = markerRequest.NoteMarker.Name;
                    existingMarker.Description   = markerRequest.NoteMarker.Description;
                    existingMarker.IsImplemented = false;
                }
                else
                {
                    map.NoteMarker.Add(markerRequest.NoteMarker);
                }
            }
            await _mapDbAccess.UpdateMap(map);

            string localizedMarkerType = _localizer["MarkerType" + markerType].Value;
            await _timelineService.AddTimelineEntry(TimelineEvent.KartaMapMarkerUpdated, map.Name, map.Id, markerId, markerType, localizedMarkerType);

            return(Ok(id));
        }
Beispiel #3
0
 /// <summary>
 /// Saves a map change marker snapshot
 /// </summary>
 /// <param name="snapshot">Snapshot to save</param>
 /// <returns>Task</returns>
 public async Task SaveMapChangeMarkerSnapshot(MapChangeMapMarker snapshot)
 {
     await SaveMarkerSnapshot(_MapChangeMarkerSnapshotCollection, snapshot);
 }