Пример #1
0
 public async Task <bool> Delete(CustomerLeadEmail CustomerLeadEmail)
 {
     if (await ValidateId(CustomerLeadEmail))
     {
     }
     return(CustomerLeadEmail.IsValidated);
 }
Пример #2
0
        public async Task <CustomerLeadEmail> Create(CustomerLeadEmail CustomerLeadEmail)
        {
            if (!await CustomerLeadEmailValidator.Create(CustomerLeadEmail))
            {
                return(CustomerLeadEmail);
            }

            try
            {
                CustomerLeadEmail.CreatorId     = CurrentContext.UserId;
                CustomerLeadEmail.EmailStatusId = EmailStatusEnum.NOT_DONE.Id;
                await UOW.CustomerLeadEmailRepository.Create(CustomerLeadEmail);

                CustomerLeadEmail = await UOW.CustomerLeadEmailRepository.Get(CustomerLeadEmail.Id);

                await Logging.CreateAuditLog(CustomerLeadEmail, new { }, nameof(CustomerLeadEmailService));

                return(CustomerLeadEmail);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerLeadEmailService));
            }
            return(null);
        }
Пример #3
0
        public async Task <bool> Delete(CustomerLeadEmail CustomerLeadEmail)
        {
            await DataContext.CustomerLeadEmail.Where(x => x.Id == CustomerLeadEmail.Id).UpdateFromQueryAsync(x => new CustomerLeadEmailDAO {
                DeletedAt = StaticParams.DateTimeNow, UpdatedAt = StaticParams.DateTimeNow
            });

            return(true);
        }
Пример #4
0
 public async Task <bool> Update(CustomerLeadEmail CustomerLeadEmail)
 {
     if (await ValidateId(CustomerLeadEmail))
     {
         await ValidateReciepient(CustomerLeadEmail);
     }
     return(CustomerLeadEmail.IsValidated);
 }
Пример #5
0
        public async Task <CustomerLeadEmail> Get(long Id)
        {
            CustomerLeadEmail CustomerLeadEmail = await UOW.CustomerLeadEmailRepository.Get(Id);

            if (CustomerLeadEmail == null)
            {
                return(null);
            }
            return(CustomerLeadEmail);
        }
Пример #6
0
        public async Task <CustomerLeadEmail> Send(CustomerLeadEmail CustomerLeadEmail)
        {
            try
            {
                var oldData = await UOW.CustomerLeadEmailRepository.Get(CustomerLeadEmail.Id);

                if (oldData == null)
                {
                    await Create(CustomerLeadEmail);
                }
                else
                {
                    await Update(CustomerLeadEmail);
                }

                var AppUserIds  = CustomerLeadEmail.CustomerLeadEmailCCMappings?.Select(x => x.AppUserId).ToList();
                var Reciepients = new List <string>();
                Reciepients.Add(CustomerLeadEmail.Reciepient);
                if (AppUserIds != null && AppUserIds.Count > 0)
                {
                    AppUserFilter AppUserFilter = new AppUserFilter
                    {
                        Skip    = 0,
                        Take    = int.MaxValue,
                        Selects = AppUserSelect.Id | AppUserSelect.Email
                    };
                    var AppUsers = await UOW.AppUserRepository.List(AppUserFilter);

                    var AppUserEmails = AppUsers.Select(x => x.Email).ToList();
                    Reciepients.AddRange(AppUserEmails);
                }
                Mail mail = new Mail
                {
                    Subject    = CustomerLeadEmail.Title,
                    Body       = CustomerLeadEmail.Content,
                    Recipients = Reciepients,
                    RowId      = Guid.NewGuid()
                };
                RabbitManager.PublishSingle(new EventMessage <Mail>(mail, mail.RowId), RoutingKeyEnum.MailSend);
                CustomerLeadEmail.EmailStatusId = EmailStatusEnum.DONE.Id;
                await UOW.CustomerLeadEmailRepository.Update(CustomerLeadEmail);

                CustomerLeadEmail = await UOW.CustomerLeadEmailRepository.Get(CustomerLeadEmail.Id);

                await Logging.CreateAuditLog(CustomerLeadEmail, new { }, nameof(CustomerLeadEmailService));

                return(CustomerLeadEmail);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerLeadEmailService));
            }
            return(null);
        }
