public ActionResult Edit(Teams team) { TeamsMapper teamsMapper = new TeamsMapper(); Teams teamFromDb = teamsMapper.SelectTeam(team.Id); if (!(User.IsInRole("Admin") || ButtonEnable.TeamsEdit(teamFromDb.UserId, new UsersMapper().SelectUser(User.Identity.Name)))) { TempData["message-error"] = "Nemáte oprávnění provádět tyto změny"; return(RedirectToAction("Detail", "Teams", new { id = team.Id })); } if (ModelState.IsValid) { teamsMapper.Edit(team); TempData["message-success"] = "Tým byl zmeněn"; return(RedirectToAction("Detail", "Teams", new { id = team.Id })); } TempData["message-error"] = "Při zpracování se stala chyba"; team.State = States.FindForTeam(team); team.Manufacturer = Manufacturers.FindForTeam(team); ViewBag.Name = team.Name; ViewBag.States = new StatesMapper().SelectAll(); ((Collection <States>)ViewBag.States).Insert(0, new States().EmptyState()); ViewBag.Manufacturers = new ManufacturersMapper().SelectAll(); ((Collection <Manufacturers>)ViewBag.Manufacturers).Insert(0, new Manufacturers().EmptyManufacturer()); return(View(team)); }
private void buttonTeamSave_Click(object sender, EventArgs e) { var teamsMapper = new TeamsMapper(); var manufacturersMapper = new ManufacturersMapper(); var teamFromDb = teamsMapper.SelectTeam(_teamId); teamFromDb.State = States.FindForTeam(teamFromDb); var totalCount = manufacturersMapper.SelectTotalCount(); var count = manufacturersMapper.SelectCountId(comboBoxManufacturer.SelectedIndex); if (totalCount / 2 < count) { labelError.Text = @"Dodavatel motorů nesmí dodávat motory více, jak polovině týmů."; return; } var team = new Teams(); team.Id = _teamId; team.Name = textBoxName.Text; team.Tyres = textBoxTyres.Text; if (comboBoxManufacturer.SelectedIndex == 0) { team.Manufacturer = null; } else { team.Manufacturer = new Manufacturers() { Id = comboBoxManufacturer.SelectedIndex }; } team.State = new States { Id = comboBoxState.SelectedIndex }; if (team.State.Id < 1) { labelError.Text = @"Tým musí mít vybraný stát"; return; } teamsMapper.Edit(team); Close(); }