Esempio n. 1
0
        public IActionResult Details(string mobileNo)
        {
            var maybeLead = _leadRepo.FindOpenLeadByMobileNo(PhoneNoModule.NormalizePhoneNoFormat(mobileNo));

            if (maybeLead.IsSome)
            {
                return(Ok(LeadDebugModule.ToDebug(maybeLead.Val)));
            }

            return(Ok("{}"));
        }
Esempio n. 2
0
        public List <Lead> FindLeadsByMobileNo(string mobileNo)
        {
            var mobileNo_ = PhoneNoModule.NormalizePhoneNoFormat(mobileNo);

            var rows = _store.QueryAsync <Lead>(new Query("leads", "mobileNo")
            {
                Key = mobileNo_
            }).Result;
            var leads = rows.Select(r => r.Value).OrderByDescending(l => l.CreatedOn).ToList();

            return(leads);
        }
Esempio n. 3
0
        public List <string> FindHeaderByMobileNo(string mobileNo)
        {
            var mobileNo_ = PhoneNoModule.NormalizePhoneNoFormat(mobileNo);

            var rows = _store.QueryAsync <string>(new Query("leads", "mobileNo")
            {
                Key = mobileNo_
            }).Result;
            var leadDocIds = rows.Select(r => r.Id).ToList();

            return(leadDocIds);
        }
Esempio n. 4
0
        public IActionResult Add([FromBody] LeadDto dto)
        {
            //check number
            dto.MobileNo = PhoneNoModule.NormalizePhoneNoFormat(dto.MobileNo);
            if (!PhoneNoModule.isPhoneNumberValid(dto.MobileNo))
            {
                return(BadRequest("Mobile number not valid. Needs to 12 Characters"));
            }

            if (!_leadTypeRepository.All.Any(s => s.Id == dto.LeadTypeId))
            {
                return(BadRequest($"Lead type {dto.LeadTypeId} not valid"));
            }

            if (!string.IsNullOrWhiteSpace(dto.ProductBracket) && !_mobileProductRepository.GetProductsByBracket(dto.ProductBracket).Any())
            {
                return(BadRequest($"No product found for {dto.ProductBracket}"));
            }

            //check if lead is active
            var currentlead = _leadRepo.FindOpenLeadByMobileNo(dto.MobileNo);

            if (currentlead.IsSome)
            {
                if (currentlead.Val.IsClosed == false)
                {
                    currentlead.Val.Close();
                    _leadRepo.Update(currentlead.Val);
                }
            }
            //LeadTypeModule
            var leadType = new LeadType(dto.LeadTypeId);
            var lead     = new Lead(leadType, dto.MobileNo, dto.FirstName.StrToOpt())
            {
                ProductBracket  = dto.ProductBracket.StrToOpt(),
                IdNumber        = dto.IdNumber.StrToOpt(),
                Surname         = dto.Surname.StrToOpt(),
                ExternalRefNo   = dto.ExternalRefNo.StrToOpt(),
                BankName        = dto.BankName.StrToOpt(),
                BankAccountType = dto.BankAccountType.StrToOpt(),
                BankAccountNo   = dto.BankAccountNo.StrToOpt(),
                EmployerName    = dto.EmployerName.StrToOpt(),
                EmployerNumber  = dto.EmployerNumber.StrToOpt(),
                EmployerAddress = string.IsNullOrEmpty(dto.EmployerAddressStreet) ? None <Address>() :  Some(new Address(dto.EmployerAddressStreet, dto.EmployerAddressSuburb, dto.EmployerAddressCity, dto.EmployerAddressPostalCode)),
                HomeAddress     = string.IsNullOrEmpty(dto.HomeAddressStreet) ? None <Address>() : Some(new Address(dto.HomeAddressStreet, dto.HomeAddressSuburb, dto.HomeAddressCity, dto.HomeAddressPostalCode))
            };

            _leadRepo.Add(lead);

            return(Ok("Lead Created"));
        }
        public Result <List <ReceiveMessageResponseDetailed> > ReceiveMessage(JObject json)
        {
            // ["{\"integrationName\":\"My first test Integration\",\"replyMessageId\":\"621540c8a226491d80e65f664de917ca\",\"messageId\":\"ef48574bcab34f19923e04283c350972\",\"fromNumber\":\"27824125236\",\"toNumber\":\"39360\",\"timestamp\":1561050996606,\"text\":\"booya\",\"charset\":\"ISO-8859-1\",\"udh\":\"\",\"network\":null,\"keyword\":null}"]
            try {
                var result = new ReceiveMessageResponseDetailed {
                    IntegrationName = json["integrationName"].ToObject <string>(),
                    ReplyMessageId  = json["replyMessageId"].ToObject <string>(),
                    MessageId       = json["messageId"].ToObject <string>(),
                    FromNumber      = PhoneNoModule.NormalizePhoneNoFormat(json["fromNumber"].ToObject <string>()),
                    ToNumber        = json["toNumber"].ToObject <string>(),
                    Timestamp       = json["timestamp"].ToObject <string>(),
                    Text            = RemoveUnwantedChars(json["text"].ToObject <string>()),
                    CharSet         = json["charset"].ToObject <string>()
                };

                return(Ok(new List <ReceiveMessageResponseDetailed> {
                    result
                }));
            }
            catch (Exception ex) {
                return(Err <List <ReceiveMessageResponseDetailed> >(ex));
            }
        }