Пример #7
0
        public async Task <ActionResult <CustomerLead_CustomerLeadEmailDTO> > GetCustomerLeadEmail([FromBody] CustomerLead_CustomerLeadEmailDTO CustomerLead_CustomerLeadEmailDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            CustomerLeadEmail CustomerLeadEmail = await CustomerLeadEmailService.Get(CustomerLead_CustomerLeadEmailDTO.Id);

            return(new CustomerLead_CustomerLeadEmailDTO(CustomerLeadEmail));
        }
 public CustomerLead_CustomerLeadEmailDTO(CustomerLeadEmail CustomerLeadEmail)
 {
     this.Id             = CustomerLeadEmail.Id;
     this.Title          = CustomerLeadEmail.Title;
     this.Content        = CustomerLeadEmail.Content;
     this.Reciepient     = CustomerLeadEmail.Reciepient;
     this.CustomerLeadId = CustomerLeadEmail.CustomerLeadId;
     this.CreatorId      = CustomerLeadEmail.CreatorId;
     this.EmailStatusId  = CustomerLeadEmail.EmailStatusId;
     this.Creator        = CustomerLeadEmail.Creator == null ? null : new CustomerLead_AppUserDTO(CustomerLeadEmail.Creator);
     this.EmailStatus    = CustomerLeadEmail.EmailStatus == null ? null : new CustomerLead_EmailStatusDTO(CustomerLeadEmail.EmailStatus);
     this.CustomerLeadEmailCCMappings = CustomerLeadEmail.CustomerLeadEmailCCMappings?.Select(x => new CustomerLead_CustomerLeadEmailCCMappingDTO(x)).ToList();
     this.CreatedAt = CustomerLeadEmail.CreatedAt;
     this.UpdatedAt = CustomerLeadEmail.UpdatedAt;
     this.Errors    = CustomerLeadEmail.Errors;
 }
Пример #9
0
 private async Task <bool> ValidateReciepient(CustomerLeadEmail CustomerLeadEmail)
 {
     if (string.IsNullOrWhiteSpace(CustomerLeadEmail.Reciepient))
     {
         CustomerLeadEmail.AddError(nameof(CustomerLeadEmailValidator), nameof(CustomerLeadEmail.Reciepient), ErrorCode.ReciepientEmpty);
     }
     else
     {
         if (!IsValidEmail(CustomerLeadEmail.Reciepient))
         {
             CustomerLeadEmail.AddError(nameof(CustomerLeadEmailValidator), nameof(CustomerLeadEmail.Reciepient), ErrorCode.ReciepientEmailInvalid);
         }
         if (CustomerLeadEmail.Reciepient.Length > 255)
         {
             CustomerLeadEmail.AddError(nameof(CustomerLeadEmailValidator), nameof(CustomerLeadEmail.Reciepient), ErrorCode.ReciepientEmailOverLength);
         }
     }
     return(CustomerLeadEmail.IsValidated);
 }
Пример #10
0
        private async Task SaveReference(CustomerLeadEmail CustomerLeadEmail)
        {
            await DataContext.CustomerLeadEmailCCMapping.Where(x => x.CustomerLeadEmailId == CustomerLeadEmail.Id).DeleteFromQueryAsync();

            if (CustomerLeadEmail.CustomerLeadEmailCCMappings != null)
            {
                List <CustomerLeadEmailCCMappingDAO> CustomerLeadEmailCCMappingDAOs = new List <CustomerLeadEmailCCMappingDAO>();
                foreach (var CustomerLeadEmailCCMapping in CustomerLeadEmail.CustomerLeadEmailCCMappings)
                {
                    CustomerLeadEmailCCMappingDAO CustomerLeadEmailCCMappingDAO = new CustomerLeadEmailCCMappingDAO
                    {
                        AppUserId           = CustomerLeadEmailCCMapping.AppUserId,
                        CustomerLeadEmailId = CustomerLeadEmail.Id,
                    };
                    CustomerLeadEmailCCMappingDAOs.Add(CustomerLeadEmailCCMappingDAO);
                }
                await DataContext.BulkMergeAsync(CustomerLeadEmailCCMappingDAOs);
            }
        }
