I am stuck on a weird problem. I have a CashGameGeneralViewModel class which looks like this
public class CashGameGeneralViewModel
{
public string Limit { get; set; }
public int HandsPlayed { get; set; }
public float AmountWon { get; set; }
}
Here is the method that should return all hands played by a certain player:
public List<CashGameGeneralViewModel> GetAllHands(string playerToFind)
{
HoldemHandContext db = new HoldemHandContext();
int playerId = GetPlayerId(playerToFind);
var holdemHandResult = (from phh in db.PlayersInHoldemHands
from hh in db.HoldemHands
where hh.Id == phh.HandPlayed && phh.PlayerId == playerId
select new CashGameGeneralViewModel()
{
Limit = //"some text",
String.Format("{0:0.00}", hh.SBlindAmount) + "/" +
String.Format("{0:0.00}", hh.BBlindAmount),
HandsPlayed = db.HoldemHands.Distinct().Count(),
AmountWon = 0
}
).ToList();
return holdemHandResult;
}
public int GetPlayerId(string playerToFind)
{
HoldemHandContext db = new HoldemHandContext();
int playerId = (from p in db.Players
where p.ScreenName == playerToFind
select p.Id).FirstOrDefault();
return playerId;
}
The problem now is the
Limit = //"some text",
String.Format("{0:0.00}", hh.SBlindAmount) + "/" +
String.Format("{0:0.00}", hh.BBlindAmount)
part. hh.SBlindAmount and hh.BBlindAmount are float values. I wanted to use String.Format because 0.10 is shortened to 0.1 and with the string format I got it like I want it. But I am getting an exception which says:
‘The invocation of the constructor on type ‘PokerRecord.View.CashGameGeneralUC’ that matches the specified binding constraints threw an exception.’ Line number ’60’ and line position ’18’.
When I remove the string.format and put in some "regular" string everything works fine… Anyone knows why?
Another answer I just thought of, and the way I’d probably prefer to do it. I’d say just store those original values in the ViewModel and then change your Limit property to just create the string based on those values:
Edit:
I’ll add my reasoning for preferring it this way – it’s non-destructive. But that may be overkill or completely unnecessary if your ViewModel isn’t going to change much or you know you’ll never need the BigBlind/SmallBlind properties in the future.