public ActionResult Create(LeadViewModel leadViewModel) { var lead = new Lead(); lead.Company = leadViewModel.Company; lead.ExpectedValue = leadViewModel.ExpectedValue; lead.ProbabilityOfSale = leadViewModel.ProbabilityOfSale; lead.Status = new Tuple<int, string>(leadViewModel.Status, ""); lead.NextFollowUp = leadViewModel.NextFollowUp; lead.StreetAddress = leadViewModel.StreetAddress; lead.City = leadViewModel.City; lead.State = leadViewModel.State; lead.Zip = leadViewModel.Zip; lead.Country = leadViewModel.Country; if (leadViewModel.LeadContacts != null && leadViewModel.LeadContacts.Any()) lead.Contacts = leadViewModel.LeadContacts.ToDictionary(k => k.Value, v => v.Value.ToString()); if (leadViewModel.LeadOwners != null && leadViewModel.LeadOwners.Any()) lead.LeadOwners = leadViewModel.LeadOwners.ToDictionary(k => k.Value, v => v.Value.ToString()); int itemId = lead.CreateLead(lead); return RedirectToAction("Index"); }
public ActionResult Delete(int id) { var lead = new Lead(); try { lead.DeleteLead(id); TempData["message"] = "Lead deleted successfully"; } catch (PodioException ex) { TempData["error"] = ex.Error.ErrorDescription; } return RedirectToAction("Index"); }
public ActionResult Create() { var lead = new Lead(); var spaceContacts = lead.GetSpaceContacts(); var spaceUsers = lead.GetUsers(); var statuses = lead.GetAllStatuses(); var leadContactsItems = spaceContacts.Select(x => new SelectListItem { Text = x.Name, Value = x.ProfileId.ToString() }); var leadOwnerItems = spaceUsers.Select(x => new SelectListItem { Text = x.Name, Value = x.ProfileId.ToString() }); var statusOptions = statuses.Select(x => new SelectListItem { Text = x.Value.ToString(), Value = x.Key.ToString() }); var model = new LeadViewModel(); model.LeadContactsOptions = leadContactsItems; model.LeadOwnersOptions = leadOwnerItems; model.StatusOptions = statusOptions; return View(model); }
public async Task<ActionResult> Filter(LeadListingViewModel leadListingModel) { var lead = new Lead(); var model = new LeadListingViewModel(); try { DateTime? nextFollowUpFromDate = leadListingModel.NextFollowUpFrom; DateTime? nextFollowUpToDate = leadListingModel.NextFollowUpTo; decimal? expectedValueFrom = leadListingModel.ExpectedValueFrom; decimal? expectedValueTo = leadListingModel.ExpectedValueTo; int? status = leadListingModel.Status; int? leadOwner = leadListingModel.LeadOwner; IEnumerable<Contact> spaceUsers = await lead.GetUsers(); Dictionary<int, string> statuses = await lead.GetAllStatuses(); IEnumerable<Lead> leads = await lead.GetAllLeads(nextFollowUpFromDate, nextFollowUpToDate, expectedValueFrom, expectedValueTo, status, leadOwner); model.LeadOwnersOptions = new SelectList(spaceUsers, "ProfileId", "Name", leadOwner); model.StatusOptions = new SelectList(statuses, "Key", "Value", status); if (leads.Any()) { model.Leads = leads.Select(x => new LeadView { Company = x.Company, LeadOwners = x.LeadOwners, ExpectedValue = x.ExpectedValue, Status = x.Status, NextFollowUp = x.NextFollowUp, PodioItemID = x.PodioItemID }); } } catch (PodioException ex) { ViewBag.error = ex.Error.ErrorDescription; } return View("Index", model); }
public async Task<ActionResult> Index() { ViewBag.message = TempData["message"]; ViewBag.error = TempData["error"]; var model = new LeadListingViewModel(); var lead = new Lead(); try { var getSpaceUsersTask = lead.GetUsers(); var getStatusesTask = lead.GetAllStatuses(); var getLeadsTask = lead.GetAllLeads(); await System.Threading.Tasks.Task.WhenAll(getSpaceUsersTask, getStatusesTask, getLeadsTask); model.LeadOwnersOptions = new SelectList(getSpaceUsersTask.Result, "ProfileId", "Name"); model.StatusOptions = new SelectList(getStatusesTask.Result, "Key", "Value"); var leads = getLeadsTask.Result; if (leads.Any()) { model.Leads = leads.Select(x => new LeadView { Company = x.Company, LeadOwners = x.LeadOwners, ExpectedValue = x.ExpectedValue, Status = x.Status, NextFollowUp = x.NextFollowUp, PodioItemID = x.PodioItemID }).ToList(); } } catch (PodioException ex) { ViewBag.error = ex.Error.ErrorDescription; } return View(model); }
public ActionResult Create() { var lead = new Lead(); var model = new LeadViewModel(); try { List<Contact> spaceContacts = lead.GetSpaceContacts(); List<Contact> spaceUsers = lead.GetUsers(); Dictionary<int, string> statuses = lead.GetAllStatuses(); model.LeadContactsOptions = new SelectList(spaceContacts, "ProfileId", "Name"); model.LeadOwnersOptions = new SelectList(spaceUsers, "ProfileId", "Name"); model.StatusOptions = new SelectList(statuses, "Key", "Value"); } catch (PodioException ex) { ViewBag.error = ex.Error.ErrorDescription; } return View(model); }
public ActionResult Filter(FormCollection formCollection) { var nextFollowUpFromDate = !string.IsNullOrEmpty(formCollection["inputFromDate"]) ? DateTime.Parse(formCollection["inputFromDate"]) : (DateTime?)null; var nextFollowUpToDate = !string.IsNullOrEmpty(formCollection["inputToDate"]) ? DateTime.Parse(formCollection["inputToDate"]) : (DateTime?)null; var expectedValueFrom = !string.IsNullOrEmpty(formCollection["inputExpectedValueFrom"]) ? int.Parse(formCollection["inputExpectedValueFrom"]) : (int?)null; var expectedValueTo = !string.IsNullOrEmpty(formCollection["inputExpectedValueTo"]) ? int.Parse(formCollection["inputExpectedValueTo"]) : (int?)null; var status = !string.IsNullOrEmpty(formCollection["ddlStatus"]) && formCollection["ddlStatus"] != "-1" ? int.Parse(formCollection["ddlStatus"]) : (int?)null; var leadOwner = !string.IsNullOrEmpty(formCollection["ddlLeadOwner"]) && formCollection["ddlLeadOwner"] != "-1" ? int.Parse(formCollection["ddlLeadOwner"]) : (int?)null; var lead = new Lead(); var spaceUsers = lead.GetUsers(); var statuses = lead.GetAllStatuses(); var leads = lead.GetAllLeads(nextFollowUpFromDate, nextFollowUpToDate, expectedValueFrom, expectedValueTo, status, leadOwner); var model = new LeadListingViewModel(); LeadViewModelOptions leadModelOption = new LeadViewModelOptions(); if (spaceUsers.Any()) leadModelOption.LeadOwnersOptions = spaceUsers.Select(x => new SelectListItem { Text = x.Name, Value = x.ProfileId.ToString() }); if (statuses.Any()) leadModelOption.StatusOptions = statuses.Select(x => new SelectListItem { Text = x.Value.ToString(), Value = x.Key.ToString() }); if (leads.Any()) model.Leads = leads.Select(x => new LeadView { Company = x.Company, LeadOwners = x.LeadOwners, ExpectedValue = x.ExpectedValue, Status = x.Status, NextFollowUp = x.NextFollowUp}) .ToList(); model.LeadViewModelOptions = leadModelOption; return View("Index", model); }
public async Task<int> CreateLead(Lead lead) { int appId = AppId; Item item = LeadToPodioItem(lead); int itemId = await _Podio.ItemService.AddNewItem(appId, item); return itemId; }
/// <summary> /// Convert Lead object to PodioAPI.Item object /// </summary> /// <param name="lead"></param> /// <returns></returns> private Item LeadToPodioItem(Lead lead) { var item = new Item(); var companyField = item.Field <TextItemField>("company-or-organisation"); if (!string.IsNullOrEmpty(lead.Company)) { companyField.Value = lead.Company; } var leadContactsField = item.Field <ContactItemField>("contacts"); if (lead.Contacts != null) { leadContactsField.ContactIds = lead.Contacts.Select(x => x.Key); } var leadOwnerField = item.Field <ContactItemField>("sales-contact"); if (lead.LeadOwners != null) { leadOwnerField.ContactIds = lead.LeadOwners.Select(x => x.Key); } var statusField = item.Field <CategoryItemField>("status2"); if (lead.Status.Item1 != default(int)) { statusField.OptionIds = new List <int> { lead.Status.Item1 } } ; var expectedValueField = item.Field <MoneyItemField>("potential-revenue"); if (lead.ExpectedValue.HasValue) { expectedValueField.Currency = "USD"; expectedValueField.Value = lead.ExpectedValue; } var probabilityOfSaleField = item.Field <ProgressItemField>("probability-of-sale"); if (lead.ProbabilityOfSale.HasValue) { probabilityOfSaleField.Value = lead.ProbabilityOfSale; } var nextFollowUpField = item.Field <DateItemField>("next-follow-up"); if (lead.NextFollowUp.HasValue) { nextFollowUpField.Start = lead.NextFollowUp; } var streetAddressField = item.Field <TextItemField>("street-address"); if (!string.IsNullOrEmpty(lead.StreetAddress)) { streetAddressField.Value = lead.StreetAddress; } var cityField = item.Field <TextItemField>("city"); if (!string.IsNullOrEmpty(lead.City)) { cityField.Value = lead.City; } var stateField = item.Field <TextItemField>("state-provins-or-territory"); if (!string.IsNullOrEmpty(lead.State)) { stateField.Value = lead.State; } var zipField = item.Field <TextItemField>("zip-codepost-code"); if (!string.IsNullOrEmpty(lead.Zip)) { zipField.Value = lead.Zip; } var countryField = item.Field <TextItemField>("country"); if (!string.IsNullOrEmpty(lead.Country)) { countryField.Value = lead.Country; } return(item); }
/// <summary> /// Get specified item from podio and convert to Lead object. /// </summary> /// <param name="itemId"></param> /// <returns></returns> public async Task<Lead> GetLead(int itemId) { int appId = AppId; var item = await _Podio.ItemService.GetItemBasic(itemId); var lead = new Lead(); lead.PodioItemID = item.ItemId; var companyField = item.Field<TextItemField>("company-or-organisation"); lead.Company = companyField.Value; var leadContactsField = item.Field<ContactItemField>("contacts"); lead.Contacts = leadContactsField.Contacts != null ? leadContactsField.Contacts.ToDictionary(k => k.ProfileId, v => v.Name) : null; var leadOwnerField = item.Field<ContactItemField>("sales-contact"); lead.LeadOwners = leadOwnerField.Contacts != null ? leadOwnerField.Contacts.ToDictionary(k => k.ProfileId, v => v.Name) : null; var statusField = item.Field<CategoryItemField>("status2"); if (statusField.Options != null && statusField.Options.Any()) lead.Status = new Tuple<int, string>(statusField.Options.First().Id.Value, statusField.Options.First().Text); var expectedValueField = item.Field<MoneyItemField>("potential-revenue"); lead.ExpectedValue = expectedValueField.Value; var probabilityOfSaleField = item.Field<ProgressItemField>("probability-of-sale"); lead.ProbabilityOfSale = probabilityOfSaleField.Value; var nextFollowUpField = item.Field<DateItemField>("next-follow-up"); lead.NextFollowUp = nextFollowUpField.StartDate; var streetAddressField = item.Field<TextItemField>("street-address"); lead.StreetAddress = streetAddressField.Value; var cityField = item.Field<TextItemField>("city"); lead.City = cityField.Value; var stateField = item.Field<TextItemField>("state-provins-or-territory"); lead.State = stateField.Value; var zipField = item.Field<TextItemField>("zip-codepost-code"); lead.Zip = zipField.Value; var countryField = item.Field<TextItemField>("country"); lead.Country = countryField.Value; return lead; }
public async Task<ActionResult> Edit(int id) { ViewBag.message = TempData["message"]; ViewBag.error = TempData["error"]; var lead = new Lead(); var model = new LeadViewModel(); try { var getLeadToEditTask = lead.GetLead(id); var getSpaceContactsTask = lead.GetSpaceContacts(); var getSpaceUsersTask = lead.GetUsers(); var getStatusesTask = lead.GetAllStatuses(); await System.Threading.Tasks.Task.WhenAll(getSpaceContactsTask, getSpaceUsersTask, getStatusesTask, getLeadToEditTask); var leadToEdit = getLeadToEditTask.Result; IEnumerable<int> selectedLeadContacts = leadToEdit.Contacts != null ? leadToEdit.Contacts.Select(x => x.Key) : null; IEnumerable<int> selectedLeadOwners = leadToEdit.LeadOwners != null ? leadToEdit.LeadOwners.Select(x => x.Key) : null; int selectedStatus = leadToEdit.Status.Item1; model.PodioItemID = leadToEdit.PodioItemID; model.Company = leadToEdit.Company; model.ExpectedValue = leadToEdit.ExpectedValue; model.ProbabilityOfSale = leadToEdit.ProbabilityOfSale; model.NextFollowUp = leadToEdit.NextFollowUp; model.StreetAddress = leadToEdit.StreetAddress; model.City = leadToEdit.City; model.Zip = leadToEdit.Zip; model.State = leadToEdit.State; model.Country = leadToEdit.Country; model.LeadContactsOptions = new SelectList(getSpaceContactsTask.Result, "ProfileId", "Name"); model.LeadOwnersOptions = new SelectList(getSpaceUsersTask.Result, "ProfileId", "Name"); model.StatusOptions = new SelectList(getStatusesTask.Result, "Key", "Value"); } catch (PodioException ex) { ViewBag.error = ex.Error.ErrorDescription; } return View(model); }
public ActionResult Index() { ViewBag.message = TempData["message"]; ViewBag.error = TempData["error"]; var model = new LeadListingViewModel(); var lead = new Lead(); try { List<Contact> spaceUsers = lead.GetUsers(); Dictionary<int,string> statuses = lead.GetAllStatuses(); IEnumerable<Lead> leads = lead.GetAllLeads(); model.LeadOwnersOptions = new SelectList(spaceUsers, "ProfileId", "Name"); model.StatusOptions = new SelectList(statuses, "Key", "Value"); if (leads.Any()) { model.Leads = leads.Select(x => new LeadView { Company = x.Company, LeadOwners = x.LeadOwners, ExpectedValue = x.ExpectedValue, Status = x.Status, NextFollowUp = x.NextFollowUp, PodioItemID = x.PodioItemID }).ToList(); } } catch (PodioException ex) { ViewBag.error = ex.Error.ErrorDescription; } return View(model); }
public void UpdateLead(Lead lead) { Item item = LeadToPodioItem(lead); item.ItemId = lead.PodioItemID; _Podio.ItemService.UpdateItem(item); }
public async Task<ActionResult> Create() { var lead = new Lead(); var model = new LeadViewModel(); try { var getSpaceContactsTask = lead.GetSpaceContacts(); var getSpaceUsersTask = lead.GetUsers(); var getStatusesTask = lead.GetAllStatuses(); await System.Threading.Tasks.Task.WhenAll(getSpaceContactsTask, getSpaceUsersTask, getStatusesTask); model.LeadContactsOptions = new SelectList(getSpaceContactsTask.Result, "ProfileId", "Name"); model.LeadOwnersOptions = new SelectList(getSpaceUsersTask.Result, "ProfileId", "Name"); model.StatusOptions = new SelectList(getStatusesTask.Result, "Key", "Value"); } catch (PodioException ex) { ViewBag.error = ex.Error.ErrorDescription; } return View(model); }
/// <summary> /// Get specified item from podio and convert to Lead object. /// </summary> /// <param name="itemId"></param> /// <returns></returns> public async Task <Lead> GetLead(int itemId) { int appId = AppId; var item = await _Podio.ItemService.GetItemBasic(itemId); var lead = new Lead(); lead.PodioItemID = item.ItemId; var companyField = item.Field <TextItemField>("company-or-organisation"); lead.Company = companyField.Value; var leadContactsField = item.Field <ContactItemField>("contacts"); lead.Contacts = leadContactsField.Contacts != null?leadContactsField.Contacts.ToDictionary(k => k.ProfileId, v => v.Name) : null; var leadOwnerField = item.Field <ContactItemField>("sales-contact"); lead.LeadOwners = leadOwnerField.Contacts != null?leadOwnerField.Contacts.ToDictionary(k => k.ProfileId, v => v.Name) : null; var statusField = item.Field <CategoryItemField>("status2"); if (statusField.Options != null && statusField.Options.Any()) { lead.Status = new Tuple <int, string>(statusField.Options.First().Id.Value, statusField.Options.First().Text); } var expectedValueField = item.Field <MoneyItemField>("potential-revenue"); lead.ExpectedValue = expectedValueField.Value; var probabilityOfSaleField = item.Field <ProgressItemField>("probability-of-sale"); lead.ProbabilityOfSale = probabilityOfSaleField.Value; var nextFollowUpField = item.Field <DateItemField>("next-follow-up"); lead.NextFollowUp = nextFollowUpField.StartDate; var streetAddressField = item.Field <TextItemField>("street-address"); lead.StreetAddress = streetAddressField.Value; var cityField = item.Field <TextItemField>("city"); lead.City = cityField.Value; var stateField = item.Field <TextItemField>("state-provins-or-territory"); lead.State = stateField.Value; var zipField = item.Field <TextItemField>("zip-codepost-code"); lead.Zip = zipField.Value; var countryField = item.Field <TextItemField>("country"); lead.Country = countryField.Value; return(lead); }
/// <summary> /// Convert LeadViewModel to Lead object /// </summary> /// <param name="leadViewModel"></param> /// <returns></returns> public static Lead LeadViewModelToLead(LeadViewModel leadViewModel) { var lead = new Lead(); lead.PodioItemID = leadViewModel.PodioItemID; lead.Company = leadViewModel.Company; lead.ExpectedValue = leadViewModel.ExpectedValue; lead.ProbabilityOfSale = leadViewModel.ProbabilityOfSale; lead.Status = new Tuple<int, string>(leadViewModel.Status, ""); lead.NextFollowUp = leadViewModel.NextFollowUp; lead.StreetAddress = leadViewModel.StreetAddress; lead.City = leadViewModel.City; lead.State = leadViewModel.State; lead.Zip = leadViewModel.Zip; lead.Country = leadViewModel.Country; if (leadViewModel.LeadContacts != null && leadViewModel.LeadContacts.Any()) lead.Contacts = leadViewModel.LeadContacts.ToDictionary(k => k.Value, v => v.Value.ToString()); if (leadViewModel.LeadOwners != null && leadViewModel.LeadOwners.Any()) lead.LeadOwners = leadViewModel.LeadOwners.ToDictionary(k => k.Value, v => v.Value.ToString()); return lead; }
public async Task<bool> UpdateLead(Lead lead) { Item item = LeadToPodioItem(lead); item.ItemId = lead.PodioItemID; var revisionId = await _Podio.ItemService.UpdateItem(item); return revisionId.HasValue; }
public ActionResult Edit(int id) { ViewBag.message = TempData["message"]; ViewBag.error = TempData["error"]; var lead = new Lead(); var model = new LeadViewModel(); try { Lead leadToEdit = lead.GetLead(id); List<Contact> spaceContacts = lead.GetSpaceContacts(); List<Contact> spaceUsers = lead.GetUsers(); Dictionary<int,string> statuses = lead.GetAllStatuses(); IEnumerable<int> selectedLeadContacts = leadToEdit.Contacts != null ? leadToEdit.Contacts.Select(x => x.Key) : null; IEnumerable<int> selectedLeadOwners = leadToEdit.LeadOwners != null ? leadToEdit.LeadOwners.Select(x => x.Key) : null; int selectedStatus = leadToEdit.Status.Item1; model.PodioItemID = leadToEdit.PodioItemID; model.Company = leadToEdit.Company; model.ExpectedValue = leadToEdit.ExpectedValue; model.ProbabilityOfSale = leadToEdit.ProbabilityOfSale; model.NextFollowUp = leadToEdit.NextFollowUp; model.StreetAddress = leadToEdit.StreetAddress; model.City = leadToEdit.City; model.Zip = leadToEdit.Zip; model.State = leadToEdit.State; model.Country = leadToEdit.Country; model.LeadContactsOptions = new MultiSelectList(spaceContacts, "ProfileId", "Name", selectedLeadContacts); model.LeadOwnersOptions = new MultiSelectList(spaceUsers, "ProfileId", "Name", selectedLeadOwners); model.StatusOptions = new SelectList(statuses, "Key", "Value", selectedStatus); } catch (PodioException ex) { ViewBag.error = ex.Error.ErrorDescription; } return View(model); }
public ActionResult Index() { var lead = new Lead(); var spaceUsers = lead.GetUsers(); var statuses = lead.GetAllStatuses(); var leads = lead.GetAllLeads(); var model = new LeadListingViewModel(); LeadViewModelOptions leadModelOption = new LeadViewModelOptions(); if (spaceUsers.Any()) leadModelOption.LeadOwnersOptions = spaceUsers.Select(x => new SelectListItem { Text = x.Name, Value = x.ProfileId.ToString() }); if (statuses.Any()) leadModelOption.StatusOptions = statuses.Select(x => new SelectListItem { Text = x.Value.ToString(), Value = x.Key.ToString() }); if (leads.Any()) model.Leads = leads.Select(x => new LeadView { Company = x.Company, LeadOwners = x.LeadOwners, ExpectedValue = x.ExpectedValue, Status = x.Status, NextFollowUp = x.NextFollowUp }) .ToList(); model.LeadViewModelOptions = leadModelOption; return View(model); }
/// <summary> /// Convert Lead object to PodioAPI.Item object /// </summary> /// <param name="lead"></param> /// <returns></returns> private Item LeadToPodioItem(Lead lead) { var item = new Item(); var companyField = item.Field<TextItemField>("company-or-organisation"); if (!string.IsNullOrEmpty(lead.Company)) companyField.Value = lead.Company; var leadContactsField = item.Field<ContactItemField>("contacts"); if (lead.Contacts != null) leadContactsField.ContactIds = lead.Contacts.Select(x => x.Key); var leadOwnerField = item.Field<ContactItemField>("sales-contact"); if (lead.LeadOwners != null) leadOwnerField.ContactIds = lead.LeadOwners.Select(x => x.Key); var statusField = item.Field<CategoryItemField>("status2"); if (lead.Status.Item1 != default(int)) statusField.OptionIds = new List<int> { lead.Status.Item1 }; var expectedValueField = item.Field<MoneyItemField>("potential-revenue"); if (lead.ExpectedValue.HasValue) { expectedValueField.Currency = "USD"; expectedValueField.Value = lead.ExpectedValue; } var probabilityOfSaleField = item.Field<ProgressItemField>("probability-of-sale"); if (lead.ProbabilityOfSale.HasValue) probabilityOfSaleField.Value = lead.ProbabilityOfSale; var nextFollowUpField = item.Field<DateItemField>("next-follow-up"); if(lead.NextFollowUp.HasValue) nextFollowUpField.Start = lead.NextFollowUp; var streetAddressField = item.Field<TextItemField>("street-address"); if (!string.IsNullOrEmpty(lead.StreetAddress)) streetAddressField.Value = lead.StreetAddress; var cityField = item.Field<TextItemField>("city"); if (!string.IsNullOrEmpty(lead.City)) cityField.Value = lead.City; var stateField = item.Field<TextItemField>("state-provins-or-territory"); if (!string.IsNullOrEmpty(lead.State)) stateField.Value = lead.State; var zipField = item.Field<TextItemField>("zip-codepost-code"); if (!string.IsNullOrEmpty(lead.Zip)) zipField.Value = lead.Zip; var countryField = item.Field<TextItemField>("country"); if(!string.IsNullOrEmpty(lead.Country)) countryField.Value = lead.Country; return item; }
public int CreateLead(Lead lead) { int appId = AppId; Item item = LeadToPodioItem(lead); int itemId = _Podio.ItemService.AddNewItem(appId, item); return itemId; }
public async Task<IEnumerable<Lead>> GetAllLeads(DateTime? nextFollowUpFrom = null, DateTime? nextFollowUpTo = null, decimal? potentialRevenueFrom = null, decimal? potentialRevenueTo = null, int? status = null, int? leadOwner = null) { List<Lead> leads = new List<Lead>(); int appId = AppId; var filterOption = new FilterOptions(); Dictionary<string, object> filters = new Dictionary<string, object>(); // Filter leads based on incomig parameters if (status != null) filters.Add("status2", status); if (leadOwner != null) filters.Add("sales-contact", new int[]{leadOwner.Value}); if (potentialRevenueFrom != null || potentialRevenueTo != null) filters.Add("potential-revenue", new { from = potentialRevenueFrom, to = potentialRevenueTo }); if (nextFollowUpFrom != null || nextFollowUpTo != null) filters.Add("next-follow-up", new { from = nextFollowUpFrom, to = nextFollowUpTo }); filterOption.Filters = filters; var filteredContent = await _Podio.ItemService.FilterItems(appId,filterOption); if (filteredContent.Items.Any()) { //Loop through and convert the podio items collection of Lead objects foreach (var item in filteredContent.Items) { var lead = new Lead(); lead.PodioItemID = item.ItemId; var companyField = item.Field<TextItemField>("company-or-organisation"); lead.Company = companyField.Value; var potentialRevenueField = item.Field<MoneyItemField>("potential-revenue"); lead.ExpectedValue = potentialRevenueField.Value; var statusField = item.Field<CategoryItemField>("status2"); if (statusField.Options != null && statusField.Options.Any()) lead.Status = new Tuple<int, string>(statusField.Options.First().Id.Value, statusField.Options.First().Text); var leadOwnerField = item.Field<ContactItemField>("sales-contact"); lead.LeadOwners = leadOwnerField.Contacts != null ? leadOwnerField.Contacts.ToDictionary(k => k.UserId.Value, v => v.Name) : null; var nextFollowUpField = item.Field<DateItemField>("next-follow-up"); lead.NextFollowUp = nextFollowUpField.StartDate; leads.Add(lead); } } return leads; }
public async Task <IEnumerable <Lead> > GetAllLeads(DateTime?nextFollowUpFrom = null, DateTime?nextFollowUpTo = null, decimal?potentialRevenueFrom = null, decimal?potentialRevenueTo = null, int?status = null, int?leadOwner = null) { List <Lead> leads = new List <Lead>(); int appId = AppId; var filterOption = new FilterOptions(); Dictionary <string, object> filters = new Dictionary <string, object>(); // Filter leads based on incomig parameters if (status != null) { filters.Add("status2", status); } if (leadOwner != null) { filters.Add("sales-contact", new int[] { leadOwner.Value }); } if (potentialRevenueFrom != null || potentialRevenueTo != null) { filters.Add("potential-revenue", new { from = potentialRevenueFrom, to = potentialRevenueTo }); } if (nextFollowUpFrom != null || nextFollowUpTo != null) { filters.Add("next-follow-up", new { from = nextFollowUpFrom, to = nextFollowUpTo }); } filterOption.Filters = filters; var filteredContent = await _Podio.ItemService.FilterItems(appId, filterOption); if (filteredContent.Items.Any()) { //Loop through and convert the podio items collection of Lead objects foreach (var item in filteredContent.Items) { var lead = new Lead(); lead.PodioItemID = item.ItemId; var companyField = item.Field <TextItemField>("company-or-organisation"); lead.Company = companyField.Value; var potentialRevenueField = item.Field <MoneyItemField>("potential-revenue"); lead.ExpectedValue = potentialRevenueField.Value; var statusField = item.Field <CategoryItemField>("status2"); if (statusField.Options != null && statusField.Options.Any()) { lead.Status = new Tuple <int, string>(statusField.Options.First().Id.Value, statusField.Options.First().Text); } var leadOwnerField = item.Field <ContactItemField>("sales-contact"); lead.LeadOwners = leadOwnerField.Contacts != null?leadOwnerField.Contacts.ToDictionary(k => k.UserId.Value, v => v.Name) : null; var nextFollowUpField = item.Field <DateItemField>("next-follow-up"); lead.NextFollowUp = nextFollowUpField.StartDate; leads.Add(lead); } } return(leads); }