public async Task <int> Count(OpportunityEmailFilter filter)
        {
            IQueryable <OpportunityEmailDAO> OpportunityEmails = DataContext.OpportunityEmail.AsNoTracking();

            OpportunityEmails = DynamicFilter(OpportunityEmails, filter);
            return(await OpportunityEmails.CountAsync());
        }
        public async Task <ActionResult <List <Opportunity_OpportunityEmailDTO> > > ListOpportunityEmail([FromBody] Opportunity_OpportunityEmailFilterDTO Opportunity_OpportunityEmailFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }
            OpportunityEmailFilter OpportunityEmailFilter = new OpportunityEmailFilter();

            OpportunityEmailFilter.Skip          = Opportunity_OpportunityEmailFilterDTO.Skip;
            OpportunityEmailFilter.Take          = Opportunity_OpportunityEmailFilterDTO.Take;
            OpportunityEmailFilter.OrderBy       = OpportunityEmailOrder.Id;
            OpportunityEmailFilter.OrderType     = OrderType.ASC;
            OpportunityEmailFilter.Selects       = OpportunityEmailSelect.ALL;
            OpportunityEmailFilter.Id            = Opportunity_OpportunityEmailFilterDTO.Id;
            OpportunityEmailFilter.Title         = Opportunity_OpportunityEmailFilterDTO.Title;
            OpportunityEmailFilter.Content       = Opportunity_OpportunityEmailFilterDTO.Content;
            OpportunityEmailFilter.CreatorId     = Opportunity_OpportunityEmailFilterDTO.CreatorId;
            OpportunityEmailFilter.CreatedAt     = Opportunity_OpportunityEmailFilterDTO.CreatedAt;
            OpportunityEmailFilter.OpportunityId = Opportunity_OpportunityEmailFilterDTO.OpportunityId;
            OpportunityEmailFilter.EmailStatusId = Opportunity_OpportunityEmailFilterDTO.EmailStatusId;
            OpportunityEmailFilter.Reciepient    = Opportunity_OpportunityEmailFilterDTO.Reciepient;

            List <OpportunityEmail> OpportunityEmails = await OpportunityEmailService.List(OpportunityEmailFilter);

            List <Opportunity_OpportunityEmailDTO> Opportunity_OpportunityEmailDTOs = OpportunityEmails
                                                                                      .Select(x => new Opportunity_OpportunityEmailDTO(x)).ToList();

            return(Opportunity_OpportunityEmailDTOs);
        }
Exemple #3
0
 public async Task <OpportunityEmailFilter> ToFilter(OpportunityEmailFilter filter)
 {
     if (filter.OrFilter == null)
     {
         filter.OrFilter = new List <OpportunityEmailFilter>();
     }
     if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
     {
         return(filter);
     }
     foreach (var currentFilter in CurrentContext.Filters)
     {
         OpportunityEmailFilter subFilter = new OpportunityEmailFilter();
         filter.OrFilter.Add(subFilter);
         List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value;
         foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions)
         {
             if (FilterPermissionDefinition.Name == nameof(subFilter.Id))
             {
                 subFilter.Id = FilterBuilder.Merge(subFilter.Id, FilterPermissionDefinition.IdFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.Title))
             {
                 subFilter.Title = FilterBuilder.Merge(subFilter.Title, FilterPermissionDefinition.StringFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.Content))
             {
                 subFilter.Content = FilterBuilder.Merge(subFilter.Content, FilterPermissionDefinition.StringFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.Reciepient))
             {
                 subFilter.Reciepient = FilterBuilder.Merge(subFilter.Reciepient, FilterPermissionDefinition.StringFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.OpportunityId))
             {
                 subFilter.OpportunityId = FilterBuilder.Merge(subFilter.OpportunityId, FilterPermissionDefinition.IdFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.CreatorId))
             {
                 subFilter.CreatorId = FilterBuilder.Merge(subFilter.CreatorId, FilterPermissionDefinition.IdFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.EmailStatusId))
             {
                 subFilter.EmailStatusId = FilterBuilder.Merge(subFilter.EmailStatusId, FilterPermissionDefinition.IdFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(CurrentContext.UserId) && FilterPermissionDefinition.IdFilter != null)
             {
                 if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.IS.Id)
                 {
                 }
                 if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.ISNT.Id)
                 {
                 }
             }
         }
     }
     return(filter);
 }
