public async Task <bool> Delete(OpportunityEmail OpportunityEmail)
 {
     if (await ValidateId(OpportunityEmail))
     {
     }
     return(OpportunityEmail.IsValidated);
 }
Beispiel #2
0
        public async Task <OpportunityEmail> Create(OpportunityEmail OpportunityEmail)
        {
            if (!await OpportunityEmailValidator.Create(OpportunityEmail))
            {
                return(OpportunityEmail);
            }

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

                OpportunityEmail = await UOW.OpportunityEmailRepository.Get(OpportunityEmail.Id);

                await Logging.CreateAuditLog(OpportunityEmail, new { }, nameof(OpportunityEmailService));

                return(OpportunityEmail);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(OpportunityEmailService));
            }
            return(null);
        }
        public async Task <bool> Delete(OpportunityEmail OpportunityEmail)
        {
            await DataContext.OpportunityEmail.Where(x => x.Id == OpportunityEmail.Id).UpdateFromQueryAsync(x => new OpportunityEmailDAO {
                DeletedAt = StaticParams.DateTimeNow, UpdatedAt = StaticParams.DateTimeNow
            });

            return(true);
        }
Beispiel #4
0
        public async Task <OpportunityEmail> Get(long Id)
        {
            OpportunityEmail OpportunityEmail = await UOW.OpportunityEmailRepository.Get(Id);

            if (OpportunityEmail == null)
            {
                return(null);
            }
            return(OpportunityEmail);
        }
Beispiel #5
0
        public async Task <OpportunityEmail> Send(OpportunityEmail OpportunityEmail)
        {
            try
            {
                var oldData = await UOW.OpportunityEmailRepository.Get(OpportunityEmail.Id);

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

                var AppUserIds  = OpportunityEmail.OpportunityEmailCCMappings?.Select(x => x.AppUserId).ToList();
                var Reciepients = new List <string>();
                Reciepients.Add(OpportunityEmail.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    = OpportunityEmail.Title,
                    Body       = OpportunityEmail.Content,
                    Recipients = Reciepients,
                    RowId      = Guid.NewGuid()
                };
                RabbitManager.PublishSingle(new EventMessage <Mail>(mail, mail.RowId), RoutingKeyEnum.MailSend);
                OpportunityEmail.EmailStatusId = EmailStatusEnum.DONE.Id;
                await UOW.OpportunityEmailRepository.Update(OpportunityEmail);

                OpportunityEmail = await UOW.OpportunityEmailRepository.Get(OpportunityEmail.Id);

                await Logging.CreateAuditLog(OpportunityEmail, new { }, nameof(OpportunityEmailService));

                return(OpportunityEmail);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(OpportunityEmailService));
            }
            return(null);
        }
        public async Task <ActionResult <Opportunity_OpportunityEmailDTO> > GetOpportunityEmail([FromBody] Opportunity_OpportunityEmailDTO Opportunity_OpportunityEmailDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            OpportunityEmail OpportunityEmail = await OpportunityEmailService.Get(Opportunity_OpportunityEmailDTO.Id);

            return(new Opportunity_OpportunityEmailDTO(OpportunityEmail));
        }
 public Opportunity_OpportunityEmailDTO(OpportunityEmail OpportunityEmail)
 {
     this.Id            = OpportunityEmail.Id;
     this.Title         = OpportunityEmail.Title;
     this.Content       = OpportunityEmail.Content;
     this.Reciepient    = OpportunityEmail.Reciepient;
     this.OpportunityId = OpportunityEmail.OpportunityId;
     this.CreatorId     = OpportunityEmail.CreatorId;
     this.EmailStatusId = OpportunityEmail.EmailStatusId;
     this.Creator       = OpportunityEmail.Creator == null ? null : new Opportunity_AppUserDTO(OpportunityEmail.Creator);
     this.EmailStatus   = OpportunityEmail.EmailStatus == null ? null : new Opportunity_EmailStatusDTO(OpportunityEmail.EmailStatus);
     this.OpportunityEmailCCMappings = OpportunityEmail.OpportunityEmailCCMappings?.Select(x => new Opportunity_OpportunityEmailCCMappingDTO(x)).ToList();
     this.CreatedAt = OpportunityEmail.CreatedAt;
     this.UpdatedAt = OpportunityEmail.UpdatedAt;
     this.Errors    = OpportunityEmail.Errors;
 }
        private async Task SaveReference(OpportunityEmail OpportunityEmail)
        {
            await DataContext.OpportunityEmailCCMapping.Where(x => x.OpportunityEmailId == OpportunityEmail.Id).DeleteFromQueryAsync();

            if (OpportunityEmail.OpportunityEmailCCMappings != null)
            {
                List <OpportunityEmailCCMappingDAO> OpportunityEmailCCMappingDAOs = new List <OpportunityEmailCCMappingDAO>();
                foreach (var OpportunityEmailCCMapping in OpportunityEmail.OpportunityEmailCCMappings)
                {
                    OpportunityEmailCCMappingDAO OpportunityEmailCCMappingDAO = new OpportunityEmailCCMappingDAO
                    {
                        AppUserId          = OpportunityEmailCCMapping.AppUserId,
                        OpportunityEmailId = OpportunityEmail.Id,
                    };
                    OpportunityEmailCCMappingDAOs.Add(OpportunityEmailCCMappingDAO);
                }
                await DataContext.BulkMergeAsync(OpportunityEmailCCMappingDAOs);
            }
        }
 private async Task <bool> ValidateReciepient(OpportunityEmail OpportunityEmail)
 {
     if (string.IsNullOrWhiteSpace(OpportunityEmail.Reciepient))
     {
         OpportunityEmail.AddError(nameof(OpportunityEmailValidator), nameof(OpportunityEmail.Reciepient), ErrorCode.ReciepientEmpty);
     }
     else
     {
         if (!IsValidEmail(OpportunityEmail.Reciepient))
         {
             OpportunityEmail.AddError(nameof(OpportunityEmailValidator), nameof(OpportunityEmail.Reciepient), ErrorCode.ReciepientEmailInvalid);
         }
         if (OpportunityEmail.Reciepient.Length > 255)
         {
             OpportunityEmail.AddError(nameof(OpportunityEmailValidator), nameof(OpportunityEmail.Reciepient), ErrorCode.ReciepientEmailOverLength);
         }
     }
     return(OpportunityEmail.IsValidated);
 }
        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);
        }
