public async Task <bool> Create(CustomerLead CustomerLead) { await ValidateName(CustomerLead); await ValidateFax(CustomerLead); return(CustomerLead.IsValidated); }
public async Task <bool> Delete(CustomerLead CustomerLead) { if (await ValidateId(CustomerLead)) { } return(CustomerLead.IsValidated); }
public async Task <bool> ValidatePhone(CustomerLead CustomerLead) { if (string.IsNullOrWhiteSpace(CustomerLead.Contact.Phone)) { CustomerLead.Contact.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Contact.Phone), ErrorCode.PhoneEmpty); } else if (CustomerLead.Contact.Phone.Length > 20) { CustomerLead.Contact.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Contact.Phone), ErrorCode.PhoneOverLength); } else { ContactFilter ContactFilter = new ContactFilter { Skip = 0, Take = 10, Id = new IdFilter { NotEqual = CustomerLead.Contact.Id }, Phone = new StringFilter { Equal = CustomerLead.Contact.Phone } }; int count = await UOW.ContactRepository.Count(ContactFilter); if (count != 0) { CustomerLead.Contact.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Contact.Phone), ErrorCode.PhoneExisted); } } return(CustomerLead.IsValidated); }
public async Task <bool> ValidateCompanyName(CustomerLead CustomerLead) { if (string.IsNullOrWhiteSpace(CustomerLead.Company.Name)) { CustomerLead.Company.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Company.Name), ErrorCode.CompanyNameEmpty); } return(CustomerLead.IsValidated); }
public virtual void InsertCustomerLead(CustomerLead customerLead) { if (customerLead == null) { throw new ArgumentNullException("customerLead"); } _customerLeadRepository.Insert(customerLead); }
public async Task <bool> Update(CustomerLead CustomerLead) { if (await ValidateId(CustomerLead)) { await ValidateName(CustomerLead); await ValidateFax(CustomerLead); } return(CustomerLead.IsValidated); }
public CustomerLead_CustomerLeadDTO(CustomerLead CustomerLead) { this.Id = CustomerLead.Id; this.CompanyName = CustomerLead.CompanyName; this.Name = CustomerLead.Name; this.TelePhone = CustomerLead.TelePhone; this.Phone = CustomerLead.Phone; this.Fax = CustomerLead.Fax; this.Email = CustomerLead.Email; this.SecondEmail = CustomerLead.SecondEmail; this.Website = CustomerLead.Website; this.CustomerLeadSourceId = CustomerLead.CustomerLeadSourceId; this.CustomerLeadLevelId = CustomerLead.CustomerLeadLevelId; this.CampaignId = CustomerLead.CampaignId; this.ProfessionId = CustomerLead.ProfessionId; this.Revenue = CustomerLead.Revenue; this.EmployeeQuantity = CustomerLead.EmployeeQuantity; this.Address = CustomerLead.Address; this.ProvinceId = CustomerLead.ProvinceId; this.DistrictId = CustomerLead.DistrictId; this.AppUserId = CustomerLead.AppUserId; this.CustomerLeadStatusId = CustomerLead.CustomerLeadStatusId; this.BusinessRegistrationCode = CustomerLead.BusinessRegistrationCode; this.SexId = CustomerLead.SexId; this.RefuseReciveSMS = CustomerLead.RefuseReciveSMS; this.NationId = CustomerLead.NationId; this.RefuseReciveEmail = CustomerLead.RefuseReciveEmail; this.Description = CustomerLead.Description; this.CurrencyId = CustomerLead.CurrencyId; this.CreatorId = CustomerLead.CreatorId; this.ZipCode = CustomerLead.ZipCode; this.CreatedAt = CustomerLead.CreatedAt; this.UpdatedAt = CustomerLead.UpdatedAt; this.IsCreateOpportunity = CustomerLead.IsCreateOpportunity; this.IsNewCompany = CustomerLead.IsNewCompany; this.IsNewContact = CustomerLead.IsNewContact; this.IsNewOpportunity = CustomerLead.IsNewOpportunity; this.CustomerLeadLevel = CustomerLead.CustomerLeadLevel == null ? null : new CustomerLead_CustomerLeadLevelDTO(CustomerLead.CustomerLeadLevel); this.CustomerLeadSource = CustomerLead.CustomerLeadSource == null ? null : new CustomerLead_CustomerLeadSourceDTO(CustomerLead.CustomerLeadSource); this.CustomerLeadStatus = CustomerLead.CustomerLeadStatus == null ? null : new CustomerLead_CustomerLeadStatusDTO(CustomerLead.CustomerLeadStatus); this.District = CustomerLead.District == null ? null : new CustomerLead_DistrictDTO(CustomerLead.District); this.Profession = CustomerLead.Profession == null ? null : new CustomerLead_ProfessionDTO(CustomerLead.Profession); this.Province = CustomerLead.Province == null ? null : new CustomerLead_ProvinceDTO(CustomerLead.Province); this.AppUser = CustomerLead.AppUser == null ? null : new CustomerLead_AppUserDTO(CustomerLead.AppUser); this.Nation = CustomerLead.Nation == null ? null : new CustomerLead_NationDTO(CustomerLead.Nation); this.Sex = CustomerLead.Sex == null ? null : new CustomerLead_SexDTO(CustomerLead.Sex); this.Currency = CustomerLead.Currency == null ? null : new CustomerLead_CurrencyDTO(CustomerLead.Currency); this.Creator = CustomerLead.Creator == null ? null : new CustomerLead_AppUserDTO(CustomerLead.Creator); this.Company = CustomerLead.Company == null ? null : new CustomerLead_CompanyDTO(CustomerLead.Company); this.Contact = CustomerLead.Contact == null ? null : new CustomerLead_ContactDTO(CustomerLead.Contact); this.Opportunity = CustomerLead.Opportunity == null ? null : new CustomerLead_OpportunityDTO(CustomerLead.Opportunity); this.CustomerLeadEmails = CustomerLead.CustomerLeadEmails?.Select(x => new CustomerLead_CustomerLeadEmailDTO(x)).ToList(); this.CustomerLeadItemMappings = CustomerLead.CustomerLeadItemMappings?.Select(x => new CustomerLead_CustomerLeadItemMappingDTO(x)).ToList(); this.CustomerLeadFileGroups = CustomerLead.CustomerLeadFileGroups?.Select(x => new CustomerLead_CustomerLeadFileGroupDTO(x)).ToList(); this.Errors = CustomerLead.Errors; }
public async Task <CustomerLead> Get(long Id) { CustomerLead CustomerLead = await UOW.CustomerLeadRepository.Get(Id); if (CustomerLead == null) { return(null); } return(CustomerLead); }
public async Task <bool> ValidateFax(CustomerLead CustomerLead) { if (!string.IsNullOrWhiteSpace(CustomerLead.Fax)) { if (CustomerLead.Fax.Length > 10) { CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Fax), ErrorCode.FaxOverLength); } } return(CustomerLead.IsValidated); }
public async Task <bool> ValidateName(CustomerLead CustomerLead) { if (string.IsNullOrWhiteSpace(CustomerLead.Name)) { CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Name), ErrorCode.NameEmpty); } else if (CustomerLead.Name.Length > 255) { CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Name), ErrorCode.NameOverLength); } return(CustomerLead.IsValidated); }
public void InsertCustomerLead(string source, string firstName, string lastName, string email, string ip) { var customerLead = new CustomerLead(); customerLead.DateReceived = DateTime.Now; customerLead.Email = email; customerLead.FirstName = firstName; customerLead.LastName = lastName; customerLead.Source = source; customerLead.IP = ip; _customerLeadService.InsertCustomerLead(customerLead); }
public async Task <bool> Convert(CustomerLead CustomerLead) { if (await ValidateId(CustomerLead)) { if (CustomerLead.Company == null) { CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Company), ErrorCode.CompanyIsNull); } else { if (CustomerLead.IsNewCompany) { await ValidateCompanyName(CustomerLead); } else { await ValidateCompany(CustomerLead); } } if (CustomerLead.Contact == null) { CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Contact), ErrorCode.ContactIsNull); } else { if (CustomerLead.IsNewContact) { await ValidateContactName(CustomerLead); await ValidatePhone(CustomerLead); } else { await ValidateContact(CustomerLead); } } if (CustomerLead.IsCreateOpportunity) { if (CustomerLead.IsNewOpportunity) { await ValidateOpportunityName(CustomerLead); } else { await ValidateOpportunity(CustomerLead); } } } return(CustomerLead.IsValidated); }
public async Task <CustomerLead> Update(CustomerLead CustomerLead) { if (!await CustomerLeadValidator.Update(CustomerLead)) { return(CustomerLead); } try { var oldData = await UOW.CustomerLeadRepository.Get(CustomerLead.Id); foreach (var CustomerLeadFileGroup in CustomerLead.CustomerLeadFileGroups) { if (CustomerLeadFileGroup.Id == 0) { CustomerLeadFileGroup.CreatorId = CurrentContext.UserId; } } await UOW.Begin(); await UOW.CustomerLeadRepository.Update(CustomerLead); await UOW.Commit(); CustomerLead = await UOW.CustomerLeadRepository.Get(CustomerLead.Id); await Logging.CreateAuditLog(CustomerLead, oldData, nameof(CustomerLeadService)); return(CustomerLead); } catch (Exception ex) { await UOW.Rollback(); if (ex.InnerException == null) { await Logging.CreateSystemLog(ex, nameof(CustomerLeadService)); throw new MessageException(ex); } else { await Logging.CreateSystemLog(ex.InnerException, nameof(CustomerLeadService)); throw new MessageException(ex.InnerException); } } }
public async Task <CustomerLead> Create(CustomerLead CustomerLead) { if (!await CustomerLeadValidator.Create(CustomerLead)) { return(CustomerLead); } try { await UOW.Begin(); var Creator = await UOW.AppUserRepository.Get(CurrentContext.UserId); CustomerLead.CreatorId = Creator.Id; CustomerLead.OrganizationId = Creator.OrganizationId; CustomerLead.CustomerLeadStatusId = CustomerLeadStatusEnum.NEW.Id; await UOW.CustomerLeadRepository.Create(CustomerLead); await UOW.CustomerLeadRepository.Update(CustomerLead); await UOW.Commit(); CustomerLead = await UOW.CustomerLeadRepository.Get(CustomerLead.Id); await Logging.CreateAuditLog(CustomerLead, new { }, nameof(CustomerLeadService)); return(CustomerLead); } catch (Exception ex) { if (ex.InnerException == null) { await Logging.CreateSystemLog(ex, nameof(CustomerLeadService)); throw new MessageException(ex); } else { await Logging.CreateSystemLog(ex.InnerException, nameof(CustomerLeadService)); throw new MessageException(ex.InnerException); } } }
public async Task <bool> ValidateId(CustomerLead CustomerLead) { CustomerLeadFilter CustomerLeadFilter = new CustomerLeadFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = CustomerLead.Id }, Selects = CustomerLeadSelect.Id }; int count = await UOW.CustomerLeadRepository.Count(CustomerLeadFilter); if (count == 0) { CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <CustomerLead> Delete(CustomerLead CustomerLead) { if (!await CustomerLeadValidator.Delete(CustomerLead)) { return(CustomerLead); } try { await UOW.Begin(); await UOW.CustomerLeadRepository.Delete(CustomerLead); await UOW.Commit(); await Logging.CreateAuditLog(new { }, CustomerLead, nameof(CustomerLeadService)); return(CustomerLead); } catch (Exception ex) { await UOW.Rollback(); if (ex.InnerException == null) { await Logging.CreateSystemLog(ex, nameof(CustomerLeadService)); throw new MessageException(ex); } else { await Logging.CreateSystemLog(ex.InnerException, nameof(CustomerLeadService)); throw new MessageException(ex.InnerException); } } }
public async Task <bool> ValidateCompany(CustomerLead CustomerLead) { if (CustomerLead.CompanyId.HasValue == false) { CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Company), ErrorCode.CompanyEmpty); } else { CompanyFilter CompanyFilter = new CompanyFilter { Id = new IdFilter { Equal = CustomerLead.CompanyId } }; var count = await UOW.CompanyRepository.Count(CompanyFilter); if (count == 0) { CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Company), ErrorCode.CompanyNotExisted); } } return(CustomerLead.IsValidated); }
public async Task <bool> ValidateOpportunity(CustomerLead CustomerLead) { if (CustomerLead.OpportunityId.HasValue == false) { CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Opportunity), ErrorCode.OpportunityEmpty); } else { OpportunityFilter OpportunityFilter = new OpportunityFilter { Id = new IdFilter { Equal = CustomerLead.OpportunityId } }; var count = await UOW.OpportunityRepository.Count(OpportunityFilter); if (count == 0) { CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Opportunity), ErrorCode.OpportunityNotExisted); } } return(CustomerLead.IsValidated); }
public Opportunity_CustomerLeadDTO(CustomerLead CustomerLead) { this.Id = CustomerLead.Id; this.Name = CustomerLead.Name; this.TelePhone = CustomerLead.TelePhone; this.Phone = CustomerLead.Phone; this.Fax = CustomerLead.Fax; this.Email = CustomerLead.Email; this.SecondEmail = CustomerLead.SecondEmail; this.CompanyId = CustomerLead.CompanyId; this.Website = CustomerLead.Website; this.CustomerLeadSourceId = CustomerLead.CustomerLeadSourceId; this.CustomerLeadLevelId = CustomerLead.CustomerLeadLevelId; this.CampaignId = CustomerLead.CampaignId; this.ProfessionId = CustomerLead.ProfessionId; this.Revenue = CustomerLead.Revenue; this.EmployeeQuantity = CustomerLead.EmployeeQuantity; this.Address = CustomerLead.Address; this.ProvinceId = CustomerLead.ProvinceId; this.DistrictId = CustomerLead.DistrictId; this.UserId = CustomerLead.AppUserId; this.CustomerLeadStatusId = CustomerLead.CustomerLeadStatusId; this.BusinessRegistrationCode = CustomerLead.BusinessRegistrationCode; this.SexId = CustomerLead.SexId; this.RefuseReciveSMS = CustomerLead.RefuseReciveSMS; this.NationId = CustomerLead.NationId; this.RefuseReciveEmail = CustomerLead.RefuseReciveEmail; this.Description = CustomerLead.Description; this.CreatorId = CustomerLead.CreatorId; this.ZipCode = CustomerLead.ZipCode; this.Errors = CustomerLead.Errors; }
public void AddToCustomerLeads(CustomerLead customerLead) { base.AddObject("CustomerLeads", customerLead); }
public async Task <CustomerLead> Convert(CustomerLead CustomerLead) { if (!await CustomerLeadValidator.Convert(CustomerLead)) { return(CustomerLead); } try { CustomerLead oldData = await UOW.CustomerLeadRepository.Get(CustomerLead.Id); await UOW.Begin(); var Creator = await UOW.AppUserRepository.Get(CurrentContext.UserId); if (CustomerLead.IsNewCompany) { Company Company = new Company { CustomerLeadId = CustomerLead.Id, Name = CustomerLead.Company?.Name, Phone = CustomerLead.Company?.Phone, FAX = CustomerLead.Fax, PhoneOther = CustomerLead.TelePhone, Email = CustomerLead.Email, EmailOther = CustomerLead.SecondEmail, ZIPCode = CustomerLead.ZipCode, Revenue = CustomerLead.Revenue, Website = CustomerLead.Website, NationId = CustomerLead.NationId, ProvinceId = CustomerLead.ProvinceId, DistrictId = CustomerLead.DistrictId, Address = CustomerLead.Address, NumberOfEmployee = CustomerLead.EmployeeQuantity, RefuseReciveEmail = CustomerLead.RefuseReciveEmail, RefuseReciveSMS = CustomerLead.RefuseReciveSMS, ProfessionId = CustomerLead.ProfessionId, Description = CustomerLead.Description, CompanyStatusId = CompanyStatusEnum.NEW.Id, AppUserId = CurrentContext.UserId, CreatorId = Creator.Id, OrganizationId = Creator.OrganizationId, }; await UOW.CompanyRepository.Create(Company); CustomerLead.CompanyId = Company.Id; } else { Company Company = await UOW.CompanyRepository.Get(CustomerLead.Company.Id); Company.CustomerLeadId = CustomerLead.Id; await UOW.CompanyRepository.Update(Company); CustomerLead.CompanyId = Company.Id; } if (CustomerLead.IsNewContact) { Contact Contact = new Contact { CustomerLeadId = CustomerLead.Id, CompanyId = CustomerLead.CompanyId, Name = CustomerLead.Contact?.Name, Phone = CustomerLead.Contact?.Phone, FAX = CustomerLead.Fax, Email = CustomerLead.Email, EmailOther = CustomerLead.SecondEmail, ZIPCode = CustomerLead.ZipCode, NationId = CustomerLead.NationId, ProvinceId = CustomerLead.ProvinceId, DistrictId = CustomerLead.DistrictId, Address = CustomerLead.Address, RefuseReciveEmail = CustomerLead.RefuseReciveEmail, RefuseReciveSMS = CustomerLead.RefuseReciveSMS, ProfessionId = CustomerLead.ProfessionId, Description = CustomerLead.Description, ContactStatusId = ContactStatusEnum.NEW.Id, AppUserId = CurrentContext.UserId, CreatorId = Creator.Id, OrganizationId = Creator.OrganizationId, }; await UOW.ContactRepository.Create(Contact); } else { Contact Contact = await UOW.ContactRepository.Get(CustomerLead.Contact.Id); Contact.CustomerLeadId = CustomerLead.Id; await UOW.ContactRepository.Update(Contact); } if (CustomerLead.IsCreateOpportunity) { if (CustomerLead.IsNewOpportunity) { var ClosingDate = new DateTime(StaticParams.DateTimeNow.Year, StaticParams.DateTimeNow.Month, 1); ClosingDate = ClosingDate.AddMonths(2).AddSeconds(-1); Opportunity Opportunity = new Opportunity { CustomerLeadId = CustomerLead.Id, CompanyId = CustomerLead.CompanyId, Name = CustomerLead.Opportunity?.Name, RefuseReciveEmail = CustomerLead.RefuseReciveEmail, RefuseReciveSMS = CustomerLead.RefuseReciveSMS, Description = CustomerLead.Description, ClosingDate = ClosingDate, ProbabilityId = ProbabilityEnum.TEN_PERCENT.Id, SaleStageId = SaleStageEnum.NEW.Id, AppUserId = CurrentContext.UserId, CreatorId = Creator.Id, OrganizationId = Creator.OrganizationId, }; await UOW.OpportunityRepository.Create(Opportunity); } else { Opportunity Opportunity = await UOW.OpportunityRepository.Get(CustomerLead.Opportunity.Id); Opportunity.CustomerLeadId = CustomerLead.Id; await UOW.OpportunityRepository.Update(Opportunity); } } await UOW.CustomerLeadRepository.UpdateState(CustomerLead); await UOW.Commit(); CustomerLead = await UOW.CustomerLeadRepository.Get(CustomerLead.Id); await Logging.CreateAuditLog(CustomerLead, oldData, nameof(CustomerLeadService)); return(CustomerLead); } catch (Exception ex) { if (ex.InnerException == null) { await Logging.CreateSystemLog(ex, nameof(CustomerLeadService)); throw new MessageException(ex); } else { await Logging.CreateSystemLog(ex.InnerException, nameof(CustomerLeadService)); throw new MessageException(ex.InnerException); } } }
public static CustomerLead CreateCustomerLead(int customerLeadID, int customerID, global::System.DateTime modifiedDate) { CustomerLead customerLead = new CustomerLead(); customerLead.CustomerLeadID = customerLeadID; customerLead.CustomerID = customerID; customerLead.ModifiedDate = modifiedDate; return customerLead; }
public CallLog_CustomerLeadDTO(CustomerLead CustomerLead) { this.Id = CustomerLead.Id; this.Name = CustomerLead.Name; this.UserId = CustomerLead.AppUserId; }