投票/投票アプリケーションを作成しようとしていますが、オプションに対して行われた投票数を追跡したいと思います。投票が行われると、IDが渡され、IDに応じて、カウンターが1つ増えます。しかし、私が投票すると、もう一方のカウンターが1つに戻ります。
// ID of the option selected:
public int VotedID { get; set; }
Counters for the options:
public int BlueCornerPercent { get; set; }
public int RedCornerPercent { get; set; }
// Snippet of code - here is where I increase the counters. theFight is an instance of the model/entity.
public void HandleVotes(Fight fight)
{
// Get full fight details:
Fight theFight = db.Fights.Find(fight.FightId);
// Get fighters id's in fight:
var f1 = (from l in theFight.Fighters
select l).First();
var f2 = (from l in theFight.Fighters
select l).Last();
if (theFight.VotedID == f1.FighterID)
{
theFight.BlueCornerPercent++;
db.SaveChanges();
}
else if (theFight.VotedID == f2.FighterID)
{
theFight.RedCornerPercent++;
db.SaveChanges();
}
}
ご覧のように、私は投票されている「ファイト」を通過し、そこからカウンターを変更しています...