コード例 #1
0
        public string CreateMessageNotification(TINNHAN tinNhan)
        {
            int id = tinNhan.MaTinNhan;
            string title = HttpUtility.HtmlDecode(tinNhan.TieuDe).Replace("\r\n", "");
            string sender = tinNhan.NGUOIGUIs.ElementAt(0).HoTenNguoiGui;
            string sendTime = tinNhan.ThoiDiemGui.ToString();

            var danhSachMaNguoiNhan = tinNhan.NGUOINHANs.Select(n => n.MaNguoiNhan).ToList();
            var arrRegid = FireBaseDao.GetFireBaseTokenById(danhSachMaNguoiNhan);

            if (arrRegid.Length == 0) return null;

            PushNotification notification = new PushNotification()
            {
                registration_ids = arrRegid,
                data = new Data()
                {
                    title = sender,
                    body = title,
                    id = id,
                    type = MESSAGE_NOTIFICATION,
                    postTime = sendTime
                }
            };
            string postData = JsonConvert.SerializeObject(notification);
            return postData;
        }
コード例 #2
0
        public IHttpActionResult Excute(string order, string maSinhVien, string token)
        {
            if (string.IsNullOrEmpty(order))
                return NotFound();

            else if (order.ToLower().Equals("save"))
            {
                try
                {
                    var result = FireBaseDao.AddFireBase(maSinhVien, token);

                    if (result) return Ok("Save token success");

                    return BadRequest("Token for this device/account is exist !");
                }
                catch (Exception ex)
                {
                    return BadRequest(ex.Message + "\r" + ex.StackTrace);
                }
            }
            else if (order.ToLower().Equals("delete"))
            {
                var result = FireBaseDao.DeleteFireBase(maSinhVien, token);
                if (result)
                    return Ok("Delete token success");
                return NotFound();
            }
            else
            {
                return NotFound();
            }
        }
コード例 #3
0
        public string CreateScheduleNotification(LICHHOC lichHoc)
        {
            var arrRegid = FireBaseDao.GetFireBaseTokenByClass(lichHoc.MaLopHocPhan);

            if (arrRegid.Length == 0) return null;

            var lopHocPhan = LopHocPhanDao.GetLopHocPhan(lichHoc.MaLopHocPhan);

            var phongHoc = LopHocPhanDao.GetPhongHoc(lichHoc.PhongHoc);

            var giangVien = LopHocPhanDao.GetGiangVien(lopHocPhan.GiangVienPhuTrach);
            
            ThoiKhoaBieu thoiKhoaBieu = new ThoiKhoaBieu()
            {
                MaLopHocPhan = lopHocPhan.MaLopHocPhan,
                TenLopHocPhan = lopHocPhan.TenLopHocPhan,
                NgayHoc = lichHoc.NgayHoc,
                HoVaTen = giangVien.HoVaTen,
                NgayTrongTuan = lichHoc.NgayHoc.DayOfWeek.GetHashCode() + 1,
                PhongHoc = phongHoc.MaPhong,
                TenPhong = phongHoc.TenPhong,
                TietHocBatDau = lichHoc.TietHocBatDau,
                TietHocKetThuc = lichHoc.TietHocKetThuc,
                HocKy = LopHocPhanDao.MaxMaHocKy(),
                MaSinhVien = ""
            };

            string notiBody = JsonConvert.SerializeObject(thoiKhoaBieu);

            PushNotification notification = new PushNotification() {
                registration_ids = arrRegid,
                data = new Data()
                {
                    title = "Lịch học bù",
                    body = notiBody,
                    postTime = DateTime.Now.ToString(),
                    type = SCHEDULE_NOTIFICATION
                }
            };
            string postData = JsonConvert.SerializeObject(notification);
            return postData;
        }
コード例 #4
0
        public string CreateNewsNotification(THONGBAO tHONGBAO)
        {
            int id = tHONGBAO.MaThongBao;
            string title = "Thông báo mới từ phòng đào tạo";
            string body = HttpUtility.HtmlDecode(tHONGBAO.TieuDe).Replace("\r\n", "");
            string postTime = tHONGBAO.ThoiGianDang.Value.ToString();

            string[] arrRegid = FireBaseDao.GetAllFireBase().Select(x => x.Token).Distinct().ToArray();

            PushNotification notification = new PushNotification()
            {
                registration_ids = arrRegid,
                data = new Data()
                {
                    title = title,
                    body = body,
                    id = id,
                    type = NEWS_NOTIFICATION,
                    postTime = postTime
                }
            };
            string postData = JsonConvert.SerializeObject(notification);
            return postData;
        }