Teams creation and prizes creation are implemented

This commit is contained in:
2020-05-05 23:25:28 +02:00
parent fc49f33575
commit 9596d9aa47
15 changed files with 387 additions and 4 deletions

View File

@ -0,0 +1,59 @@
using MVCUI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TrackerLibrary;
using TrackerLibrary.Models;
namespace MVCUI.Controllers
{
public class TeamsController : Controller
{
// GET: Teams
public ActionResult Index()
{
List<TeamModel> allTeams = GlobalConfig.Connection.GetTeam_All();
return View(allTeams);
}
// GET: Teams/Create
public ActionResult Create()
{
List<PersonModel> people = GlobalConfig.Connection.GetPerson_All();
TeamMVCModel input = new TeamMVCModel();
input.TeamMembers = people.Select(x => new SelectListItem { Text = x.FullName, Value = x.Id.ToString() }).ToList();
return View(input);
}
// POST: Teams/Create
[ValidateAntiForgeryToken()]
[HttpPost]
public ActionResult Create(TeamMVCModel model)
{
try
{
// TODO: Add insert logic here
if(ModelState.IsValid && model.SelectedTeamMembers.Count > 0)
{
TeamModel t = new TeamModel();
t.TeamName = model.TeamName;
t.TeamMembers = model.SelectedTeamMembers.Select(x => new PersonModel { Id = int.Parse(x) }).ToList();
GlobalConfig.Connection.CreateTeam(t);
return RedirectToAction("Index");
}
else
{
return RedirectToAction("Create");
}
}
catch
{
return View();
}
}
}
}