Example #1
0
 private int?CountDraft(string currentUser)
 {
     using (WorkFlowEntities entities = new WorkFlowEntities())
     {
         var user = new ApplicationUser(entities, currentUser);
         return(user.CountDraft());
     }
 }
Example #2
0
 public static Dictionary <string, string> GetUsernames()
 {
     Employee[] data = GetData(() =>
     {
         using (WorkFlowEntities entities = new WorkFlowEntities())
         {
             return(entities.GlobalUserView.Where(p => p.EmpStatus == "A").Select(p => new Employee {
                 UserNo = p.EmployeeID, Name = p.EmployeeName
             }).ToArray());
         }
     }, "GlobalUserViews");
     return(data.DistinctBy(p => p.UserNo).ToDictionary(p => p.UserNo, p => p.Name));
 }
Example #3
0
 public static Employee[] GetAllUsers()
 {
     using (WorkFlowEntities entities = new WorkFlowEntities())
     {
         return
             (entities.GlobalUserView
              .Select(p => new Employee {
             Name = p.EmployeeName, UserNo = p.EmployeeID, Country = p.Country
         })
              .Distinct()
              .OrderBy(p => p.Country)
              .ThenBy(p => p.Name)
              .ToArray());
     }
 }
Example #4
0
        public static string GetUsernameByNo(string usernno)
        {
            if (string.IsNullOrWhiteSpace(usernno))
            {
                return(usernno);
            }
            var data = GetData(() =>
            {
                using (WorkFlowEntities entities = new WorkFlowEntities())
                {
                    return(entities.Users.Where(p => p.StatusId > 0).Select(p => new { p.UserNo, p.Username }).ToDictionary(p => p.UserNo, p => p.Username));
                }
            }, "LocalUsernames");
            string username = data.ContainsKey(usernno) ? data[usernno] : usernno;

            return(username);
        }
Example #5
0
        //#TODO
        public static string GetWF_UsernameByNo(string userno)
        {
            if (string.IsNullOrWhiteSpace(userno))
            {
                return(userno);
            }
            Employee[] data = GetData(() =>
            {
                using (WorkFlowEntities entities = new WorkFlowEntities())
                {
                    return(entities.GlobalUserView.Where(p => p.EmpStatus == "A").Select(p => new Employee {
                        UserNo = p.EmployeeID, Name = p.EmployeeName
                    }).ToArray());
                }
            }, "GlobalUserViews");
            var    user     = data.FirstOrDefault(p => p.UserNo.EqualsIgnoreCaseAndBlank(userno));
            string username = (user != null) ? user.Name : userno;

            return(username);
        }
Example #6
0
 public Approver(WorkFlowEntities entities, string applicantUser) : base(entities, applicantUser)
 {
 }
Example #7
0
 public NotificationManager(WorkFlowEntities entities, string user)
 {
     _entities    = entities;
     _currentUser = user;
 }
 public BaseWFApiController()
 {
     Entities = new WorkFlowEntities();
 }
