public async Task HookLead([FromBody] HookVM data) { // Gravity Forms separates form fields with "----------" by considering a section field that come right after a page break // So, we can separate lead details by using "--------------------------------" // try { var customer = this.CreateCustomerEntity(data); if (_cusRepo.IsCustomerExisted(data.EMail)) { customer = _cusRepo.GetByEmail(customer.EMail); } else { _cusRepo.Add(customer); } var lead = this.CreateLeadEntity(data, customer); _leadRepo.Add(lead, "WordPress"); if (_uow.Commit()) { //RedirectToAction(nameof(MessageController.SendCompanyLeadHooked), nameof(EnumController.Message), new { leadId = lead.Id }); await _messageController.SendCompanyLeadHooked(lead.Id, this.Url, this.Request); } else { } } catch (Exception e) { // logging here } }
private Lead CreateLeadEntity(HookVM data, Customer customer) { return(new Lead { CustomerId = customer.Id , LeadTypeId = data.LeadTypeId , Details = this.RipLeadDetails(data.Details) }); }
private Customer CreateCustomerEntity(HookVM data) { if (String.IsNullOrEmpty(data.ContactName.Trim())) { data.ContactName = "Unknown"; } if (String.IsNullOrEmpty(data.ContactNumber.Trim())) { data.ContactNumber = "0"; } return(new Customer { ContactName = data.ContactName , BusinessName = data.BusinessName , ContactNumber = data.ContactNumber , EMail = data.EMail }); }