Exemple #4
0
        public async Task <List <OpportunityEmail> > List(OpportunityEmailFilter OpportunityEmailFilter)
        {
            try
            {
                List <OpportunityEmail> OpportunityEmails = await UOW.OpportunityEmailRepository.List(OpportunityEmailFilter);

                return(OpportunityEmails);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(OpportunityEmailService));
            }
            return(null);
        }
Exemple #5
0
        public async Task <int> Count(OpportunityEmailFilter OpportunityEmailFilter)
        {
            try
            {
                int result = await UOW.OpportunityEmailRepository.Count(OpportunityEmailFilter);

                return(result);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(OpportunityEmailService));
            }
            return(0);
        }
        public async Task <List <OpportunityEmail> > List(OpportunityEmailFilter filter)
        {
            if (filter == null)
            {
                return(new List <OpportunityEmail>());
            }
            IQueryable <OpportunityEmailDAO> OpportunityEmailDAOs = DataContext.OpportunityEmail.AsNoTracking();

            OpportunityEmailDAOs = DynamicFilter(OpportunityEmailDAOs, filter);
            OpportunityEmailDAOs = DynamicOrder(OpportunityEmailDAOs, filter);
            List <OpportunityEmail> OpportunityEmails = await DynamicSelect(OpportunityEmailDAOs, filter);

            return(OpportunityEmails);
        }
        public async Task <bool> ValidateId(OpportunityEmail OpportunityEmail)
        {
            OpportunityEmailFilter OpportunityEmailFilter = new OpportunityEmailFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = OpportunityEmail.Id
                },
                Selects = OpportunityEmailSelect.Id
            };

            int count = await UOW.OpportunityEmailRepository.Count(OpportunityEmailFilter);

            if (count == 0)
            {
                OpportunityEmail.AddError(nameof(OpportunityEmailValidator), nameof(OpportunityEmail.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
        public async Task <ActionResult <long> > CountOpportunityEmail([FromBody] Opportunity_OpportunityEmailFilterDTO Opportunity_OpportunityEmailFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }
            OpportunityEmailFilter OpportunityEmailFilter = new OpportunityEmailFilter();

            OpportunityEmailFilter.Id            = Opportunity_OpportunityEmailFilterDTO.Id;
            OpportunityEmailFilter.Title         = Opportunity_OpportunityEmailFilterDTO.Title;
            OpportunityEmailFilter.Content       = Opportunity_OpportunityEmailFilterDTO.Content;
            OpportunityEmailFilter.CreatorId     = Opportunity_OpportunityEmailFilterDTO.CreatorId;
            OpportunityEmailFilter.CreatedAt     = Opportunity_OpportunityEmailFilterDTO.CreatedAt;
            OpportunityEmailFilter.OpportunityId = Opportunity_OpportunityEmailFilterDTO.OpportunityId;
            OpportunityEmailFilter.EmailStatusId = Opportunity_OpportunityEmailFilterDTO.EmailStatusId;
            OpportunityEmailFilter.Reciepient    = Opportunity_OpportunityEmailFilterDTO.Reciepient;

            return(await OpportunityEmailService.Count(OpportunityEmailFilter));
        }
        private IQueryable <OpportunityEmailDAO> OrFilter(IQueryable <OpportunityEmailDAO> query, OpportunityEmailFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <OpportunityEmailDAO> initQuery = query.Where(q => false);

            foreach (OpportunityEmailFilter OpportunityEmailFilter in filter.OrFilter)
            {
                IQueryable <OpportunityEmailDAO> queryable = query;
                if (OpportunityEmailFilter.Id != null && OpportunityEmailFilter.Id.HasValue)
                {
                    queryable = queryable.Where(q => q.Id, OpportunityEmailFilter.Id);
                }
                if (OpportunityEmailFilter.Title != null && OpportunityEmailFilter.Title.HasValue)
                {
                    queryable = queryable.Where(q => q.Title, OpportunityEmailFilter.Title);
                }
                if (OpportunityEmailFilter.Content != null && OpportunityEmailFilter.Content.HasValue)
                {
                    queryable = queryable.Where(q => q.Content, OpportunityEmailFilter.Content);
                }
                if (OpportunityEmailFilter.Reciepient != null && OpportunityEmailFilter.Reciepient.HasValue)
                {
                    queryable = queryable.Where(q => q.Reciepient, OpportunityEmailFilter.Reciepient);
                }
                if (OpportunityEmailFilter.OpportunityId != null && OpportunityEmailFilter.OpportunityId.HasValue)
                {
                    queryable = queryable.Where(q => q.OpportunityId, OpportunityEmailFilter.OpportunityId);
                }
                if (OpportunityEmailFilter.CreatorId != null && OpportunityEmailFilter.CreatorId.HasValue)
                {
                    queryable = queryable.Where(q => q.CreatorId, OpportunityEmailFilter.CreatorId);
                }
                if (OpportunityEmailFilter.EmailStatusId != null && OpportunityEmailFilter.EmailStatusId.HasValue)
                {
                    queryable = queryable.Where(q => q.EmailStatusId, OpportunityEmailFilter.EmailStatusId);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
 private IQueryable <OpportunityEmailDAO> DynamicFilter(IQueryable <OpportunityEmailDAO> query, OpportunityEmailFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => false));
     }
     query = query.Where(q => !q.DeletedAt.HasValue);
     if (filter.CreatedAt != null && filter.CreatedAt.HasValue)
     {
         query = query.Where(q => q.CreatedAt, filter.CreatedAt);
     }
     if (filter.UpdatedAt != null && filter.UpdatedAt.HasValue)
     {
         query = query.Where(q => q.UpdatedAt, filter.UpdatedAt);
     }
     if (filter.Id != null && filter.Id.HasValue)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.Title != null && filter.Title.HasValue)
     {
         query = query.Where(q => q.Title, filter.Title);
     }
     if (filter.Content != null && filter.Content.HasValue)
     {
         query = query.Where(q => q.Content, filter.Content);
     }
     if (filter.Reciepient != null && filter.Reciepient.HasValue)
     {
         query = query.Where(q => q.Reciepient, filter.Reciepient);
     }
     if (filter.OpportunityId != null && filter.OpportunityId.HasValue)
     {
         query = query.Where(q => q.OpportunityId, filter.OpportunityId);
     }
     if (filter.CreatorId != null && filter.CreatorId.HasValue)
     {
         query = query.Where(q => q.CreatorId, filter.CreatorId);
     }
     if (filter.EmailStatusId != null && filter.EmailStatusId.HasValue)
     {
         query = query.Where(q => q.EmailStatusId, filter.EmailStatusId);
     }
     query = OrFilter(query, filter);
     return(query);
 }
        private async Task <List <OpportunityEmail> > DynamicSelect(IQueryable <OpportunityEmailDAO> query, OpportunityEmailFilter filter)
        {
            List <OpportunityEmail> OpportunityEmails = await query.Select(q => new OpportunityEmail()
            {
                Id            = filter.Selects.Contains(OpportunityEmailSelect.Id) ? q.Id : default(long),
                Title         = filter.Selects.Contains(OpportunityEmailSelect.Title) ? q.Title : default(string),
                Content       = filter.Selects.Contains(OpportunityEmailSelect.Content) ? q.Content : default(string),
                Reciepient    = filter.Selects.Contains(OpportunityEmailSelect.Reciepient) ? q.Reciepient : default(string),
                OpportunityId = filter.Selects.Contains(OpportunityEmailSelect.Opportunity) ? q.OpportunityId : default(long),
                CreatorId     = filter.Selects.Contains(OpportunityEmailSelect.Creator) ? q.CreatorId : default(long),
                EmailStatusId = filter.Selects.Contains(OpportunityEmailSelect.EmailStatus) ? q.EmailStatusId : default(long),
                Creator       = filter.Selects.Contains(OpportunityEmailSelect.Creator) && q.Creator != null ? new AppUser
                {
                    Id             = q.Creator.Id,
                    Username       = q.Creator.Username,
                    DisplayName    = q.Creator.DisplayName,
                    Address        = q.Creator.Address,
                    Email          = q.Creator.Email,
                    Phone          = q.Creator.Phone,
                    SexId          = q.Creator.SexId,
                    Birthday       = q.Creator.Birthday,
                    Avatar         = q.Creator.Avatar,
                    Department     = q.Creator.Department,
                    OrganizationId = q.Creator.OrganizationId,
                    Longitude      = q.Creator.Longitude,
                    Latitude       = q.Creator.Latitude,
                    StatusId       = q.Creator.StatusId,
                    RowId          = q.Creator.RowId,
                    Used           = q.Creator.Used,
                } : null,
                EmailStatus = filter.Selects.Contains(OpportunityEmailSelect.EmailStatus) && q.EmailStatus != null ? new EmailStatus
                {
                    Id   = q.EmailStatus.Id,
                    Code = q.EmailStatus.Code,
                    Name = q.EmailStatus.Name,
                } : null,
                Opportunity = filter.Selects.Contains(OpportunityEmailSelect.Opportunity) && q.Opportunity != null ? new Opportunity
                {
                    Id                      = q.Opportunity.Id,
                    Name                    = q.Opportunity.Name,
                    CompanyId               = q.Opportunity.CompanyId,
                    CustomerLeadId          = q.Opportunity.CustomerLeadId,
                    ClosingDate             = q.Opportunity.ClosingDate,
                    SaleStageId             = q.Opportunity.SaleStageId,
                    ProbabilityId           = q.Opportunity.ProbabilityId,
                    PotentialResultId       = q.Opportunity.PotentialResultId,
                    LeadSourceId            = q.Opportunity.LeadSourceId,
                    AppUserId               = q.Opportunity.AppUserId,
                    CurrencyId              = q.Opportunity.CurrencyId,
                    Amount                  = q.Opportunity.Amount,
                    ForecastAmount          = q.Opportunity.ForecastAmount,
                    Description             = q.Opportunity.Description,
                    CreatorId               = q.Opportunity.CreatorId,
                    RefuseReciveSMS         = q.Opportunity.RefuseReciveSMS,
                    RefuseReciveEmail       = q.Opportunity.RefuseReciveEmail,
                    OpportunityResultTypeId = q.Opportunity.OpportunityResultTypeId,
                } : null,
                CreatedAt = q.CreatedAt,
                UpdatedAt = q.UpdatedAt,
            }).ToListAsync();

            var Ids = OpportunityEmails.Select(x => x.Id).ToList();
            var OpportunityEmailCCMappings = await DataContext.OpportunityEmailCCMapping.Where(x => Ids.Contains(x.OpportunityEmailId)).Select(x => new OpportunityEmailCCMapping
            {
                AppUserId          = x.AppUserId,
                OpportunityEmailId = x.OpportunityEmailId,
                AppUser            = x.AppUser == null ? null : new AppUser
                {
                    Id          = x.AppUser.Id,
                    Username    = x.AppUser.Username,
                    DisplayName = x.AppUser.DisplayName,
                    Email       = x.AppUser.Email,
                }
            }).ToListAsync();

            foreach (var OpportunityEmail in OpportunityEmails)
            {
                OpportunityEmail.OpportunityEmailCCMappings = OpportunityEmailCCMappings.Where(x => x.OpportunityEmailId == OpportunityEmail.Id).ToList();
            }
            return(OpportunityEmails);
        }
        private IQueryable <OpportunityEmailDAO> DynamicOrder(IQueryable <OpportunityEmailDAO> query, OpportunityEmailFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case OpportunityEmailOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

                case OpportunityEmailOrder.Title:
                    query = query.OrderBy(q => q.Title);
                    break;

                case OpportunityEmailOrder.Content:
                    query = query.OrderBy(q => q.Content);
                    break;

                case OpportunityEmailOrder.Reciepient:
                    query = query.OrderBy(q => q.Reciepient);
                    break;

                case OpportunityEmailOrder.Opportunity:
                    query = query.OrderBy(q => q.OpportunityId);
                    break;

                case OpportunityEmailOrder.Creator:
                    query = query.OrderBy(q => q.CreatorId);
                    break;

                case OpportunityEmailOrder.EmailStatus:
                    query = query.OrderBy(q => q.EmailStatusId);
                    break;
                }
                break;

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

                case OpportunityEmailOrder.Title:
                    query = query.OrderByDescending(q => q.Title);
                    break;

                case OpportunityEmailOrder.Content:
                    query = query.OrderByDescending(q => q.Content);
                    break;

                case OpportunityEmailOrder.Reciepient:
                    query = query.OrderByDescending(q => q.Reciepient);
                    break;

                case OpportunityEmailOrder.Opportunity:
                    query = query.OrderByDescending(q => q.OpportunityId);
                    break;

                case OpportunityEmailOrder.Creator:
                    query = query.OrderByDescending(q => q.CreatorId);
                    break;

                case OpportunityEmailOrder.EmailStatus:
                    query = query.OrderByDescending(q => q.EmailStatusId);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }