public Dictionary <string, RealtimeModel> statistics() { List <getAllUser_Result> users = new List <getAllUser_Result>(); digimarketEntities1 db = new digimarketEntities1(); using (var data = db.getAllUser()) { users = data.ToList <getAllUser_Result>(); } Dictionary <string, RealtimeModel> realtimeList = new Dictionary <string, RealtimeModel>(); foreach (var user in users) { TrafficController trafficController = new TrafficController(); //List < List < UserStats >> total_stats = new List<List<UserStats>>(); RealtimeModel final = new RealtimeModel() { total_traffic = 0, message = "BackEnd Task for" + user.fullname, country_stats = new List <CountryStat>() }; List <get_user_traffic_Result> res = trafficController.get_all_sites(user.uid); foreach (var item in res) { Authorization auth = new Authorization(item.email); var result = auth.service.Data.Realtime.Get("ga:" + item.ga_id, "rt:activeUsers"); result.Dimensions = "rt:country"; result.Filters = "ga:campaign=@" + user.username; try { var response = result.Execute(); if (response.TotalResults != 0) { final.total_traffic = final.total_traffic + Int64.Parse(response.TotalsForAllResults["rt:activeUsers"]); foreach (var row in response.Rows) { // UserStats temp = user_stats.Last<UserStats>(); CountryStat cStats = new CountryStat(); cStats = final.country_stats.FirstOrDefault(x => x.country == row[0]); if (cStats == null) { cStats = new CountryStat() { country = row[0], sessions = Int64.Parse(row[1]) }; final.country_stats.Add(cStats); } else { final.country_stats.Remove(cStats); cStats.sessions = cStats.sessions + Int64.Parse(row[1]); final.country_stats.Add(cStats); } } } } catch (Exception e) { } } realtimeList.Add(user.uid, final); } return(realtimeList); }
public PaymentStats payment_details([FromBody] User user) { PaymentStats stats = new PaymentStats() { total_earned = 0, total_traffic = 0, available = 0, last_paid = 0, unpaid_traffic = 0 }; user_earned earned = new user_earned() { premium = 0, non_premium = 0 }; get_payment_Result last = new get_payment_Result(); DateTime joiningDate = new DateTime(); using (var join = new digimarketEntities1().get_joining_date(user.uid)) { joiningDate = join.FirstOrDefault <get_joining_date_Result>().date; } user_traffic traffic = new TrafficController().UserSession(new DataModel.User_Analytic_Input() { uid = user.uid, from_date = new ArticleController().convertDate(joiningDate), to_date = new ArticleController().convertDate(DateTime.Now), extra = user.username }); using (var rate = new digimarketEntities1().get_rate("premium")) { earned.premium = earned.premium + ((traffic.premium * Decimal.ToDouble(rate.FirstOrDefault <get_rate_Result>().rate)) / 1000); } using (var rate = new digimarketEntities1().get_rate("non-premium")) { earned.non_premium = earned.non_premium + ((traffic.non_premium * Decimal.ToDouble(rate.FirstOrDefault <get_rate_Result>().rate)) / 1000); } stats.total_traffic = traffic.premium + traffic.non_premium; stats.total_earned = earned.premium + earned.non_premium; using (var history = new digimarketEntities1().get_payment(user.uid)) { try { last = history.OrderByDescending(m => m.payment_date).FirstOrDefault() ?? new get_payment_Result() { traffic = 0, amount = 0, uid = user.uid }; } catch (Exception ex) { } } stats.last_paid = Decimal.ToDouble(last.amount); using (var history = new digimarketEntities1().get_total_earned(user.uid)) { try { var result = history.FirstOrDefault <get_total_earned_Result>(); stats.available = stats.total_earned - Decimal.ToDouble(result.totalAmount ?? 0); stats.unpaid_traffic = stats.total_traffic - Decimal.ToInt64(result.totalTraffic ?? 0); } catch (Exception ex) { } } return(stats); }