Beispiel #1
0
        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));
        }
Beispiel #2
0
        public ActionResult Edit(int id)
        {
            TeamsMapper teamsMapper = new TeamsMapper();
            Teams       team        = teamsMapper.SelectTeam(id);

            if (!(User.IsInRole("Admin") || ButtonEnable.TeamsEdit(team.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 }));
            }

            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());

            ViewBag.IfTeam = User.Identity.IsAuthenticated && ButtonEnable.TeamsEdit(team.UserId, new UsersMapper().SelectUser(User.Identity.Name));

            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();
        }
Beispiel #4
0
        public ActionResult Detail(int id)
        {
            TeamsMapper teamsMapper = new TeamsMapper();
            Teams       team        = teamsMapper.SelectTeam(id);

            team.State        = States.FindForTeam(team);
            team.Manufacturer = Manufacturers.FindForTeam(team);

            teamsMapper.GetPrevNextDriver(id, out int?prev, out int?next);
            ViewBag.Prev = prev;
            ViewBag.Next = next;

            ViewBag.IfTeam = User.Identity.IsAuthenticated && ButtonEnable.TeamsEdit(team.UserId, new UsersMapper().SelectUser(User.Identity.Name));

            return(View(team));
        }
Beispiel #5
0
        public bool OpenRecord(object primaryKey)
        {
            if (primaryKey == null)
            {
                return(false);
            }
            var idTeam      = (int)primaryKey;
            var teamsMapper = new TeamsMapper();
            var team        = teamsMapper.SelectTeam(idTeam);

            labelName.Text  = team.Name;
            labelTyres.Text = team.Tyres;

            team.Manufacturer = Manufacturers.FindForTeam(team);
            if (team.Manufacturer != null)
            {
                var manufacturer = new ManufacturersMapper().SelectManufacturer(team.Manufacturer.Id);
                labelManufacturer.Text = manufacturer.Name;
            }
            else
            {
                labelManufacturer.Text = @"N/A";
            }

            team.State = States.FindForTeam(team);
            var state = new StatesMapper().SelectState(team.State.Id);

            labelState.Text = state.Name;

            labelHeader.Text = @"Výpis týmu - " + team.Name;
            Text             = labelHeader.Text;

            _teamId = team.Id;
            teamsMapper.GetPrevNextDriver(_teamId, out _prevId, out _nextId);

            buttonTeamEdit.Visible = ButtonEnable.TeamsEdit(team.UserId, new UsersMapper().SelectUser(Logged.CurrentUser.UserRole));

            return(true);
        }