public async Task <IActionResult> SetBackground(string levelId, [FromForm] List <IFormFile> files) { var level = await _levelService.Get(levelId); if (level == null) { return(NotFound()); } var image = files.FirstOrDefault(); if (image != null && image.Length > 0) { using (var ms = new MemoryStream()) { image.CopyTo(ms); var fileBytes = ms.ToArray(); string s = Convert.ToBase64String(fileBytes); level.Image = s; } } await _levelService.Update(levelId, level); return(JsonResponse.New(level)); }
public async Task <IActionResult> GetLevels() { var converted = _mapper.Map <List <LevelDto> >(await _levelService.Get()); var result = converted; return(JsonResponse.New(result)); }
public async Task <IActionResult> GetEntities(string level) { var entities = await _entityService.GetEntitiesByLevel(level); var converted = _mapper.Map <List <EntityDto> >(entities); return(JsonResponse.New(converted)); }
public async Task <IActionResult> AddLevel(LevelDto levelDto) { var level = _mapper.Map <Level>(levelDto); level.Id = Guid.NewGuid().ToString(); var result = await _levelService.Create(level); return(JsonResponse.New(_mapper.Map <LevelDto>(result))); }
public async Task <IActionResult> AddEntity(string level, EntityDto entityDto) { var entity = _mapper.Map <Entity>(entityDto); entity.Id = Guid.NewGuid().ToString(); entity.LevelId = level; var result = await _entityService.Create(entity); return(JsonResponse.New(_mapper.Map <EntityDto> (result))); }
public async Task <IActionResult> UpdateRoom(string id, RoomDto room) { var baseRoom = await _roomService.Get(id); baseRoom.CopyProperties(room); baseRoom.Id = id; await _roomService.Update(id, baseRoom); return(JsonResponse.New(_mapper.Map <RoomDto>(baseRoom))); }
public async Task <IActionResult> DeleteEntity(string entityId) { var entity = await _entityService.Get(entityId); if (entity == null) { return(NotFound("Сущность не найдена")); } await _entityService.Remove(entity); return(JsonResponse.New("ok")); }
public async Task <IActionResult> GetFundForBook(string bookId) { try { var result = await _ngonbLibraryService.SearchById(bookId); return(JsonResponse.New(result)); } catch (Exception e) { return(BadRequest("Что-то пошло не так при попытке запросить расположение книги")); } }
public async Task <IActionResult> DeleteBackground(string levelId) { var level = await _levelService.Get(levelId); if (level == null) { return(NotFound()); } level.Image = ""; await _levelService.Update(levelId, level); return(JsonResponse.New(level)); }
public async Task <IActionResult> RemoveLevel(string levelId) { var level = await _levelService.Get(levelId); if (level == null) { return(NotFound()); } await _roomService.RemoveRoomsByLevel(levelId); await _levelService.Remove(levelId); return(JsonResponse.New("ok")); }
public async Task <IActionResult> UpdateAttributes(string roomId, List <string> attributes) { var room = await _roomService.Get(roomId); if (room == null) { return(BadRequest("Нечему менять аттрибуты")); } room.Attributes = attributes; await _roomService.Update(roomId, room); return(JsonResponse.New(room)); }
public async Task <IActionResult> AddRoom(RoomDto room) { var level = await _levelService.Get(room.Level); if (level == null) { return(BadRequest("Попытка добавить на несуществующий этаж")); } var baseRoom = _mapper.Map <BaseRoom>(room); baseRoom.Id = Guid.NewGuid().ToString(); var result = await _roomService.Create(baseRoom); return(JsonResponse.New(_mapper.Map <RoomDto>(result))); }
public async Task <IActionResult> SetPhoto(string id, [FromForm] List <IFormFile> files) { var room = await _roomService.Get(id); var image = files.FirstOrDefault(); if (image != null && image.Length > 0) { using (var ms = new MemoryStream()) { image.CopyTo(ms); var fileBytes = ms.ToArray(); string s = Convert.ToBase64String(fileBytes); room.Photo = s; } } await _roomService.Update(id, room); return(JsonResponse.New(_mapper.Map <RoomDto>(room))); }
public async Task <IActionResult> BindEntity(string sourceId, string targetId) { var sourceEntity = await _entityService.Get(sourceId); var targetEntity = await _entityService.Get(targetId); if (sourceEntity == null || targetEntity == null) { return(NotFound("Сущность не найдена")); } if (sourceEntity.Type != targetEntity.Type) { return(BadRequest("Типы связываемых сущностей не совпадают")); } if (sourceEntity.Type != "stairs" && sourceEntity.Type != "elevator" && targetEntity.Type != "stairs" && targetEntity.Type != "elevator") { return(BadRequest("Попытка связать несвязываемые сущности")); } if (!sourceEntity.BoundEntitiesIds.Contains(targetId)) { sourceEntity.BoundEntitiesIds.Add(targetId); } if (!targetEntity.BoundEntitiesIds.Contains(sourceId)) { targetEntity.BoundEntitiesIds.Add(sourceId); } await _entityService.Update(sourceId, sourceEntity); await _entityService.Update(targetId, targetEntity); return(JsonResponse.New("ok")); }
private async Task <IActionResult> PathToRoom(BaseRoom sourceRoom, BaseRoom targetRoom) { var target = (BasePathable)targetRoom; var rooms = (await _roomService.Get()).Where(x => x.Type == "room" && x.Level == sourceRoom.Level); var nonPassable = (await _roomService.Get()).Where(x => x.Type != "room" && x.Level == sourceRoom.Level).ToList(); var doors = (await _entityService.GetEntitiesByType("door")).Where(x => x.LevelId == sourceRoom.Level).ToList(); var stairs = (await _entityService.GetEntitiesByType("stair")).Where(x => x.LevelId == sourceRoom.Level).ToList(); var elevators = (await _entityService.GetEntitiesByType("elevator")).Where(x => x.LevelId == sourceRoom.Level).ToList(); bool isAnotherLevel = false; if (targetRoom.Level != sourceRoom.Level) { isAnotherLevel = true; if (stairs.Any()) { } //target = stairs.First(); else if (elevators.Any()) { } // target = elevators.First(); else { return(NotFound( "Невозможно проложить путь: комнаты находятся на разных этажах, но нет ни лестниц ни лифта")); } } // строим граф соединений всех комнат var graph = new Graph <BasePathable>(); foreach (var baseRoom in rooms) // для начала добавим все комнаты { graph.AddVertex(baseRoom); } foreach (var door in doors) // потом добавим все двери { graph.AddVertex(door); foreach (var room in rooms) // и посмотрим, если дверь пересекается с комнатой, то добавим грань { bool doesIntersects = DoesIntersects(door, room); if (doesIntersects) { graph.AddEdge(new Tuple <BasePathable, BasePathable>(door, room)); graph.AddEdge(new Tuple <BasePathable, BasePathable>(room, door)); } } } if (isAnotherLevel) { foreach (var door in stairs) { foreach (var room in rooms) { bool doesIntersects = DoesIntersects(door, room); if (doesIntersects) { target = room; } } } foreach (var door in elevators) { foreach (var room in rooms) { bool doesIntersects = DoesIntersects(door, room); if (doesIntersects) { target = room; } } } } var bfsAlgo = new GraphBfsAlgorithm(); var shortestPathFunc = bfsAlgo.ShortestPathFunction(graph, rooms.First(x => x.Id == sourceRoom.Id)); try { // сначала графами строим путь var shortestPath = shortestPathFunc(rooms.First(x => x.Id == target.Id)).ToList(); /* string result = ""; * * result = result.Trim();*/ /*var result = string.Join(" ", * shortestPath.Select(x => Math.Floor(x.Position.X + (x.Size == null ? 0 : x.Size.Width / 2)) + "," + Math.Floor(x.Position.Y + (x.Size == null ? 0 : x.Size.Height / 2))));*/ string result = ""; var previous = shortestPath[0].Position + shortestPath[0].Size / 2; previous.X = Math.Floor(previous.X); previous.Y = Math.Floor(previous.Y); result += previous.X + "," + previous.Y + " "; for (int i = 1; i < shortestPath.Count() - 1; i++) { var current = shortestPath[i]; if (current.GetType() == typeof(Entity)) { result += current.Position.X + "," + current.Position.Y + " "; continue; } continue; } previous = shortestPath.Last().Position + shortestPath.Last().Size / 2; previous.X = Math.Floor(previous.X); previous.Y = Math.Floor(previous.Y); result += previous.X + "," + previous.Y; return(JsonResponse.New(result)); } catch (Exception e) { Console.WriteLine(e.Message); return(BadRequest("Не удалось построить маршрут")); } return(BadRequest("Не удалось построить маршрут")); }
public async Task <IActionResult> RemoveRoom(string id) { await _roomService.Remove(id); return(JsonResponse.New("ok")); }
public async Task <IActionResult> GetRooms() { var converted = _mapper.Map <List <RoomDto> >(await _roomService.Get()); return(JsonResponse.New(converted)); }