예제 #1
0
 public SLAAlertFRTMailFilter ToFilter(SLAAlertFRTMailFilter filter)
 {
     if (filter.OrFilter == null)
     {
         filter.OrFilter = new List <SLAAlertFRTMailFilter>();
     }
     if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
     {
         return(filter);
     }
     foreach (var currentFilter in CurrentContext.Filters)
     {
         SLAAlertFRTMailFilter subFilter = new SLAAlertFRTMailFilter();
         filter.OrFilter.Add(subFilter);
         List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value;
         foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions)
         {
             if (FilterPermissionDefinition.Name == nameof(subFilter.Id))
             {
                 subFilter.Id = FilterPermissionDefinition.IdFilter;
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.SLAAlertFRTId))
             {
                 subFilter.SLAAlertFRTId = FilterPermissionDefinition.IdFilter;
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.Mail))
             {
                 subFilter.Mail = FilterPermissionDefinition.StringFilter;
             }
         }
     }
     return(filter);
 }
예제 #2
0
        public async Task <int> Count(SLAAlertFRTMailFilter filter)
        {
            IQueryable <SLAAlertFRTMailDAO> SLAAlertFRTMails = DataContext.SLAAlertFRTMail.AsNoTracking();

            SLAAlertFRTMails = DynamicFilter(SLAAlertFRTMails, filter);
            return(await SLAAlertFRTMails.CountAsync());
        }
예제 #3
0
        public async Task <List <SLAAlertFRTMail> > List(SLAAlertFRTMailFilter filter)
        {
            if (filter == null)
            {
                return(new List <SLAAlertFRTMail>());
            }
            IQueryable <SLAAlertFRTMailDAO> SLAAlertFRTMailDAOs = DataContext.SLAAlertFRTMail.AsNoTracking();

            SLAAlertFRTMailDAOs = DynamicFilter(SLAAlertFRTMailDAOs, filter);
            SLAAlertFRTMailDAOs = DynamicOrder(SLAAlertFRTMailDAOs, filter);
            List <SLAAlertFRTMail> SLAAlertFRTMails = await DynamicSelect(SLAAlertFRTMailDAOs, filter);

            return(SLAAlertFRTMails);
        }
