public ActionResult Create([Bind(Exclude = "Id")] Account account) { string userName = this.User.Identity.Name; int sectorId = Int32.Parse(Request.Form["Account.SectorId"]);/*we prefix, as the sector is inside the Account editor*/ /*and isn't directly bound as field of the Account*/ //we get the owner the account User owner = _userService.GetUser(userName); //we get the industrial sector from the db IndustrialSector sector = _sectorService.GetIndustrialSector(sectorId); account.Owner = owner; account.IndustrialSector = sector; if (!_accountService.CreateAccount(account)) { var sectors = _sectorService.ListIndustrialSectors(); var viewModel = new AccountViewModel(account) { Sectors = new SelectList(sectors, "Id", "Sector") }; return(View(viewModel)); } return(RedirectToAction("Index")); }
// // GET: /Sector/Edit/5 public ActionResult Edit(int id) { var sector = _sectorService.GetIndustrialSector(id); if (sector == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(View("NotFound")); } return(View(sector)); }