Beispiel #11
0
        public async Task <OpportunityEmail> Delete(OpportunityEmail OpportunityEmail)
        {
            if (!await OpportunityEmailValidator.Delete(OpportunityEmail))
            {
                return(OpportunityEmail);
            }

            try
            {
                await UOW.OpportunityEmailRepository.Delete(OpportunityEmail);

                await Logging.CreateAuditLog(new { }, OpportunityEmail, nameof(OpportunityEmailService));

                return(OpportunityEmail);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(OpportunityEmailService));
            }
            return(null);
        }
        public async Task <bool> Create(OpportunityEmail OpportunityEmail)
        {
            OpportunityEmailDAO OpportunityEmailDAO = new OpportunityEmailDAO();

            OpportunityEmailDAO.Id            = OpportunityEmail.Id;
            OpportunityEmailDAO.Title         = OpportunityEmail.Title;
            OpportunityEmailDAO.Content       = OpportunityEmail.Content;
            OpportunityEmailDAO.Reciepient    = OpportunityEmail.Reciepient;
            OpportunityEmailDAO.OpportunityId = OpportunityEmail.OpportunityId;
            OpportunityEmailDAO.CreatorId     = OpportunityEmail.CreatorId;
            OpportunityEmailDAO.EmailStatusId = OpportunityEmail.EmailStatusId;
            OpportunityEmailDAO.CreatedAt     = StaticParams.DateTimeNow;
            OpportunityEmailDAO.UpdatedAt     = StaticParams.DateTimeNow;
            DataContext.OpportunityEmail.Add(OpportunityEmailDAO);
            await DataContext.SaveChangesAsync();

            OpportunityEmail.Id = OpportunityEmailDAO.Id;
            await SaveReference(OpportunityEmail);

            return(true);
        }
        public async Task <bool> Update(OpportunityEmail OpportunityEmail)
        {
            OpportunityEmailDAO OpportunityEmailDAO = DataContext.OpportunityEmail.Where(x => x.Id == OpportunityEmail.Id).FirstOrDefault();

            if (OpportunityEmailDAO == null)
            {
                return(false);
            }
            OpportunityEmailDAO.Id            = OpportunityEmail.Id;
            OpportunityEmailDAO.Title         = OpportunityEmail.Title;
            OpportunityEmailDAO.Content       = OpportunityEmail.Content;
            OpportunityEmailDAO.Reciepient    = OpportunityEmail.Reciepient;
            OpportunityEmailDAO.OpportunityId = OpportunityEmail.OpportunityId;
            OpportunityEmailDAO.CreatorId     = OpportunityEmail.CreatorId;
            OpportunityEmailDAO.EmailStatusId = OpportunityEmail.EmailStatusId;
            OpportunityEmailDAO.UpdatedAt     = StaticParams.DateTimeNow;
            await DataContext.SaveChangesAsync();

            await SaveReference(OpportunityEmail);

            return(true);
        }
