public ActionResult IssueBill(int id, IssueBillModel model)
        {
            if (!User.IsInRole("buildingmanager")) { return new HttpUnauthorizedResult(); }

            LegalPerson legalPerson = personsRepository.GetLegalPersonByUsername(User.Identity.Name);
            var building = buildingsRepository.GetById(id);
            if (building == null) {
                return HttpNotFound();
            }

            if (!building.BuildingManager.LegalPerson.Equals(legalPerson)) {
                return new HttpUnauthorizedResult();
            }

            if (ModelState.IsValid) {
                try {
                    var bill = new Bill(legalPerson, building.Reserve, model.PaymentDescription, 23) {
                        ReferenceNumber = string.Format("{0}-{1}-{2}", building.Id, building.BuildingManager.Id, DateTime.Now.ToString("yyyy-MM-dd"))
                    };

                    foreach (var billItemModel in model.BillItems) {
                        var billItem = new BillItem(billItemModel.Quantity, billItemModel.Price, billItemModel.Description);
                        bill.AddBillItem(billItem);
                    }

                    billsRepository.SaveOrUpdate(bill);
                    var url = Url.Action("bill", "buildingmanager", new {Id = bill.Id}, "http");
                    emailNotifier.NotifyOfBilling(bill, url);
                    return RedirectToAction("bills");

                } catch (BusinessRulesException ex) {
                    ex.CopyTo(ModelState);
                }
            }

            model.Roles = Roles.GetRolesForUser();
            model.Building = Mapper.Map<Building, BuildingListModel>(building);

            return View(model);
        }
        public ActionResult IssueBill(int id)
        {
            if (!User.IsInRole("buildingmanager")) { return new HttpUnauthorizedResult(); }

            LegalPerson legalPerson = personsRepository.GetLegalPersonByUsername(User.Identity.Name);
            var building = buildingsRepository.GetById(id);
            if(building == null) {
                return HttpNotFound();
            }

            if(!building.BuildingManager.LegalPerson.Equals(legalPerson)) {
                return new HttpUnauthorizedResult();
            }

            var model = new IssueBillModel {
                Building = Mapper.Map<Building, BuildingListModel>(building),
                Roles = Roles.GetRolesForUser(),
                CurrentRole = "buildingmanager",
                Links = new LinksModel{ Id = building.Id, Links = NavLinksGenerator.GetManagerLinks(building, "Upraviteljevi računi")}
            };

            return View(model);
        }