public static void SendNotifi(string title, string messenge, string user, NDHDBEntities db, MongoHelper mongoHelp) { string sendTo = ""; string NType = "ID"; string NCode = user; string Id = Guid.NewGuid().ToString(); var firebaseInfo = db.RegFirebases.Where(p => p.UserLogin == user).FirstOrDefault(); if (firebaseInfo != null) { sendTo = firebaseInfo.RegId; title = title.ToUpper(); string json = "{ \"notification\": {\"click_action\": \"OPEN_ACTIVITY_1\" ,\"title\": \"" + title + "\",\"body\": \"" + messenge + "\"},\"data\": {\"title\": \"'" + title + "'\",\"message\": \"'" + messenge + "'\"},\"to\": \"" + sendTo + "\"}"; var responseString = HaiUtil.sendRequestFirebase(json); MongoNotificationHistory notification = new MongoNotificationHistory() { GuiId = Id, Title = title, Messenge = messenge, NType = NType, CreateTime = DateTime.Now, MessengeResult = responseString, Content = messenge, Success = 1, NCode = new List <string>(), UserRead = new List <string>() }; notification.NCode.Add(NCode); mongoHelp.saveNotificationHistory(notification); } }
// logout public void saveNotificationHistory(ref MongoNotificationHistory history) { var collection = db.GetCollection <MongoNotificationHistory>("NotificationHistory"); collection.InsertOneAsync(history); }
public ActionResult Send(string title, string messenge, string content, string user, string type, string area, string branch, string group) { if (!Utitl.CheckUser(db, User.Identity.Name, "ManageNotification", 1)) { return(RedirectToAction("relogin", "home")); } string sendTo = ""; string NType = ""; string NCode = ""; string Id = Guid.NewGuid().ToString(); if (type == "ID") { NCode = user; NType = "ID"; var firebaseInfo = db.RegFirebases.Where(p => p.UserLogin == user).FirstOrDefault(); if (firebaseInfo == null) { return(RedirectToAction("send", "notification", new { msg = "Nhân viên chưa sử dụng APP." })); } sendTo = firebaseInfo.RegId; } else { NType = "TOPIC"; sendTo = "/topics/"; if (group == "2") { // theo khu vuc sendTo += type + area; NCode = type + area; } else if (group == "3") { // theo chi nhanh sendTo += type + branch; NCode = type + branch; } else { sendTo += type + "ALL"; NCode = type + "ALL"; } } title = title.ToUpper(); string json = "{ \"notification\": {\"click_action\": \"OPEN_ACTIVITY_1\" ,\"title\": \"" + title + "\",\"body\": \"" + messenge + "\"},\"data\": {\"title\": \"'" + title + "'\",\"message\": \"'" + messenge + "'\"},\"to\": \"" + sendTo + "\"}"; var responseString = sendRequestFirebase(json); MongoNotificationHistory notification = new MongoNotificationHistory() { GuiId = Id, Title = title, Messenge = messenge, NType = NType, CreateTime = DateTime.Now, MessengeResult = responseString, Content = content, Success = 1, NCode = new List <string>(), UserRead = new List <string>() }; notification.NCode.Add(NCode); mongoHelp.saveNotificationHistory(ref notification); return(RedirectToAction("send", "notification", new { msg = "Đã gửi " + notification.GuiId })); }