public ActionResult Edit(Drivers driver) { driver.Team = Teams.FindForDriver(driver); if (!(User.IsInRole("Admin") || driver.Team != null && ButtonEnable.TeamsEdit(driver.Team.UserId, new UsersMapper().SelectUser(User.Identity.Name)))) { return(RedirectToAction("Detail", "Drivers", new { id = driver.Id })); } DriversMapper driverMapper = new DriversMapper(); if (ModelState.IsValid) { driverMapper.Edit(driver); TempData["message-success"] = "Uživatel byl zmeněn"; return(RedirectToAction("Detail", "Drivers", new { id = driver.Id })); } driver.Team = Teams.FindForDriver(driver); driver.State = States.FindForDriver(driver); Drivers driverFromDb = driverMapper.SelectDriver(driver.Id); ViewBag.FirstName = driverFromDb.FirstName; ViewBag.LastName = driverFromDb.LastName; ViewBag.States = new StatesMapper().SelectAll(); ((Collection <States>)ViewBag.States).Insert(0, new States().EmptyState()); ViewBag.Teams = new TeamsMapper().SelectAll(); ((Collection <Teams>)ViewBag.Teams).Insert(0, new Teams().EmptyTeam()); return(View(driver)); }
public static States FindForDriver(Drivers driver) { var driversMapper = new DriversMapper(); if (driversMapper.SelectTeam(driver.Id) == null) { return(null); } return(new StatesMapper().SelectState((int)driversMapper.SelectState(driver.Id))); }
public bool OpenRecord(object primaryKey) { InsertItems.ToStatesNationality(comboBoxNationality); InsertItems.ToTeams(comboBoxTeam); if (primaryKey == null) { return(false); } var idDriver = (int)primaryKey; var driver = new DriversMapper().SelectDriver(idDriver); textBoxFirstName.Text = driver.FirstName; textBoxLastName.Text = driver.LastName; if (driver.Number != null) { numericUpDownNumber.Value = (int)driver.Number; } if (driver.DateOfBirth != null) { dateTimePickerDateOfbirth.Value = (DateTime)driver.DateOfBirth; } driver.Team = Teams.FindForDriver(driver); if (driver.Team != null) { comboBoxTeam.SelectedIndex = driver.Team.Id; } else { comboBoxTeam.SelectedIndex = -1; } driver.State = States.FindForDriver(driver); if (driver.State != null) { comboBoxNationality.SelectedIndex = driver.State.Id; } else { comboBoxNationality.SelectedIndex = -1; } labelHeader.Text = @"Úprava jezdce - " + driver.FirstName + @" " + driver.LastName; Text = labelHeader.Text; _driverId = driver.Id; return(true); }
public ActionResult Detail(int id) { DriversMapper driverMapper = new DriversMapper(); Drivers driver = driverMapper.SelectDriver(id); driver.State = States.FindForDriver(driver); driver.Team = Teams.FindForDriver(driver); driverMapper.GetPrevNextDriver(id, out int?prev, out int?next); ViewBag.Prev = prev; ViewBag.Next = next; ViewBag.IfTeam = User.Identity.IsAuthenticated && driver.Team != null && ButtonEnable.TeamsEdit(driver.Team.UserId, new UsersMapper().SelectUser(User.Identity.Name)); return(View(driver)); }
private void RefreshData() { var auctions = new DriversMapper().SelectAll(); var bindingList = new BindingList <Drivers>(auctions); dataGridView1.AutoGenerateColumns = false; dataGridView1.Rows.Clear(); foreach (var driver in bindingList) { var rowIndex = dataGridView1.Rows.Add(); var row = dataGridView1.Rows[rowIndex]; row.Cells["FirstName"].Value = driver.FirstName; row.Cells["LastName"].Value = driver.LastName; row.Cells["ID"].Value = driver.Id; } }
public bool OpenRecord(object primaryKey) { if (primaryKey == null) { return(false); } var idGp = (int)primaryKey; var gpMapper = new GpMapper(); var classificationMapper = new ClassificationMapper(); var gp = gpMapper.SelectGp(idGp); var drivers = new DriversMapper().SelectAll(); var bindingList = new BindingList <Drivers>(drivers); dataGridView1.AutoGenerateColumns = false; dataGridView1.Rows.Clear(); foreach (var driver in bindingList) { var rowIndex = dataGridView1.Rows.Add(); var row = dataGridView1.Rows[rowIndex]; row.Cells["Position"].Value = classificationMapper.SelectGpDriver(gp.Id, driver.Id); row.Cells["LastName"].Value = driver.LastName; row.Cells["FirstName"].Value = driver.FirstName; row.Cells["ID"].Value = driver.Id; } if (classificationMapper.SelectGpCount(gp.Id) == 0) { labelError.Text = @"Výsledky pro tuto GP ještě neexistují."; } else { labelError.Text = ""; } labelHeader.Text = @"Zobrazení výsledků GP - " + gp.Name; Text = labelHeader.Text; _gpId = idGp; gpMapper.GetPrevNextDriver(_gpId, out _prevId, out _nextId); buttonGpEdit.Visible = ButtonEnable.TeamsEdit(gp.UserId, new UsersMapper().SelectUser(Logged.CurrentUser.UserRole)); return(true); }
public bool OpenRecord(object primaryKey) { if (primaryKey == null) { return(false); } var idDriver = (int)primaryKey; var driverMapper = new DriversMapper(); var driver = driverMapper.SelectDriver(idDriver); labelFirstNameEdit.Text = driver.FirstName; labelLastNameEdit.Text = driver.LastName; labelNumberEdit.Text = driver.Number.ToString(); if (driver.DateOfBirth != null) { labelDateOfBirthEdit.Text = ((DateTime)driver.DateOfBirth).ToString("dd/MM/yyyy"); } driver.Team = Teams.FindForDriver(driver); if (driver.Team != null) { var team = new TeamsMapper().SelectTeam(driver.Team.Id); labelTeamEdit.Text = team.Name; } else { labelTeamEdit.Text = @"N/A"; } driver.State = States.FindForDriver(driver); var state = new StatesMapper().SelectState(driver.State.Id); labelNationailityEdit.Text = state.Nationality; labelHeader.Text = @"Výpis jezdce - " + driver.FirstName + @" " + driver.LastName; Text = labelHeader.Text; _driverId = driver.Id; driverMapper.GetPrevNextDriver(_driverId, out _prevId, out _nextId); buttonDriverEdit.Visible = driver.Team != null && ButtonEnable.TeamsEdit(driver.Team.UserId, new UsersMapper().SelectUser(Logged.CurrentUser.UserRole)); return(true); }
public ActionResult Add(Drivers driver) { DriversMapper driverMapper = new DriversMapper(); ModelState.Remove("Id"); if (ModelState.IsValid) { driverMapper.Insert(driver); TempData["message-success"] = "Uživatel byl přidán"; return(RedirectToAction("Index", "Drivers")); } ViewBag.States = new StatesMapper().SelectAll(); ((Collection <States>)ViewBag.States).Insert(0, new States().EmptyState()); ViewBag.Teams = new TeamsMapper().SelectAll(); ((Collection <Teams>)ViewBag.Teams).Insert(0, new Teams().EmptyTeam()); return(View(driver)); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (value != null) { try { var driversMapper = new DriversMapper(); var number = (Teams)value; if (driversMapper.SelectCountDrivers(number.Id) >= 2 && ((Library.Models.Drivers)validationContext.ObjectInstance).Team.Id != number.Id) { return(new ValidationResult("Tým již má přidělené 2 jezdce.")); } } catch (Exception) { return(new ValidationResult("Špatně vybraný tým.")); } } return(ValidationResult.Success); }
public ActionResult Edit(int id) { DriversMapper driverMapper = new DriversMapper(); Drivers driver = driverMapper.SelectDriver(id); driver.Team = Teams.FindForDriver(driver); if (!(User.IsInRole("Admin") || driver.Team != null && ButtonEnable.TeamsEdit(driver.Team.UserId, new UsersMapper().SelectUser(User.Identity.Name)))) { return(RedirectToAction("Detail", "Drivers", new { id = id })); } driver.State = States.FindForDriver(driver); ViewBag.FirstName = driver.FirstName; ViewBag.LastName = driver.LastName; ViewBag.States = new StatesMapper().SelectAll(); ((Collection <States>)ViewBag.States).Insert(0, new States().EmptyState()); ViewBag.Teams = new TeamsMapper().SelectAll(); ((Collection <Teams>)ViewBag.Teams).Insert(0, new Teams().EmptyTeam()); return(View(driver)); }
private void ButtonDriverEdit_Click(object sender, EventArgs e) { var count = 0; var driversMapper = new DriversMapper(); var driverFromDb = driversMapper.SelectDriver(_driverId); driverFromDb.Team = Teams.FindForDriver(driverFromDb); var driver = new Drivers { Id = _driverId, FirstName = textBoxFirstName.Text, LastName = textBoxLastName.Text }; if (driver.FirstName.Any(char.IsDigit) || driver.LastName.Any(char.IsDigit)) { labelError.Text = @"Jméno nebo příjmení obsahuje číslice"; return; } driver.Number = (int)numericUpDownNumber.Value; driver.DateOfBirth = dateTimePickerDateOfbirth.Value; if ((DateTime.Now - (DateTime)driver.DateOfBirth).TotalDays < (365 * 15)) { labelError.Text = @"Jezdec nesmí mít méně, než 15 let"; return; } if (comboBoxTeam.SelectedIndex == 0) { driver.Team = null; } else { driver.Team = new Teams { Id = comboBoxTeam.SelectedIndex }; count = driversMapper.SelectCountDrivers(comboBoxTeam.SelectedIndex); } if (driver.Team != null && (count >= 2 && driverFromDb.Team.Id != driver.Team.Id)) { labelError.Text = @"Tým již má přidělené 2 jezdce"; return; } driver.State = new States { Id = comboBoxNationality.SelectedIndex }; if (driver.State.Id < 1) { labelError.Text = @"Uživatel musí m9t vybranou národnost"; return; } driversMapper.Edit(driver); Close(); }
public bool OpenRecord(object primaryKey) { try { if (primaryKey == null) { return(false); } _gpId = (int)primaryKey; var gpMapper = new GpMapper(); var classificationMapper = new ClassificationMapper(); var results = classificationMapper.SelectAll(_gpId); var gp = gpMapper.SelectGp(_gpId); var drivers = new DriversMapper().SelectAll(); var positions = new PointsMapper().SelectAll(); var bindingList = new BindingList <Drivers>(drivers); dataGridView1.AutoGenerateColumns = false; dataGridView1.Rows.Clear(); foreach (var driver in bindingList) { var rowIndex = dataGridView1.Rows.Add(); var row = dataGridView1.Rows[rowIndex]; row.Cells["Position"].ValueType = typeof(int); ((DataGridViewComboBoxCell)row.Cells["Position"]).Items.Insert(0, ""); foreach (var position in positions) { ((DataGridViewComboBoxCell)row.Cells["Position"]).Items.Insert(position.Position, position.Position); } try { if (results.ContainsKey(driver.Id)) { row.Cells["Position"].Value = results[driver.Id].Position; } } catch { // ignored } row.Cells["LastName"].Value = driver.LastName; row.Cells["FirstName"].Value = driver.FirstName; row.Cells["ID"].Value = driver.Id; } labelError.Text = ""; if (results.Count == 0) { labelError.Text += @"Výsledky pro tuto GP ještě neexistují. "; } if (gp.Date.AddHours(1) > DateTime.Now) { labelError.Text += @"Výsledky lze uložit nejdříve 1 hodinu po startu GP. "; } labelHeader.Text = @"Úprava výsledků GP - " + gp.Name; Text = labelHeader.Text; } catch (Exception e) { Console.WriteLine(e); throw; } return(true); }