Example #9
0
        public void Send()
        {
            foreach (PushTargetData data in _pushdata.Where(p => p.Type == PushType.Notification))
            {
                data.Id = data.ReadCaseNotificationReceiverId();
                data.ReadCaseNotificationReceiverId = null;
            }
            Task.Factory.StartNew(() =>
            {
                Broker.Start();
                using (WorkFlowEntities entities = new WorkFlowEntities())
                {
                    foreach (PushTargetData data in _pushdata.Where(p => p.Type == PushType.Inbox))
                    {
                        var action =
                            entities.WF_CaseUserActions.AsNoTracking().FirstOrDefault(p => p.FlowCaseId == data.Id);
                        var receivers =
                            entities.UserDeviceTokens.AsNoTracking().Where(
                                p => data.Users.Contains(p.UserNo.ToLower()) && p.DeviceToken != null && p.StatusId > 0);
                        if (action != null && receivers.Any())
                        {
                            foreach (var group in receivers.GroupBy(p => p.LastDeviceLang))
                            {
                                GcmNotification notification = new GcmNotification
                                {
                                    RegistrationIds = group.Select(p => p.DeviceToken).ToList(),
                                    Data            = JObject.FromObject(new
                                    {
                                        type         = "Inbox",
                                        actionId     = action.CaseUserActionId,
                                        flowCaseId   = action.FlowCaseId,
                                        department   = action.WF_FlowCases.Department,
                                        applicant    = entities.GlobalUserView.FirstOrDefault(p => p.EmployeeID.Equals(action.WF_FlowCases.UserNo))?.EmployeeName ?? action.WF_FlowCases.UserNo,
                                        templateName =
                                            entities.WF_Flows.First(p => p.FlowId == action.WF_FlowCases.FlowId)
                                            .WF_FlowGroups.WF_FlowTypes.Name,
                                        subject      = action.WF_FlowCases.Subject,
                                        templateType = entities.WF_Flows.First(p => p.FlowId == action.WF_FlowCases.FlowId)
                                                       .WF_FlowGroups.WF_FlowTypes.TemplateType ?? 0,
                                        ver              = action.WF_FlowCases.Ver ?? 0,
                                        received         = action.Created,
                                        deadline         = action.WF_FlowCases.Deadline,
                                        isFlagged        = action.WF_FlowCases.IsFlagged,
                                        isReadByApprover = action.StatusId == 2 ? 1 : 0,
                                        attachments      =
                                            action.WF_FlowCases.WF_FlowCases_Attachments.Where(q => q.StatusId > 0)
                                            .Select(q => new
                                        {
                                            attachmentId = q.AttachementId,
                                            fileName     = q.OriFileName
                                        }),
                                        lastUpdated = action.LastUpdated
                                    })
                                };

                                /*
                                 * switch (group.Key)
                                 * {
                                 *  case "en_US":
                                 *      notification.Notification = JObject.FromObject(new
                                 *      {
                                 *          title = "Inbox",
                                 *          body = "Your inbox has a new message."
                                 *      });
                                 *      break;
                                 *  case "ko_KR":
                                 *      notification.Notification = JObject.FromObject(new
                                 *      {
                                 *          title = "받은 편지함",
                                 *          body = "받은 편지함에 새 메시지가 있습니다."
                                 *      });
                                 *      break;
                                 *  case "zh_CN":
                                 *      notification.Notification = JObject.FromObject(new
                                 *      {
                                 *          title = "收信箱",
                                 *          body = "你的收信箱有新信息."
                                 *      });
                                 *      break;
                                 *  default:
                                 *      notification.Notification = JObject.FromObject(new
                                 *      {
                                 *          title = "收信箱",
                                 *          body = "你的收信箱有新消息."
                                 *      });
                                 *      break;
                                 * }*/
                                Broker.QueueNotification(notification);
                            }
                        }
                    }
                    foreach (PushTargetData data in _pushdata.Where(p => p.Type == PushType.Notification))
                    {
                        var notificationReceiver =
                            entities.WF_CaseNotificationReceivers.AsNoTracking()
                            .FirstOrDefault(p => p.CaseNotificationReceiverId == data.Id);
                        var receivers =
                            entities.UserDeviceTokens.AsNoTracking().Where(
                                p => data.Users.Contains(p.UserNo.ToLower()) && p.DeviceToken != null && p.StatusId > 0);
                        if (notificationReceiver != null && receivers.Any())
                        {
                            foreach (var group in receivers.GroupBy(p => p.LastDeviceLang))
                            {
                                GcmNotification notification = new GcmNotification
                                {
                                    RegistrationIds = group.Select(p => p.DeviceToken).ToList(),
                                    Data            = JObject.FromObject(new
                                    {
                                        type             = "Notification",
                                        notificationId   = notificationReceiver.CaseNotificationReceiverId,
                                        notificationType =
                                            notificationReceiver.WF_CaseNotifications.NotificationType,
                                        flowCaseId = notificationReceiver.WF_CaseNotifications.FlowCaseId,
                                        department =
                                            notificationReceiver.WF_CaseNotifications.WF_FlowCases.Department,
                                        applicant    = entities.GlobalUserView.FirstOrDefault(p => p.EmployeeID.Equals(notificationReceiver.WF_CaseNotifications.WF_FlowCases.UserNo))?.EmployeeName ?? notificationReceiver.WF_CaseNotifications.WF_FlowCases.UserNo,
                                        templateName =
                                            entities.WF_Flows.First(
                                                p =>
                                                p.FlowId == notificationReceiver.WF_CaseNotifications.WF_FlowCases.FlowId)
                                            .WF_FlowGroups.WF_FlowTypes.Name,
                                        subject      = notificationReceiver.WF_CaseNotifications.WF_FlowCases.Subject,
                                        templateType = entities.WF_Flows.First(
                                            p =>
                                            p.FlowId == notificationReceiver.WF_CaseNotifications.WF_FlowCases.FlowId)
                                                       .WF_FlowGroups.WF_FlowTypes.TemplateType ?? 0,
                                        ver         = notificationReceiver.WF_CaseNotifications.WF_FlowCases.Ver ?? 0,
                                        received    = notificationReceiver.WF_CaseNotifications.WF_FlowCases.Created,
                                        deadline    = notificationReceiver.WF_CaseNotifications.WF_FlowCases.Deadline,
                                        sourceType  = notificationReceiver.SourceType,
                                        sender      = notificationReceiver.WF_CaseNotifications.Sender,
                                        attachments =
                                            entities.WF_FlowCases_Attachments.Where(
                                                q =>
                                                q.StatusId > 0 &&
                                                q.FlowCaseId ==
                                                notificationReceiver.WF_CaseNotifications.FlowCaseId)
                                            .Select(q => new
                                        {
                                            attachmentId = q.AttachementId,
                                            fileName     = q.OriFileName
                                        })
                                    })
                                };

                                /*
                                 * switch (group.Key)
                                 * {
                                 *  case "en_US":
                                 *      notification.Notification = JObject.FromObject(new
                                 *      {
                                 *          title = "Notification",
                                 *          body = "Your Notification has a new message."
                                 *      });
                                 *      break;
                                 *  case "ko_KR":
                                 *      notification.Notification = JObject.FromObject(new
                                 *      {
                                 *          title = "공고",
                                 *          body = "알림에 새 메시지가 있습니다."
                                 *      });
                                 *      break;
                                 *  case "zh_CN":
                                 *      notification.Notification = JObject.FromObject(new
                                 *      {
                                 *          title = "通知",
                                 *          body = "你的通知中有新信息."
                                 *      });
                                 *      break;
                                 *  default:
                                 *      notification.Notification = JObject.FromObject(new
                                 *      {
                                 *          title = "通知",
                                 *          body = "你的通知中有新消息."
                                 *      });
                                 *      break;
                                 * }
                                 */
                                Broker.QueueNotification(notification);
                            }
                        }
                    }
                }
                Broker.Stop();
            });
        }