public ActionResult Index() { HomeViewModel h = new HomeViewModel(); return View(h); }
public ActionResult WebClick(int? id) { tbl_Website web = new tbl_Website(); tbl_Account acc = new tbl_Account(); long coinPerClick = 0; long coinPerDay = 0; int id_acc; DateTime lastClick; long timeSpan = 0; try { DateTime now = DateTime.Now; web = db.tbl_Website.Where(m => m.ID_Web == id).FirstOrDefault(); if (web.LastClick != null) { lastClick = (DateTime)web.LastClick; timeSpan = (now - lastClick).Minutes; } else { web.LastClick = now; timeSpan = 11; } if (timeSpan > 10) { coinPerClick = (long)web.CoinPerClick; id_acc = (int)web.ID_Account; acc = db.tbl_Account.Where(m => m.ID_Account == id_acc).FirstOrDefault(); coinPerDay = (long)acc.CoinPerDay; if (coinPerDay >= coinPerClick) acc.CoinPerDay -= coinPerClick; else if (acc.TotalCoin >= coinPerClick) acc.TotalCoin -= coinPerClick; if (coinPerDay < coinPerClick && acc.TotalCoin < coinPerClick) web.Active = 0; web.LastClick = now; web.TongSoClick++; } else { web.SoClickFree++; web.TongSoClick++; } db.SaveChanges(); }catch(Exception) { } HomeViewModel h = new HomeViewModel(); return View(h); }