/// <summary> /// Add new notification /// </summary> /// <param name="model"></param> /// <returns></returns> private async Task <ResultModel <NotificationModel> > AddNotification(NotificationModel model) { ResultModel <NotificationModel> result = new ResultModel <NotificationModel>(); var entity = model.ToEntity(); entity.CreatedDate = model.CreatedDate = DateTime.Now; entity.Account = null; UnitOfWork.NotifyRepository.Add(entity); var iresult = await UnitOfWork.CommitAsync(); if (iresult > 0) { result.Status = ActionStatus.Ok; result.Data = model; } return(result); }
/// <summary> /// adds a new groupthink notification /// </summary> /// <param name="notification"></param> public int SendNotification(NotificationModel notification) { return(NotificationOp.AddNotification(notification.ToEntity(notification))); }
public bool Add(NotificationModel model, bool isProduction = false) { using (var dbContext = new MissionskyOAEntities()) { var entity = model.ToEntity(); entity.CreatedTime = DateTime.Now; dbContext.Notifications.Add(entity); dbContext.SaveChanges(); if (model.TargetUserIds != null && model.TargetUserIds.Count > 0) { foreach (var userId in model.TargetUserIds) { NotificationTargetUser nUser = new NotificationTargetUser() { Notification = entity, NotificationId = entity.Id, TargetUserId = userId }; dbContext.NotificationTargetUsers.Add(nUser); } dbContext.SaveChanges(); } try { string title = "通知"; switch (model.BusinessType) { case BusinessType.Approving: title = "审批通知"; break; case BusinessType.BookMeetingRoomSuccessAnnounce: title = "预定会议室成功"; break; case BusinessType.CacnelMeetingRoomSuccessAnnounce: title = "取消会议室预定成功"; break; case BusinessType.ExpressMessage: title = "快递消息"; break; default: break; } if (model.MessageType == NotificationType.Email) { EmailClient.Send(new List <string>() { model.Target }, null, string.IsNullOrEmpty(model.Title) ? title : model.Title, model.MessageContent); } else if (model.MessageType == NotificationType.SMessage) { //短信服务暂时没有 return(true); } else { JPushClient client = new JPushClient(JPushExtensions.app_key, JPushExtensions.master_secret); string parameters = "{\"businessType\":" + ((int)model.BusinessType).ToString() + ",\"notificationId\":" + entity.Id + "}"; if (model.BusinessType == BusinessType.AdministrationEventAnnounce) { title = string.IsNullOrEmpty(model.Title) ? "公告" : model.Title; PushPayload payload = JPushExtensions.PushBroadcast(null, title, model.MessageContent, parameters, isProduction); JPushExtensions.SendPush(payload, client); } else if (model.BusinessType == BusinessType.AssetInventory) { title = string.IsNullOrEmpty(model.Title) ? "资产盘点公告" : model.Title; PushPayload payload = JPushExtensions.PushBroadcast(null, title, model.MessageContent, parameters, isProduction); JPushExtensions.SendPush(payload, client); } else { if (!string.IsNullOrEmpty(model.Target)) { string target = model.Target; // 2. 检查邮箱的格式 if (!String.IsNullOrEmpty(model.Target) && model.Target.IsEmail()) { target = model.Target.ToLower().Split('@')[0].Replace(".", ""); } if (model.Scope == NotificationScope.UserGroup) { PushPayload payload = JPushExtensions.PushBroadcast(new string[] { target }, title, model.MessageContent, parameters, isProduction); JPushExtensions.SendPush(payload, client); } else { PushPayload payload = JPushExtensions.PushObject_android_and_ios(new string[] { target }, title, model.MessageContent, parameters, isProduction); JPushExtensions.SendPush(payload, client); } } } } } catch (Exception ex) { Console.WriteLine(ex.InnerException != null ? ex.InnerException.Message : ex.Message); return(true); } } return(true); }