예제 #4
0
        public async Task <bool> ValidateId(SLAAlertFRTMail SLAAlertFRTMail)
        {
            SLAAlertFRTMailFilter SLAAlertFRTMailFilter = new SLAAlertFRTMailFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = SLAAlertFRTMail.Id
                },
                Selects = SLAAlertFRTMailSelect.Id
            };

            int count = await UOW.SLAAlertFRTMailRepository.Count(SLAAlertFRTMailFilter);

            if (count == 0)
            {
                SLAAlertFRTMail.AddError(nameof(SLAAlertFRTMailValidator), nameof(SLAAlertFRTMail.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
예제 #5
0
        public async Task <List <SLAAlertFRTMail> > List(SLAAlertFRTMailFilter SLAAlertFRTMailFilter)
        {
            try
            {
                List <SLAAlertFRTMail> SLAAlertFRTMails = await UOW.SLAAlertFRTMailRepository.List(SLAAlertFRTMailFilter);

                return(SLAAlertFRTMails);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(SLAAlertFRTMailService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(SLAAlertFRTMailService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
예제 #6
0
        public async Task <int> Count(SLAAlertFRTMailFilter SLAAlertFRTMailFilter)
        {
            try
            {
                int result = await UOW.SLAAlertFRTMailRepository.Count(SLAAlertFRTMailFilter);

                return(result);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(SLAAlertFRTMailService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(SLAAlertFRTMailService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
예제 #7
0
        private IQueryable <SLAAlertFRTMailDAO> DynamicOrder(IQueryable <SLAAlertFRTMailDAO> query, SLAAlertFRTMailFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case SLAAlertFRTMailOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

                case SLAAlertFRTMailOrder.SLAAlertFRT:
                    query = query.OrderBy(q => q.SLAAlertFRTId);
                    break;

                case SLAAlertFRTMailOrder.Mail:
                    query = query.OrderBy(q => q.Mail);
                    break;
                }
                break;

            case OrderType.DESC:
                switch (filter.OrderBy)
                {
                case SLAAlertFRTMailOrder.Id:
                    query = query.OrderByDescending(q => q.Id);
                    break;

                case SLAAlertFRTMailOrder.SLAAlertFRT:
                    query = query.OrderByDescending(q => q.SLAAlertFRTId);
                    break;

                case SLAAlertFRTMailOrder.Mail:
                    query = query.OrderByDescending(q => q.Mail);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }
예제 #8
0
        private IQueryable <SLAAlertFRTMailDAO> OrFilter(IQueryable <SLAAlertFRTMailDAO> query, SLAAlertFRTMailFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <SLAAlertFRTMailDAO> initQuery = query.Where(q => false);

            foreach (SLAAlertFRTMailFilter SLAAlertFRTMailFilter in filter.OrFilter)
            {
                IQueryable <SLAAlertFRTMailDAO> queryable = query;
                if (SLAAlertFRTMailFilter.Id != null)
                {
                    queryable = queryable.Where(q => q.Id, SLAAlertFRTMailFilter.Id);
                }
                if (SLAAlertFRTMailFilter.SLAAlertFRTId != null)
                {
                    queryable = queryable.Where(q => q.SLAAlertFRTId.HasValue).Where(q => q.SLAAlertFRTId, SLAAlertFRTMailFilter.SLAAlertFRTId);
                }
                if (SLAAlertFRTMailFilter.Mail != null)
                {
                    queryable = queryable.Where(q => q.Mail, SLAAlertFRTMailFilter.Mail);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
예제 #9
0
 private IQueryable <SLAAlertFRTMailDAO> DynamicFilter(IQueryable <SLAAlertFRTMailDAO> query, SLAAlertFRTMailFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => false));
     }
     query = query.Where(q => !q.DeletedAt.HasValue);
     if (filter.CreatedAt != null)
     {
         query = query.Where(q => q.CreatedAt, filter.CreatedAt);
     }
     if (filter.UpdatedAt != null)
     {
         query = query.Where(q => q.UpdatedAt, filter.UpdatedAt);
     }
     if (filter.Id != null)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.SLAAlertFRTId != null)
     {
         query = query.Where(q => q.SLAAlertFRTId.HasValue).Where(q => q.SLAAlertFRTId, filter.SLAAlertFRTId);
     }
     if (filter.Mail != null)
     {
         query = query.Where(q => q.Mail, filter.Mail);
     }
     query = OrFilter(query, filter);
     return(query);
 }
예제 #10
0
        private async Task <List <SLAAlertFRTMail> > DynamicSelect(IQueryable <SLAAlertFRTMailDAO> query, SLAAlertFRTMailFilter filter)
        {
            List <SLAAlertFRTMail> SLAAlertFRTMails = await query.Select(q => new SLAAlertFRTMail()
            {
                Id            = filter.Selects.Contains(SLAAlertFRTMailSelect.Id) ? q.Id : default(long),
                SLAAlertFRTId = filter.Selects.Contains(SLAAlertFRTMailSelect.SLAAlertFRT) ? q.SLAAlertFRTId : default(long?),
                Mail          = filter.Selects.Contains(SLAAlertFRTMailSelect.Mail) ? q.Mail : default(string),
                SLAAlertFRT   = filter.Selects.Contains(SLAAlertFRTMailSelect.SLAAlertFRT) && q.SLAAlertFRT != null ? new SLAAlertFRT
                {
                    Id = q.SLAAlertFRT.Id,
                    TicketIssueLevelId = q.SLAAlertFRT.TicketIssueLevelId,
                    IsNotification     = q.SLAAlertFRT.IsNotification,
                    IsMail             = q.SLAAlertFRT.IsMail,
                    IsSMS             = q.SLAAlertFRT.IsSMS,
                    Time              = q.SLAAlertFRT.Time,
                    TimeUnitId        = q.SLAAlertFRT.TimeUnitId,
                    IsAssignedToUser  = q.SLAAlertFRT.IsAssignedToUser,
                    IsAssignedToGroup = q.SLAAlertFRT.IsAssignedToGroup,
                    SmsTemplateId     = q.SLAAlertFRT.SmsTemplateId,
                    MailTemplateId    = q.SLAAlertFRT.MailTemplateId,
                } : null,
                CreatedAt = q.CreatedAt,
                UpdatedAt = q.UpdatedAt,
            }).ToListAsync();

            return(SLAAlertFRTMails);
        }