private dynamic PushNotification(string notificationType, string userName, string notificationId) { try { var client = new RestClient("https://fcm.googleapis.com/fcm/send"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", " application/json"); request.AddHeader("Authorization", " key=" + _config["FireBase:ServerKey"] + ""); string registrationToken = ""; FireBaseNotification firebaseNoti = new FireBaseNotification(); firebaseNoti.From = _config["FireBase:Sender"]; firebaseNoti.CollapseKey = _config["FireBase:collapseKey"]; if (notificationType == NotificationType.Add) { string teamLeadId = _userRoleServices.GetUserRoleByUserName(userName).TeamLead; registrationToken = _userLoginservices.Get(teamLeadId).registration_token; } else { registrationToken = _userLoginservices.Get(userName).registration_token; } var notification = FindOne(notificationId); firebaseNoti.RegistrationIds = new string[] { registrationToken }; firebaseNoti.Notification = new NotificationFireBase { Body = notification.message }; firebaseNoti.Data = new Data { NotificationId = new Random().Next(99999999), NotificationType = NotificationType.Add, GreenType = notification.green, RecordId = notification.Id, TotalNotifications = 1, Username = userName }; request.AddParameter(" application/json", "" + JsonConvert.SerializeObject(firebaseNoti) + "", ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); return(JsonConvert.DeserializeObject <dynamic>(response.Content)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(null); } }
public long UpdateCustomer(Customer customer) { long updateCount = 0; try { string teamLead = ""; string userName = ""; string message = ""; string type = ""; dynamic prvCustomer = _customer.Find(c => c.Id == customer.Id).FirstOrDefault(); var currUser = _userroleServices.GetUserRoleByUserName(customer.UserName); if (currUser != null) { teamLead = currUser.TeamLead; } customer.ModifiedDate = Convert.ToDateTime(DateTime.Now); customer.CreatedDate = prvCustomer.CreatedDate; updateCount = _customer.ReplaceOne(c => c.Id == customer.Id, customer).ModifiedCount; if (customer.Status.ToUpper() == CustomerStatus.SUBMIT) { // Update to CRM var dataCRMProcessing = new DataCRMProcessing { CustomerId = customer.Id, Status = DataCRMProcessingStatus.InProgress }; _dataCRMProcessingServices.CreateOne(dataCRMProcessing); // Notification userName = teamLead; if (!String.IsNullOrEmpty(customer.Result?.Reason)) { type = NotificationType.Edit; message = string.Format(Message.NotificationUpdate, customer.UserName, customer.Personal.Name); } else { type = NotificationType.Add; message = string.Format(Message.NotificationAdd, customer.UserName, customer.Personal.Name); } } else if (customer.Status.ToUpper() == CustomerStatus.REJECT) { userName = customer.UserName; type = NotificationType.TeamLeadReject; message = string.Format(Message.TeamLeadReject, teamLead, customer.Personal.Name); } else if (customer.Status.ToUpper() == CustomerStatus.APPROVE) { // send data to MC if (customer.GreenType == GeenType.GreenC) { var dataMCProcessing = new DataMCProcessing { CustomerId = customer.Id, Status = DataCRMProcessingStatus.InProgress }; _dataMCProcessingServices.CreateOne(dataMCProcessing); } userName = customer.UserName; type = NotificationType.TeamLeadApprove; message = string.Format(Message.TeamLeadApprove, teamLead, customer.Personal.Name); } if (message != "") { var objNoti = new Notification { green = GeenType.GreenC, recordId = customer.Id, isRead = false, type = type, userName = userName, message = message, createAt = Convert.ToDateTime(DateTime.Today.ToLongDateString()) }; _notificationServices.CreateOne(objNoti); } } catch (Exception ex) { updateCount = -1; _logger.LogError(ex, ex.Message); } return(updateCount); }