public static GuildMemberModel FromDbObject(Entity.guild_members dbObject) => dbObject != null ? new GuildMemberModel { Id = dbObject.pk_id, Guild = GuildModel.FromDbObject(dbObject.guild), Player = PlayerModel.FromDbObject(dbObject.player) } : null;
public List <PlayerModel> GetGuildMembers(string guildName) { var getGuildModel = GuildModel.FromDbObject(_entities.guilds.FirstOrDefault(x => x.name.Equals(guildName))); if (getGuildModel == null) { throw GuildNotFoundException.FromName(guildName); } return(_entities.guild_members.Include("player").Where(x => x.fk_guild == getGuildModel.Id).Select(x => x.player).ToList().Select(PlayerModel.FromDbObject).ToList()); }
public void AddGuildMember(string playerName, string guildName) { var getPlayerModel = PlayerModel.FromDbObject(_entities.players.FirstOrDefault(x => x.name.Equals(playerName))); if (getPlayerModel == null) { throw PlayerNotFoundException.FromName(playerName); } var guildModel = GuildModel.FromDbObject(_entities.guilds.FirstOrDefault(x => x.name.Equals(guildName))); if (guildModel == null) { throw GuildNotFoundException.FromName(guildName); } _entities.guild_members.Add(new guild_members { fk_guild = guildModel.Id, fk_player = getPlayerModel.Id }); _entities.SaveChanges(); }