Пример #11
0
        public async Task <bool> ValidateId(CustomerLeadEmail CustomerLeadEmail)
        {
            CustomerLeadEmailFilter CustomerLeadEmailFilter = new CustomerLeadEmailFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = CustomerLeadEmail.Id
                },
                Selects = CustomerLeadEmailSelect.Id
            };

            int count = await UOW.CustomerLeadEmailRepository.Count(CustomerLeadEmailFilter);

            if (count == 0)
            {
                CustomerLeadEmail.AddError(nameof(CustomerLeadEmailValidator), nameof(CustomerLeadEmail.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Пример #12
0
        public async Task <CustomerLeadEmail> Delete(CustomerLeadEmail CustomerLeadEmail)
        {
            if (!await CustomerLeadEmailValidator.Delete(CustomerLeadEmail))
            {
                return(CustomerLeadEmail);
            }

            try
            {
                await UOW.CustomerLeadEmailRepository.Delete(CustomerLeadEmail);

                await Logging.CreateAuditLog(new { }, CustomerLeadEmail, nameof(CustomerLeadEmailService));

                return(CustomerLeadEmail);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerLeadEmailService));
            }
            return(null);
        }
Пример #13
0
        public async Task <bool> Create(CustomerLeadEmail CustomerLeadEmail)
        {
            CustomerLeadEmailDAO CustomerLeadEmailDAO = new CustomerLeadEmailDAO();

            CustomerLeadEmailDAO.Id             = CustomerLeadEmail.Id;
            CustomerLeadEmailDAO.Title          = CustomerLeadEmail.Title;
            CustomerLeadEmailDAO.Content        = CustomerLeadEmail.Content;
            CustomerLeadEmailDAO.Reciepient     = CustomerLeadEmail.Reciepient;
            CustomerLeadEmailDAO.CustomerLeadId = CustomerLeadEmail.CustomerLeadId;
            CustomerLeadEmailDAO.CreatorId      = CustomerLeadEmail.CreatorId;
            CustomerLeadEmailDAO.EmailStatusId  = CustomerLeadEmail.EmailStatusId;
            CustomerLeadEmailDAO.CreatedAt      = StaticParams.DateTimeNow;
            CustomerLeadEmailDAO.UpdatedAt      = StaticParams.DateTimeNow;
            DataContext.CustomerLeadEmail.Add(CustomerLeadEmailDAO);
            await DataContext.SaveChangesAsync();

            CustomerLeadEmail.Id = CustomerLeadEmailDAO.Id;
            await SaveReference(CustomerLeadEmail);

            return(true);
        }
Пример #14
0
        public async Task <bool> Update(CustomerLeadEmail CustomerLeadEmail)
        {
            CustomerLeadEmailDAO CustomerLeadEmailDAO = DataContext.CustomerLeadEmail.Where(x => x.Id == CustomerLeadEmail.Id).FirstOrDefault();

            if (CustomerLeadEmailDAO == null)
            {
                return(false);
            }
            CustomerLeadEmailDAO.Id             = CustomerLeadEmail.Id;
            CustomerLeadEmailDAO.Title          = CustomerLeadEmail.Title;
            CustomerLeadEmailDAO.Content        = CustomerLeadEmail.Content;
            CustomerLeadEmailDAO.Reciepient     = CustomerLeadEmail.Reciepient;
            CustomerLeadEmailDAO.CustomerLeadId = CustomerLeadEmail.CustomerLeadId;
            CustomerLeadEmailDAO.CreatorId      = CustomerLeadEmail.CreatorId;
            CustomerLeadEmailDAO.EmailStatusId  = CustomerLeadEmail.EmailStatusId;
            CustomerLeadEmailDAO.UpdatedAt      = StaticParams.DateTimeNow;
            await DataContext.SaveChangesAsync();

            await SaveReference(CustomerLeadEmail);

            return(true);
        }
Пример #15
0
        public async Task <CustomerLeadEmail> Update(CustomerLeadEmail CustomerLeadEmail)
        {
            if (!await CustomerLeadEmailValidator.Update(CustomerLeadEmail))
            {
                return(CustomerLeadEmail);
            }
            try
            {
                var oldData = await UOW.CustomerLeadEmailRepository.Get(CustomerLeadEmail.Id);

                await UOW.CustomerLeadEmailRepository.Update(CustomerLeadEmail);

                CustomerLeadEmail = await UOW.CustomerLeadEmailRepository.Get(CustomerLeadEmail.Id);

                await Logging.CreateAuditLog(CustomerLeadEmail, oldData, nameof(CustomerLeadEmailService));

                return(CustomerLeadEmail);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerLeadEmailService));
            }
            return(null);
        }
