private function GetProducts($order = 1)
 {
     $service = new \FabricaDeBolo\Domain\Services\ContentService();
     $sorting = new \FabricaDeBolo\Infrastructure\SortingCollection();
     switch ($order) {
         case 1:
             $sorting->Add(new \FabricaDeBolo\Infrastructure\Sorting("price", true));
             break;
         case 2:
             $sorting->Add(new \FabricaDeBolo\Infrastructure\Sorting("priority", true));
             break;
         case 3:
             $sorting->Add(new \FabricaDeBolo\Infrastructure\Sorting("title", true));
             break;
     }
     $result = $service->GetProducts($sorting);
     return $result->Items;
 }
 public function Cadastro(\FabricaDeBolo\Models\FranchiseeModel $model)
 {
     if ($this->IsPostBack() && $model != null) {
         $customer = new \FabricaDeBolo\Domain\Entities\Customer();
         $customer->has_children = is_bool($model->hasChildren) && $model->hasChildren === true || $model->hasChildren === "true" ? 1 : 0;
         $customer->children_age = $model->childrenAge;
         $customer->marital_status_id = $model->maritalStatus;
         $customer->peoples_live_with_you = $model->peoplesLiveWithYou;
         $customer->family_income = $model->familyIncome;
         $customer->properties = $model->properties;
         $customer->fixed_expenses_percent = $model->fixedExpensesPercent;
         $customer->literacy_id = $model->literacyId;
         $customer->make_course = is_bool($model->makeCourse) && $model->makeCourse === true || $model->makeCourse === "true" ? 1 : 0;
         $customer->course = $model->course;
         $customer->course_year = isset($model->courseYear) ? $model->courseYear : 0;
         $customer->college = $model->college;
         $customer->windows_knowledge = $model->windowsKnowledge;
         $customer->word_knowledge = $model->wordKnowledge;
         $customer->excel_knowledge = $model->excelKnowledge;
         $customer->internet_knowledge = $model->internetKnowledge;
         $customer->other_knowledge = $model->otherKnowledge;
         $customer->question_state_id = $model->questionState;
         $customer->question_city_id = $model->questionCity;
         $customer->question_neighborhood = $model->questionNeighborhood;
         $customer->question_region = $model->questionRegion;
         $customer->question_address = $model->questionAddress;
         $customer->question_values = $model->questionValues;
         $customer->brand_weight = $model->brandWeight;
         $customer->business_model_weight = $model->businessModelWeight;
         $customer->support_weight = $model->supportWeight;
         $customer->franchisee_weight = $model->franchiseeWeight;
         $customerPerson = new \FabricaDeBolo\Domain\Entities\CustomerPerson();
         $customerPerson->type = 'F';
         $customerPerson->name = $model->name;
         $customerPerson->cpf = $model->cpf;
         $customerPerson->rg = $model->rg;
         $customerPerson->birthday = \DateTime::createFromFormat("!d/m/Y", $model->birthday);
         $customerPerson->email = $model->email;
         $customerPerson->profession = $model->profession;
         $customerPerson->current_company = $model->currentCompany;
         $customerPerson->hive_of_activity = $model->hiveOfActivity;
         $customerPerson->office = $model->office;
         $customerPerson->profession_time = $model->professionTime;
         $customerPerson->profession_other_incomes = $model->professionOtherIncomes;
         $customerPerson->occupation_area = $model->occupationArea;
         $p1 = new \FabricaDeBolo\Domain\Entities\CustomerPersonPhone();
         $p1->phone = $model->residentialPhone;
         $p1->type = 'RS';
         $p2 = new \FabricaDeBolo\Domain\Entities\CustomerPersonPhone();
         $p2->phone = $model->commercialPhone;
         $p2->type = 'CM';
         $p3 = new \FabricaDeBolo\Domain\Entities\CustomerPersonPhone();
         $p3->phone = $model->cellphone;
         $p3->type = 'CE';
         $p4 = new \FabricaDeBolo\Domain\Entities\CustomerPersonPhone();
         $p4->phone = $model->faxPhone;
         $p4->type = 'FX';
         $customerSpouse = new \FabricaDeBolo\Domain\Entities\CustomerPerson();
         $customerSpouse->type = 'C';
         $customerSpouse->name = $model->spouseName;
         $customerSpouse->cpf = $model->spouseCpf;
         $customerSpouse->rg = $model->spouseRg;
         $customerSpouse->birthday = \DateTime::createFromFormat("!d/m/Y", $model->spouseBirthday);
         $customerSpouse->email = $model->spouseEmail;
         $customerSpouse->profession = $model->spouseProfession;
         $customerSpouse->current_company = $model->spouseCurrentCompany;
         $customerSpouse->hive_of_activity = $model->spouseHiveOfActivity;
         $customerSpouse->office = $model->spouseOffice;
         $customerSpouse->profession_time = $model->spouseProfessionTime;
         $customerSpouse->profession_other_incomes = $model->spouseProfessionOtherIncomes;
         $customerSpouse->occupation_area = $model->spouseOccupationArea;
         $p5 = new \FabricaDeBolo\Domain\Entities\CustomerPersonPhone();
         $p5->phone = $model->spouseResidentialPhone;
         $p5->type = 'RS';
         $p6 = new \FabricaDeBolo\Domain\Entities\CustomerPersonPhone();
         $p6->phone = $model->spouseCommercialPhone;
         $p6->type = 'CM';
         $p7 = new \FabricaDeBolo\Domain\Entities\CustomerPersonPhone();
         $p7->phone = $model->spouseCellphone;
         $p7->type = 'CE';
         $questions = array();
         foreach ($this->_questions as $qk => $q) {
             if (isset($model->questions[$qk])) {
                 $question = new \FabricaDeBolo\Domain\Entities\CustomerQuestion();
                 $question->index = $qk;
                 $question->answer = $model->questions[$qk];
                 array_push($questions, $question);
             }
         }
         $service = new CustomerService();
         $result = $service->AddRequest($customer, array($customerPerson, $customerSpouse), array($p1, $p2, $p3, $p4), array($p5, $p6, $p7), $questions);
         if ($result->Success) {
             $this->ViewData->Add("Success", "Sua solicitação foi recebida. Em breve entraremos em contato.");
             $model = new \FabricaDeBolo\Models\FranchiseeModel();
         } else {
             $this->ViewData->Add("ErrorMessage", "Não foi possível registrar sua solicitação. Por favor tente mais tarde." . $result->ErrorMessage);
         }
     }
     foreach ($this->_questions as $id => $question) {
         $q = new \FabricaDeBolo\Models\FranchiseeQuestionModel();
         $q->id = $id;
         $q->question = $question;
         $model->questions[$id - 1] = $q;
     }
     $model->literacies = new \System\Mvc\SelectList(array("Ensino Fundamental"));
     $contentService = new \FabricaDeBolo\Domain\Services\ContentService();
     $stateResult = $contentService->GetStates();
     $cityResult = $contentService->GetCities(null);
     $this->ViewData->Add("questionStates", new \System\Mvc\SelectList($stateResult->Items, "state_id", "name"));
     $this->ViewData->Add("states", new \System\Mvc\SelectList($stateResult->Items, "state_id", "acronym"));
     $this->ViewData->Add("cities", new \System\Mvc\SelectList($cityResult->Items, "city_id", "name"));
     $this->ViewData->Add("maritalStatus", new \System\Mvc\SelectList($this->_maritalStatus));
     return $this->View("Cadastro", $model);
 }