Hi im calculating a users points based on upvotes they have recieved for posts they have submitted, events they have submitted and comments that have recieved points -
public int GetUserPoints(string userName)
{
int? postPoints = db.Posts.Where(p => p.Aspnet_User.UserName == userName).Sum(b => (int?)b.UpVotes);
int? eventPoints = db.Events.Where(p => p.Aspnet_User.UserName == userName).Sum(b => (int?)b.UpVotes);
int? commentPoints = db.Comments.Where(p => p.Aspnet_User.UserName == userName).Sum(c => (int?)c.UpVotes - (int?)c.DownVotes);
return (postPoints.HasValue ? postPoints.Value : 0) + (eventPoints.HasValue ? eventPoints.Value : 0) + (commentPoints.HasValue ? commentPoints.Value / 5 : 0);
}
Im making 3 separate db calls to achieve this. can i do this in one?
postPoints ?? 0instead of(postPoints.HasValue ? postPoints.Value : 0)