コード例 #1
0
 public DC_GetUsersToNotify getUsersToNotify(DC_GetUsersToNotify rqTaskID)
 {
     using (BL_SchedulerServices obj = new BL_SchedulerServices())
     {
         return(obj.getUsersToNotify(rqTaskID));
     }
 }
コード例 #2
0
        public DC_GetUsersToNotify getUsersToNotify(DC_GetUsersToNotify rqTask_Id)
        {
            DC_GetUsersToNotify RunningData = new DC_GetUsersToNotify();

            try
            {
                StringBuilder sb = new StringBuilder();

                sb.Append(" DECLARE @TaskID uniqueIdentifier = '" + rqTask_Id.Task_ID.ToString() + "';");
                sb.Append(" IF EXISTS(select top 1 1  from AspNetUsers aspnt ");
                sb.Append(" Inner join AspNetUserRoles roles on aspnt.Id = roles.UserId");
                sb.Append(" inner join Supplier_Schedule ss on roles.RoleId = ss.User_Role_Id");
                sb.Append(" inner Join Supplier_Scheduled_Task tsk on ss.SupplierScheduleID = tsk.Schedule_Id  where tsk.Task_Id = @TaskID");
                sb.Append(" and aspnt.IsActive = 1 AND aspnt.UserName like '%@%.com')");
                sb.Append(" begin");
                sb.Append(" select  1 UsersFound,STUFF((select ';' + CONVERT(varchar(50), LTRIM(RTRIM(aspnt.UserName)))  from AspNetUsers aspnt");
                sb.Append(" Inner join AspNetUserRoles roles on aspnt.Id = roles.UserId");
                sb.Append(" inner join Supplier_Schedule ss on roles.RoleId = ss.User_Role_Id");
                sb.Append(" inner Join Supplier_Scheduled_Task tsk on ss.SupplierScheduleID = tsk.Schedule_Id  where tsk.Task_Id = @TaskID");
                sb.Append(" and aspnt.IsActive = 1 AND aspnt.UserName like '%@%.com'  group by  aspnt.UserName for xml path('')  ), 1, 1, '') as EmailAddress");
                sb.Append(" end");
                sb.Append(" else");
                sb.Append(" begin");
                sb.Append(" select  0 UsersFound,STUFF((select ';' + CONVERT(varchar(50), LTRIM(RTRIM(aspnt.UserName)))  from AspNetUsers aspnt");
                sb.Append(" Inner join AspNetUserRoles roles on aspnt.Id = roles.UserId");
                sb.Append(" inner join Supplier_Schedule ss on roles.RoleId = ss.User_Role_Id");
                sb.Append(" inner Join Supplier_Scheduled_Task tsk on ss.SupplierScheduleID = tsk.Schedule_Id  where tsk.Task_Id = @TaskID");
                sb.Append(" and aspnt.IsActive = 1 AND aspnt.UserName like '%@%.com'  group by  aspnt.UserName for xml path('')  ), 1, 1, '') as EmailAddress");
                sb.Append(" end");

                using (ConsumerEntities context = new ConsumerEntities())
                {
                    context.Database.CommandTimeout = 0;
                    RunningData = context.Database.SqlQuery <DC_GetUsersToNotify>(sb.ToString()).ToList().FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw new FaultException <DataContracts.DC_ErrorStatus>(new DataContracts.DC_ErrorStatus
                {
                    ErrorMessage    = "Error while fetching Email Addess.",
                    ErrorStatusCode = System.Net.HttpStatusCode.InternalServerError
                });
            }

            return(RunningData);
        }