Пример #16
0
        public async Task <bool> Create(CustomerLeadEmail CustomerLeadEmail)
        {
            await ValidateReciepient(CustomerLeadEmail);

            return(CustomerLeadEmail.IsValidated);
        }
Пример #17
0
        public async Task <CustomerLeadEmail> Get(long Id)
        {
            CustomerLeadEmail CustomerLeadEmail = await DataContext.CustomerLeadEmail.AsNoTracking()
                                                  .Where(x => x.Id == Id)
                                                  .Where(x => x.DeletedAt == null)
                                                  .Select(x => new CustomerLeadEmail()
            {
                CreatedAt      = x.CreatedAt,
                UpdatedAt      = x.UpdatedAt,
                Id             = x.Id,
                Title          = x.Title,
                Content        = x.Content,
                Reciepient     = x.Reciepient,
                CustomerLeadId = x.CustomerLeadId,
                CreatorId      = x.CreatorId,
                EmailStatusId  = x.EmailStatusId,
                CustomerLead   = x.CustomerLead == null ? null : new CustomerLead
                {
                    Id                = x.CustomerLead.Id,
                    CompanyName       = x.CustomerLead.CompanyName,
                    Name              = x.CustomerLead.Name,
                    Phone             = x.CustomerLead.Phone,
                    Email             = x.CustomerLead.Email,
                    Website           = x.CustomerLead.Website,
                    NationId          = x.CustomerLead.NationId,
                    ProvinceId        = x.CustomerLead.ProvinceId,
                    DistrictId        = x.CustomerLead.DistrictId,
                    Address           = x.CustomerLead.Address,
                    RefuseReciveEmail = x.CustomerLead.RefuseReciveEmail,
                    RefuseReciveSMS   = x.CustomerLead.RefuseReciveSMS,
                    ProfessionId      = x.CustomerLead.ProfessionId,
                    CurrencyId        = x.CustomerLead.CurrencyId,
                    CreatorId         = x.CustomerLead.CreatorId,
                    Description       = x.CustomerLead.Description,
                },
                Creator = x.Creator == null ? null : new AppUser
                {
                    Id             = x.Creator.Id,
                    Username       = x.Creator.Username,
                    DisplayName    = x.Creator.DisplayName,
                    Address        = x.Creator.Address,
                    Email          = x.Creator.Email,
                    Phone          = x.Creator.Phone,
                    SexId          = x.Creator.SexId,
                    Birthday       = x.Creator.Birthday,
                    Avatar         = x.Creator.Avatar,
                    Department     = x.Creator.Department,
                    OrganizationId = x.Creator.OrganizationId,
                    Longitude      = x.Creator.Longitude,
                    Latitude       = x.Creator.Latitude,
                    StatusId       = x.Creator.StatusId,
                    RowId          = x.Creator.RowId,
                    Used           = x.Creator.Used,
                },
                EmailStatus = x.EmailStatus == null ? null : new EmailStatus
                {
                    Id   = x.EmailStatus.Id,
                    Code = x.EmailStatus.Code,
                    Name = x.EmailStatus.Name,
                },
            }).FirstOrDefaultAsync();

            if (CustomerLeadEmail == null)
            {
                return(null);
            }

            CustomerLeadEmail.CustomerLeadEmailCCMappings = await DataContext.CustomerLeadEmailCCMapping
                                                            .Where(x => x.CustomerLeadEmailId == Id)
                                                            .Select(x => new CustomerLeadEmailCCMapping
            {
                CustomerLeadEmailId = x.CustomerLeadEmailId,
                AppUserId           = x.AppUserId,
                AppUser             = x.AppUser == null ? null : new AppUser
                {
                    Id          = x.AppUser.Id,
                    Username    = x.AppUser.Username,
                    DisplayName = x.AppUser.DisplayName,
                    Email       = x.AppUser.Email,
                }
            }).ToListAsync();

            return(CustomerLeadEmail);
        }