I have a online offer brochure (www.itilbud.dk) each time an offer is shown i would like to record it in my database, so I can keep track of views for documentation of rotation. Im using Linq2Sql and ASP.NET MVC 2.
Right now i do the following method each time i load the offers:
public List<Offer> LoadAll()
{
List<Offer> offers = sdc.Offers.Where(x=>x.Active ==true)开发者_如何转开发.OrderByDescending(x => x.Created).ToList();
IncrementRotation(offers);
return offers;
}
private void IncrementRotation(List<Offer> offers)
{
var thread = new Thread(new ParameterizedThreadStart(IncRotationsAsync));
thread.Start(offers);
IncRotationsAsync(offers);
}
private void IncRotationsAsync(Object offers)
{
List<Offer> updateOffers = (List<Offer>)offers;
OfferRepository repository = new OfferRepository();
foreach (Offer o in updateOffers)
{
o.Rotations = o.Rotations+1;
repository.Save(o);
}
}
That however sometimes fail and is not very good, any idea on how to accomplish this task?
I'd use a client side tracking mechanism in your Google Analytics. It gives you much more information to target/personalise your content and a reporting portal that don't have to build.
_gaq.push(['_trackEvent', 'catalogue', 'view', 'Prod:213');
Maybe I'm not understand something, but why do you need so much code to do "UPDATE views SET view_count = view_count+1 WHERE offer_id = ??"
精彩评论