Beispiel #1
0
        public GameEventDetail GetGameEventByID(int id, bool isBlockID)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = new GameEvent();
                if (isBlockID)
                {
                    entity = ctx.GameEvents.Single(e => e.BlockID == id);
                }
                else
                {
                    entity = ctx.GameEvents.Single(e => e.ID == id);
                }
                var userEntity = ctx.Users.FirstOrDefault(e => e.Id == entity.OwnerID.ToString());
                int mapID      = 0;
                if (ctx.Blocks.Any(b => b.ID == entity.BlockID))
                {
                    mapID = ctx.Blocks.Single(b => b.ID == entity.BlockID).MapID;
                }
                var gameEventModel = new GameEventDetail
                {
                    ID          = entity.ID,
                    BlockID     = entity.BlockID,
                    MapID       = mapID,
                    Creator     = userEntity.UserName,
                    TypeOfEvent = entity.TypeOfEvent.ToString(),
                    Name        = entity.Name,
                    Description = entity.Description
                };

                return(gameEventModel);
            }
        }
Beispiel #2
0
        public BlockDetailsWithEvent GetBlockByID(int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity      = ctx.Blocks.Single(e => e.ID == id);
                var userEntity  = ctx.Users.FirstOrDefault(e => e.Id == entity.OwnerID.ToString());
                var blockDetail = new BlockDetail
                {
                    ID          = entity.ID,
                    MapID       = entity.MapID,
                    Creator     = userEntity.UserName,
                    TypeOfBlock = entity.TypeOfBlock.ToString(),
                    Name        = entity.Name,
                    Description = entity.Description,
                    PosX        = entity.PosX,
                    PosY        = entity.PosY,
                    HasEvent    = ctx.GameEvents.Any(ge => ge.BlockID == entity.ID)
                };

                if (entity.TypeOfBlock.ToString() == "Exit")
                {
                    var exitEntity = ctx.ExitBlocks.Single(e => e.ID == id);
                    blockDetail.ExitDirection = exitEntity.ExitDirection.ToString();
                    blockDetail.ExitToID      = exitEntity.ExitToID;
                }

                var eventDetail = new GameEventDetail();
                if (blockDetail.HasEvent)
                {
                    eventDetail = GetGameEvent(entity.ID);
                }

                return(new BlockDetailsWithEvent {
                    BlockDetail = blockDetail, GameEventDetail = eventDetail
                });
            }
        }
Beispiel #3
0
 public BlockDetailsWithEvent()
 {
     GameEventDetail = new GameEventDetail();
 }