public ActionResult Edit(EditModel editModel)
        {
            if (ModelState.IsValid) {
                var person = personsRepository.GetPersonByUsername(User.Identity.Name);
                if (person == null) {
                    return HttpNotFound();
                }

                person.Name = editModel.Name;

                if (!string.IsNullOrEmpty(editModel.Surname) && person is PhysicalPerson) {
                    (person as PhysicalPerson).Surname = editModel.Surname;
                }

                var city = citiesRepository.GetById(editModel.Address.City.Id);
                var address = new Address(editModel.Address.StreetAddress, editModel.Address.StreetAddressNumber, city);
                person.Address = address;

                if (!string.IsNullOrEmpty(editModel.TelephoneNumber)) {
                    person.AddTelephone(new Telephone("Telefon", editModel.TelephoneNumber));
                } else if (!string.IsNullOrEmpty(editModel.MobileNumber)) {
                    person.AddTelephone(new Telephone("Mobitel", editModel.MobileNumber));
                }

                NHibernateMembershipUser user = Membership.GetUser() as NHibernateMembershipUser;
                user.User.Email = editModel.Email;

                if (!string.IsNullOrEmpty(editModel.Password) && !string.IsNullOrEmpty(editModel.ConfirmPassword) &&
                    editModel.Password.Equals(editModel.ConfirmPassword)) {
                    var membershipProvider = Membership.Provider;
                    var isPasswordChanged = membershipProvider.ChangePassword(User.Identity.Name, editModel.OldPassword, editModel.Password);
                    if (!isPasswordChanged) {
                        ModelState.AddModelError("OldPassword", "Unjeli ste neispravnu trenutnu lozinku.");
                        editModel.Address.Cities = new SelectList(citiesRepository.GetAll(), "Id", "Name", editModel.Address.City.Id);
                        editModel.Roles = Roles.GetRolesForUser();
                        editModel.UserName = User.Identity.Name;
                        return View(editModel);
                    }
                }

                return RedirectToAction("index", "dashboard");

            }

            editModel.Address.Cities = new SelectList(citiesRepository.GetAll(), "Id", "Name", editModel.Address.City.Id);
            editModel.Roles = Roles.GetRolesForUser();
            editModel.UserName = User.Identity.Name;
            return View(editModel);
        }
        public ActionResult Edit()
        {
            var person = personsRepository.GetPersonByUsername(User.Identity.Name);
            if (person == null) {
                return HttpNotFound();
            }

            NHibernateMembershipUser user = Membership.GetUser() as NHibernateMembershipUser;

            var model = new EditModel {
                Roles = Roles.GetRolesForUser(),
                UserName = user.UserName,
                Email = user.Email,
                Name = person.Name,
                Address = Mapper.Map<Address, AddressModel>(person.Address)
            };

            if (person is PhysicalPerson) {
                model.Surname = (person as PhysicalPerson).Surname;
            }

            model.Address.Cities = new SelectList(citiesRepository.GetAll(), "Id", "Name", person.Address.City.Id);
            foreach (var telephone in person.Telephones) {
                if (telephone.NameOfTelephoneNumber == "Telefon") {
                    model.TelephoneNumber = telephone.TelephoneNumber;
                } else if (telephone.TelephoneNumber == "Mobitel") {
                    model.MobileNumber = telephone.TelephoneNumber;
                }
            }

            return View(model);
        }