Beispiel #14
0
        public async Task <OpportunityEmail> Update(OpportunityEmail OpportunityEmail)
        {
            if (!await OpportunityEmailValidator.Update(OpportunityEmail))
            {
                return(OpportunityEmail);
            }
            try
            {
                var oldData = await UOW.OpportunityEmailRepository.Get(OpportunityEmail.Id);

                await UOW.OpportunityEmailRepository.Update(OpportunityEmail);

                OpportunityEmail = await UOW.OpportunityEmailRepository.Get(OpportunityEmail.Id);

                await Logging.CreateAuditLog(OpportunityEmail, oldData, nameof(OpportunityEmailService));

                return(OpportunityEmail);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(OpportunityEmailService));
            }
            return(null);
        }
        public async Task <OpportunityEmail> Get(long Id)
        {
            OpportunityEmail OpportunityEmail = await DataContext.OpportunityEmail.AsNoTracking()
                                                .Where(x => x.Id == Id)
                                                .Where(x => x.DeletedAt == null)
                                                .Select(x => new OpportunityEmail()
            {
                CreatedAt     = x.CreatedAt,
                UpdatedAt     = x.UpdatedAt,
                Id            = x.Id,
                Title         = x.Title,
                Content       = x.Content,
                Reciepient    = x.Reciepient,
                OpportunityId = x.OpportunityId,
                CreatorId     = x.CreatorId,
                EmailStatusId = x.EmailStatusId,
                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,
                },
                Opportunity = x.Opportunity == null ? null : new Opportunity
                {
                    Id                      = x.Opportunity.Id,
                    Name                    = x.Opportunity.Name,
                    CompanyId               = x.Opportunity.CompanyId,
                    CustomerLeadId          = x.Opportunity.CustomerLeadId,
                    ClosingDate             = x.Opportunity.ClosingDate,
                    SaleStageId             = x.Opportunity.SaleStageId,
                    ProbabilityId           = x.Opportunity.ProbabilityId,
                    PotentialResultId       = x.Opportunity.PotentialResultId,
                    LeadSourceId            = x.Opportunity.LeadSourceId,
                    AppUserId               = x.Opportunity.AppUserId,
                    CurrencyId              = x.Opportunity.CurrencyId,
                    Amount                  = x.Opportunity.Amount,
                    ForecastAmount          = x.Opportunity.ForecastAmount,
                    Description             = x.Opportunity.Description,
                    CreatorId               = x.Opportunity.CreatorId,
                    RefuseReciveSMS         = x.Opportunity.RefuseReciveSMS,
                    RefuseReciveEmail       = x.Opportunity.RefuseReciveEmail,
                    OpportunityResultTypeId = x.Opportunity.OpportunityResultTypeId,
                },
            }).FirstOrDefaultAsync();

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

            OpportunityEmail.OpportunityEmailCCMappings = await DataContext.OpportunityEmailCCMapping
                                                          .Where(x => x.OpportunityEmailId == Id)
                                                          .Select(x => new OpportunityEmailCCMapping
            {
                OpportunityEmailId = x.OpportunityEmailId,
                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(OpportunityEmail);
        }
        public async Task <bool> Create(OpportunityEmail OpportunityEmail)
        {
            await ValidateReciepient(OpportunityEmail);

            return(OpportunityEmail.IsValidated);
        }