Пример #1
0
        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));
        }
Пример #2
0
        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));
        }