public async Task <bool> CreateAuditLog(object newData, object oldData, string className, [CallerMemberName] string methodName = "") { AppUser AppUser = await UOW.AppUserRepository.Get(CurrentContext.UserId); AuditLog AuditLog = new AuditLog { AppUserId = CurrentContext.UserId, AppUser = AppUser.DisplayName, ClassName = className, MethodName = methodName, ModuleName = StaticParams.ModuleName, OldData = JsonConvert.SerializeObject(oldData), NewData = JsonConvert.SerializeObject(newData), Time = StaticParams.DateTimeNow, RowId = Guid.NewGuid(), }; RabbitManager.PublishSingle(new EventMessage <AuditLog>(AuditLog, AuditLog.RowId), RoutingKeyEnum.AuditLogSend); return(true); }
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 <CustomerEmailHistory> Send(CustomerEmailHistory CustomerEmailHistory) { try { var oldData = await UOW.CustomerEmailHistoryRepository.Get(CustomerEmailHistory.Id); if (oldData == null) { await Create(CustomerEmailHistory); } else { await Update(CustomerEmailHistory); } var Reciepients = CustomerEmailHistory.CustomerCCEmailHistories?.Select(x => x.CCEmail).ToList(); if (Reciepients == null) { Reciepients = new List <string>(); } Reciepients.Add(CustomerEmailHistory.Reciepient); Mail mail = new Mail { Subject = CustomerEmailHistory.Title, Body = CustomerEmailHistory.Content, Recipients = Reciepients, RowId = Guid.NewGuid() }; RabbitManager.PublishSingle(new EventMessage <Mail>(mail, mail.RowId), RoutingKeyEnum.MailSend); CustomerEmailHistory.EmailStatusId = EmailStatusEnum.DONE.Id; await UOW.CustomerEmailHistoryRepository.Update(CustomerEmailHistory); CustomerEmailHistory = await UOW.CustomerEmailHistoryRepository.Get(CustomerEmailHistory.Id); await Logging.CreateAuditLog(CustomerEmailHistory, new { }, nameof(CustomerEmailHistoryService)); return(CustomerEmailHistory); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CustomerEmailHistoryService)); } return(null); }