public async Task <bool> Delete(CustomerEmailHistory CustomerEmailHistory)
 {
     if (await ValidateId(CustomerEmailHistory))
     {
     }
     return(CustomerEmailHistory.IsValidated);
 }
Ejemplo n.º 2
0
        public async Task <bool> Delete(CustomerEmailHistory CustomerEmailHistory)
        {
            await DataContext.CustomerEmailHistory.Where(x => x.Id == CustomerEmailHistory.Id).UpdateFromQueryAsync(x => new CustomerEmailHistoryDAO {
                DeletedAt = StaticParams.DateTimeNow, UpdatedAt = StaticParams.DateTimeNow
            });

            return(true);
        }
Ejemplo n.º 3
0
        public async Task <CustomerEmailHistory> Get(long Id)
        {
            CustomerEmailHistory CustomerEmailHistory = await UOW.CustomerEmailHistoryRepository.Get(Id);

            if (CustomerEmailHistory == null)
            {
                return(null);
            }
            return(CustomerEmailHistory);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Customer_CustomerEmailHistoryDTO> > GetCustomerEmailHistory([FromBody] Customer_CustomerEmailHistoryDTO Customer_CustomerEmailHistoryDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            CustomerEmailHistory CustomerEmailHistory = await CustomerEmailHistoryService.Get(Customer_CustomerEmailHistoryDTO.Id);

            return(new Customer_CustomerEmailHistoryDTO(CustomerEmailHistory));
        }
 public Customer_CustomerEmailHistoryDTO(CustomerEmailHistory CustomerEmailHistory)
 {
     this.Id                       = CustomerEmailHistory.Id;
     this.Title                    = CustomerEmailHistory.Title;
     this.Content                  = CustomerEmailHistory.Content;
     this.Reciepient               = CustomerEmailHistory.Reciepient;
     this.CustomerId               = CustomerEmailHistory.CustomerId;
     this.CreatorId                = CustomerEmailHistory.CreatorId;
     this.EmailStatusId            = CustomerEmailHistory.EmailStatusId;
     this.CreatedAt                = CustomerEmailHistory.CreatedAt;
     this.UpdatedAt                = CustomerEmailHistory.UpdatedAt;
     this.Creator                  = CustomerEmailHistory.Creator == null ? null : new Customer_AppUserDTO(CustomerEmailHistory.Creator);
     this.Customer                 = CustomerEmailHistory.Customer == null ? null : new Customer_CustomerDTO(CustomerEmailHistory.Customer);
     this.EmailStatus              = CustomerEmailHistory.EmailStatus == null ? null : new Customer_EmailStatusDTO(CustomerEmailHistory.EmailStatus);
     this.CustomerCCEmailHistories = CustomerEmailHistory.CustomerCCEmailHistories?.Select(x => new Customer_CustomerCCEmailHistoryDTO(x)).ToList();
     this.Errors                   = CustomerEmailHistory.Errors;
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        private async Task SaveReference(CustomerEmailHistory CustomerEmailHistory)
        {
            await DataContext.CustomerCCEmailHistory.Where(x => x.CustomerEmailHistoryId == CustomerEmailHistory.Id).DeleteFromQueryAsync();

            if (CustomerEmailHistory.CustomerCCEmailHistories != null)
            {
                List <CustomerCCEmailHistoryDAO> CustomerCCEmailHistoryDAOs = new List <CustomerCCEmailHistoryDAO>();
                foreach (var CustomerCCEmailHistory in CustomerEmailHistory.CustomerCCEmailHistories)
                {
                    CustomerCCEmailHistoryDAO CustomerCCEmailHistoryDAO = new CustomerCCEmailHistoryDAO
                    {
                        Id = CustomerCCEmailHistory.Id,
                        CustomerEmailHistoryId = CustomerEmailHistory.Id,
                        CCEmail = CustomerCCEmailHistory.CCEmail
                    };
                    CustomerCCEmailHistoryDAOs.Add(CustomerCCEmailHistoryDAO);
                }
                await DataContext.BulkMergeAsync(CustomerCCEmailHistoryDAOs);
            }
        }
        public async Task <bool> ValidateId(CustomerEmailHistory CustomerEmailHistory)
        {
            CustomerEmailHistoryFilter CustomerEmailHistoryFilter = new CustomerEmailHistoryFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = CustomerEmailHistory.Id
                },
                Selects = CustomerEmailHistorySelect.Id
            };

            int count = await UOW.CustomerEmailHistoryRepository.Count(CustomerEmailHistoryFilter);

            if (count == 0)
            {
                CustomerEmailHistory.AddError(nameof(CustomerEmailHistoryValidator), nameof(CustomerEmailHistory.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Ejemplo n.º 9
0
        public async Task <bool> Create(CustomerEmailHistory CustomerEmailHistory)
        {
            CustomerEmailHistoryDAO CustomerEmailHistoryDAO = new CustomerEmailHistoryDAO();

            CustomerEmailHistoryDAO.Id            = CustomerEmailHistory.Id;
            CustomerEmailHistoryDAO.Title         = CustomerEmailHistory.Title;
            CustomerEmailHistoryDAO.Content       = CustomerEmailHistory.Content;
            CustomerEmailHistoryDAO.Reciepient    = CustomerEmailHistory.Reciepient;
            CustomerEmailHistoryDAO.CustomerId    = CustomerEmailHistory.CustomerId;
            CustomerEmailHistoryDAO.CreatorId     = CustomerEmailHistory.CreatorId;
            CustomerEmailHistoryDAO.EmailStatusId = CustomerEmailHistory.EmailStatusId;
            CustomerEmailHistoryDAO.CreatedAt     = StaticParams.DateTimeNow;
            CustomerEmailHistoryDAO.UpdatedAt     = StaticParams.DateTimeNow;
            DataContext.CustomerEmailHistory.Add(CustomerEmailHistoryDAO);
            await DataContext.SaveChangesAsync();

            CustomerEmailHistory.Id = CustomerEmailHistoryDAO.Id;
            await SaveReference(CustomerEmailHistory);

            return(true);
        }
Ejemplo n.º 10
0
        public async Task <CustomerEmailHistory> Delete(CustomerEmailHistory CustomerEmailHistory)
        {
            if (!await CustomerEmailHistoryValidator.Delete(CustomerEmailHistory))
            {
                return(CustomerEmailHistory);
            }

            try
            {
                await UOW.CustomerEmailHistoryRepository.Delete(CustomerEmailHistory);

                await Logging.CreateAuditLog(new { }, CustomerEmailHistory, nameof(CustomerEmailHistoryService));

                return(CustomerEmailHistory);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerEmailHistoryService));
            }
            return(null);
        }
Ejemplo n.º 11
0
        public async Task <bool> Update(CustomerEmailHistory CustomerEmailHistory)
        {
            CustomerEmailHistoryDAO CustomerEmailHistoryDAO = DataContext.CustomerEmailHistory.Where(x => x.Id == CustomerEmailHistory.Id).FirstOrDefault();

            if (CustomerEmailHistoryDAO == null)
            {
                return(false);
            }
            CustomerEmailHistoryDAO.Id            = CustomerEmailHistory.Id;
            CustomerEmailHistoryDAO.Title         = CustomerEmailHistory.Title;
            CustomerEmailHistoryDAO.Content       = CustomerEmailHistory.Content;
            CustomerEmailHistoryDAO.Reciepient    = CustomerEmailHistory.Reciepient;
            CustomerEmailHistoryDAO.CustomerId    = CustomerEmailHistory.CustomerId;
            CustomerEmailHistoryDAO.CreatorId     = CustomerEmailHistory.CreatorId;
            CustomerEmailHistoryDAO.EmailStatusId = CustomerEmailHistory.EmailStatusId;
            CustomerEmailHistoryDAO.UpdatedAt     = StaticParams.DateTimeNow;
            await DataContext.SaveChangesAsync();

            await SaveReference(CustomerEmailHistory);

            return(true);
        }
Ejemplo n.º 12
0
        public async Task <CustomerEmailHistory> Create(CustomerEmailHistory CustomerEmailHistory)
        {
            if (!await CustomerEmailHistoryValidator.Create(CustomerEmailHistory))
            {
                return(CustomerEmailHistory);
            }

            try
            {
                CustomerEmailHistory.CreatorId = CurrentContext.UserId;
                await UOW.CustomerEmailHistoryRepository.Create(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);
        }
Ejemplo n.º 13
0
        public async Task <CustomerEmailHistory> Update(CustomerEmailHistory CustomerEmailHistory)
        {
            if (!await CustomerEmailHistoryValidator.Update(CustomerEmailHistory))
            {
                return(CustomerEmailHistory);
            }
            try
            {
                var oldData = await UOW.CustomerEmailHistoryRepository.Get(CustomerEmailHistory.Id);

                await UOW.CustomerEmailHistoryRepository.Update(CustomerEmailHistory);

                CustomerEmailHistory = await UOW.CustomerEmailHistoryRepository.Get(CustomerEmailHistory.Id);

                await Logging.CreateAuditLog(CustomerEmailHistory, oldData, nameof(CustomerEmailHistoryService));

                return(CustomerEmailHistory);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerEmailHistoryService));
            }
            return(null);
        }
Ejemplo n.º 14
0
        public async Task <CustomerEmailHistory> Get(long Id)
        {
            CustomerEmailHistory CustomerEmailHistory = await DataContext.CustomerEmailHistory.AsNoTracking()
                                                        .Where(x => x.Id == Id)
                                                        .Where(x => x.DeletedAt == null)
                                                        .Select(x => new CustomerEmailHistory()
            {
                CreatedAt     = x.CreatedAt,
                UpdatedAt     = x.UpdatedAt,
                Id            = x.Id,
                Title         = x.Title,
                Content       = x.Content,
                Reciepient    = x.Reciepient,
                CustomerId    = x.CustomerId,
                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,
                },
                Customer = x.Customer == null ? null : new Customer
                {
                    Id                 = x.Customer.Id,
                    Code               = x.Customer.Code,
                    Name               = x.Customer.Name,
                    Phone              = x.Customer.Phone,
                    Address            = x.Customer.Address,
                    NationId           = x.Customer.NationId,
                    ProvinceId         = x.Customer.ProvinceId,
                    DistrictId         = x.Customer.DistrictId,
                    WardId             = x.Customer.WardId,
                    CustomerTypeId     = x.Customer.CustomerTypeId,
                    Birthday           = x.Customer.Birthday,
                    Email              = x.Customer.Email,
                    ProfessionId       = x.Customer.ProfessionId,
                    CustomerResourceId = x.Customer.CustomerResourceId,
                    SexId              = x.Customer.SexId,
                    StatusId           = x.Customer.StatusId,
                    CompanyId          = x.Customer.CompanyId,
                    ParentCompanyId    = x.Customer.ParentCompanyId,
                    TaxCode            = x.Customer.TaxCode,
                    Fax                = x.Customer.Fax,
                    Website            = x.Customer.Website,
                    NumberOfEmployee   = x.Customer.NumberOfEmployee,
                    BusinessTypeId     = x.Customer.BusinessTypeId,
                    Investment         = x.Customer.Investment,
                    RevenueAnnual      = x.Customer.RevenueAnnual,
                    IsSupplier         = x.Customer.IsSupplier,
                    Descreption        = x.Customer.Descreption,
                    Used               = x.Customer.Used,
                    RowId              = x.Customer.RowId,
                },
                EmailStatus = x.EmailStatus == null ? null : new EmailStatus
                {
                    Id   = x.EmailStatus.Id,
                    Code = x.EmailStatus.Code,
                    Name = x.EmailStatus.Name,
                },
            }).FirstOrDefaultAsync();

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

            CustomerEmailHistory.CustomerCCEmailHistories = await DataContext.CustomerCCEmailHistory
                                                            .Where(x => x.CustomerEmailHistoryId == CustomerEmailHistory.Id)
                                                            .Select(x => new CustomerCCEmailHistory
            {
                Id      = x.Id,
                CCEmail = x.CCEmail,
                CustomerEmailHistoryId = x.CustomerEmailHistoryId
            }).ToListAsync();

            return(CustomerEmailHistory);
        }
 public async Task <bool> Create(CustomerEmailHistory CustomerEmailHistory)
 {
     return(CustomerEmailHistory.IsValidated);
 }