예제 #1
0
        public async Task <int> AddLeadStatusAsync(LeadStatusHistory leadStatus)
        {
            using (var intuitContext = GetContext())
            {
                await intuitContext.LeadStatusHistory.AddAsync(leadStatus);

                return(await intuitContext.SaveChangesAsync());
            }
        }
예제 #2
0
        private bool BulkSave(MemoryStream stream, out int count, out int total)
        {
            count = 0;
            var leadSourcesDict = GetLeadSourceDict();
            var pincodeDict     = GetPincodeDict();
            var subDistDict     = GetSubDistDict();
            var localityDic     = GetLocalityDict();

            using (var reader = ExcelReaderFactory.CreateReader(stream))
            {
                total = reader.RowCount - 1;
                reader.Read();
                int index = 0;
                while (reader.Read())
                {
                    string businessName = reader.GetString(index++);

                    string proprietorName   = reader.GetString(index++);
                    string proprietorMobile = reader.GetDouble(index++).ToString();

                    string communicatorName   = reader.GetString(index++);
                    string communicatorMobile = reader.GetDouble(index++).ToString();

                    string address1   = reader.GetString(index++);
                    string address2   = reader.GetString(index++);
                    long   pinOrZip   = (long)reader.GetDouble(index++);
                    Guid?  pinOrZipId = pincodeDict.ContainsKey(pinOrZip) ? (Guid?)pincodeDict[pinOrZip].Id : null;

                    string village = reader.GetString(index++);

                    Guid?villageId = localityDic.ContainsKey(village) ? (Guid?)localityDic[village].Id : null;

                    string subDistrict   = reader.GetString(index++);
                    Guid?  subDistrictId = subDistDict.ContainsKey(subDistrict) ? (Guid?)subDistDict[subDistrict].Id : null;

                    string mobileNumber   = reader.GetDouble(index++).ToString();
                    string landLine       = reader.GetDouble(index++).ToString();
                    string leadSourceName = reader.GetString(index++);

                    /**
                     * Need to reset the column index to zero
                     */
                    index = 0;

                    LeadSource leadSource = null;
                    if (leadSourcesDict.ContainsKey(leadSourceName))
                    {
                        leadSource = leadSourcesDict[leadSourceName];
                    }

                    Lead foundLead = this.service
                                     .FindByMobile(mobileNumber, landLine);
                    if (foundLead != null)
                    {
                        continue;
                    }

                    var leadOpenStatus = leadStatusService.FindByName("Open");

                    Contact proprietorcontact = null;
                    if (proprietorName != null && proprietorMobile != null &&
                        proprietorMobile.Length >= 10)
                    {
                        proprietorcontact = new Contact
                        {
                            Id           = Guid.NewGuid(),
                            FirstName    = proprietorName,
                            MobileNumber = proprietorMobile
                        };
                    }
                    Contact communicatorContact = null;
                    if (communicatorName != null && communicatorMobile != null &&
                        communicatorMobile.Length >= 10)
                    {
                        communicatorContact = new Contact
                        {
                            Id           = Guid.NewGuid(),
                            FirstName    = communicatorName,
                            MobileNumber = communicatorMobile
                        };
                    }
                    var history = new LeadStatusHistory
                    {
                        StatusDate = DateTime.Now,
                        Status     = null,
                        StatusId   = leadOpenStatus.Id,
                        Created    = DateTime.Now,
                        Order      = 0,
                    };
                    Lead lead = new Lead
                    {
                        SourceId = leadSource.Id,
                        Source   = null,
                        History  = new List <LeadStatusHistory>()
                        {
                            history
                        },
                        CurrentLeadStatusId = history.Id
                    };

                    lead.Contact = new BusinessContact
                    {
                        BusinessName   = businessName,
                        ContactAddress = new Database.Entity.Crm.Address.Master
                        {
                            AddressLine1        = address1,
                            AddressLine2        = address2,
                            LocalityOrVillage   = village,
                            LocalityOrVillageId = villageId,
                            PinOrZip            = pinOrZip,

                            SubDistrict   = subDistrict,
                            SubDistrictId = subDistrictId
                        },
                        Proprietor    = proprietorcontact,
                        ContactPerson = communicatorContact,
                        MobileNumber  = mobileNumber,
                        Landline      = landLine,
                    };
                    lead = baseService.Save(lead);
                    if (lead == null)
                    {
                        continue;
                    }

                    count++;
                }
            }
            return(true);
        }