public ActionResult RegisterContractor(RegisterContractorUserModel contractorModel)
        {
            if (ModelState.IsValid) {
                Person person = personsRepository.GetByOib(contractorModel.Oib);
                bool isUserExistingForPerson = false;
                if (person != null) {
                    var existingUser = housingMgmtUsersRepository.GetUserByPerson(person);
                    isUserExistingForPerson = existingUser != null;
                }

                if (!isUserExistingForPerson) {
                    MembershipCreateStatus createStatus;
                    NHibernateMembershipUser membershipUser =
                        Membership.CreateUser(contractorModel.UserName, contractorModel.Password, contractorModel.Email,
                                              null, null, true, null, out createStatus) as NHibernateMembershipUser;

                    if (createStatus == MembershipCreateStatus.Success) {

                        if (person == null) {
                            // Probaj kreirati pravnu osobu i izvodaca radova
                            City city = citiesRepository.GetById(contractorModel.City);
                            person = new LegalPerson(contractorModel.Oib, contractorModel.Name) {
                                NumberOfBankAccount = contractorModel.NumberOfBankAccount,
                                Address = new Address(contractorModel.StreetAddress, contractorModel.StreetAddressNumber, city)
                            };

                            if (!string.IsNullOrEmpty(contractorModel.TelephoneNumber)) {
                                person.AddTelephone(new Telephone("Telefon", contractorModel.TelephoneNumber));
                            }

                            if (!string.IsNullOrEmpty(contractorModel.MobileNumber)) {
                                person.AddTelephone(new Telephone("Mobitel", contractorModel.MobileNumber));
                            }
                        }

                        if (person is LegalPerson) {
                            Contractor contractor = null;
                            try {
                                membershipUser.User.Person = person;

                                var contractorRole = rolesRepository.GetRole("contractor");
                                membershipUser.User.AddRole(contractorRole);

                                var partitionSpaces = partitionSpacesRepository.GetPartitionSpaces(person);
                                if (partitionSpaces.Count > 0) {
                                    var ownerRole = rolesRepository.GetRole("owner");
                                    membershipUser.User.AddRole(ownerRole);
                                }

                                contractor = new Contractor(person as LegalPerson);

                                foreach (var repairServiceId in contractorModel.SelectedRepairServices) {
                                    var repairService = repairServicesRepository.GetById(repairServiceId);
                                    if (repairService != null) {
                                        contractor.AddRepairService(repairService);
                                    }
                                }

                                FormsAuthentication.SetAuthCookie(contractorModel.UserName, false);
                                contractorsRepository.SaveOrUpdate(contractor);
                                emailNotifier.NotifyOfRegistration(membershipUser.User);
                                return RedirectToAction("index", "dashboard");

                            } catch (BusinessRulesException ex) {
                                ex.CopyTo(ModelState);
                            }
                        } else {
                            ModelState.AddModelError("Oib", "Osoba sa ovim OIB-om je već upisana te nije pravna osoba.");
                        }

                    } else {
                        ModelState.AddModelError("", errorCodeToString(createStatus));
                    }
                } else {
                    ModelState.AddModelError("", "Navedena osoba već ima kreiran korisnički račun.");
                }

            }

            contractorModel.Cities = new SelectList(citiesRepository.GetAll(), "Id", "Name");
            contractorModel.RepairServices = new SelectList(repairServicesRepository.GetAll(), "Id", "Name", contractorModel.City);

            return View(contractorModel);
        }
        public ActionResult RegisterContractor()
        {
            if (User.Identity.IsAuthenticated) {
                return RedirectToAction("index", "dashboard");
            }

            RegisterContractorUserModel model = new RegisterContractorUserModel {
                Cities = new SelectList(citiesRepository.GetAll(), "Id", "Name"),
                RepairServices = new SelectList(repairServicesRepository.GetAll(), "Id", "Name")
            };

            return View(model);
        }