예제 #1
0
 [HttpGet("Nam")]                                              // danh sách năm của view website để hiển thị chọn báo cáo
 public IActionResult Nam()
 {
     try{
         View_Store view_Store   = new View_Store();
         var        danhsachView = view_Store.getAll();          //danh sách view
         List <int> danhsachnam  = new List <int>();
         foreach (var item in danhsachView)
         {
             DateTime a   = DateTime.Parse(item.Date);
             int      dem = 0;
             for (int i = 0; i < danhsachnam.Count; i++)
             {
                 if (danhsachnam[i] == a.Year)
                 {
                     dem++;
                 }
             }
             if (dem == 0)
             {
                 danhsachnam.Add(a.Year);                            //nếu năm này chưa thêm vào danh sách thì add
             }
             if (danhsachnam.Count == 0)
             {
                 danhsachnam.Add(a.Year);                             // nếu danh sách năm chưa có thêm năm đầu tiên cho phần tử số 0
             }
         }
         return(Ok(danhsachnam));
     }
     catch {
         return(Ok("Error"));
     }
 }
예제 #2
0
 [HttpGet("ThongKeView")]                                       //Thống kê số view của website
 public IActionResult ThongKeView()
 {
     try{
         View_Store view_Store   = new View_Store();
         var        danhsachView = view_Store.getAll();
         return(Ok(danhsachView.Count));                         //trả về 1 con số hiển thị số view của website
     }
     catch {
         return(Ok("Error"));
     }
 }
예제 #3
0
 [HttpGet("ThongKeTheoNamAll")]                                   //Thống kê lượt view của website
 public IActionResult ThongKeTheoNamAll(int nam)
 {
     try{
         View_Store view_Store   = new View_Store();
         var        danhsachView = view_Store.getAll();
         int[]      thongkenam   = new int[12];                   //1 năm 12 tháng, mảng tháng trong năm
         foreach (var item in danhsachView)
         {
             DateTime a = DateTime.Parse(item.Date);
             for (int i = 0; i < 12; i++)
             {
                 if (i == a.Month - 1 && nam == a.Year)
                 {
                     thongkenam[i] = thongkenam[i] + 1;
                 }
             }
         }
         return(Ok(thongkenam));
     }
     catch {
         return(Ok("Error"));
     }
 }
예제 #4
0
 [HttpGet("ThongKeTheoThangAll")]                                    //thống kê lượt view theo tháng website
 public IActionResult ThongKeTheoThangAll(int thang, int nam)
 {
     try{
         View_Store view_Store   = new View_Store();
         var        danhsachView = view_Store.getAll();
         int        songay       = view_Store.fun(thang, nam);         //Số ngày của tháng
         int[]      thongkethang = new int[songay];
         foreach (var item in danhsachView)
         {
             DateTime a = DateTime.Parse(item.Date);
             for (int i = 0; i < songay; i++)
             {
                 if (i == a.Day - 1 && thang == a.Month && nam == a.Year)
                 {
                     thongkethang[i] = thongkethang[i] + 1;
                 }
             }
         }
         return(Ok(thongkethang));
     }
     catch {
         return(Ok("Error"));
     }
 }
예제 #5
0
 [HttpGet("ThongKeTheoNgayAll")]                                           //thống kê view theo ngày của website
 public IActionResult ThongKeTheoNgayAll(int ngay, int thang, int nam)
 {
     try{
         View_Store view_Store   = new View_Store();
         var        danhsachView = view_Store.getAll();
         int[]      thongkengay  = new int[24];                             //mảng 24 giờ của 1 ngày
         foreach (var item in danhsachView)
         {
             DateTime a    = DateTime.Parse(item.Date);
             TimeSpan Time = a.TimeOfDay;
             for (int i = 0; i < 24; i++)
             {
                 if (i == a.Hour && ngay == a.Day && thang == a.Month && nam == a.Year)   //Nếu trùng giờ thì số view sẽ tăng lên
                 {
                     thongkengay[i] = thongkengay[i] + 1;
                 }
             }
         }
         return(Ok(thongkengay));
     }
     catch {
         return(Ok("Error"));
     }
 }