public async Task <TeamViewModel> Create(TeamInputModel model, string creatorId) { Team team = new Team() { Name = model.Name }; team.Members.Add(new TeamMember { UserId = creatorId, TeamRole = TeamRole.Administrator }); foreach (TeamMemberInputModel modelMember in model.Members) { bool isUserValid = await this.userManager.FindByIdAsync(modelMember.Id) != null; if (isUserValid) { team.Members.Add(new TeamMember() { UserId = modelMember.Id, TeamRole = TeamRole.Member }); } } this.teamsRepository.Add(team); await this.teamsRepository.SaveChangesAsync(); var viewModel = Mapper.Map <TeamViewModel>(team); return(viewModel); }
public async Task <IActionResult> Add(TeamInputModel inputModel) { var user = usersService.GetUserByUsername(User.Identity.Name); await this.teamsService.AddAsync(user.Id, user, inputModel.TeamName, inputModel.Users); return(this.Redirect("/")); }
public IActionResult Add() { var users = this.usersService.GetAllUsers().Where(u => u.UserName != User.Identity.Name).Where(u => u.TeamId == null); var inputModel = new TeamInputModel(); ViewBag.Users = users; ViewBag.Data = inputModel; return(View()); }
public async Task <TeamViewModel> EditAsync(int id, TeamInputModel model) { var team = await this.GetByIdAsync(id); team.Name = model.Name; var result = await this.repo.SaveAsync(team); return(this.mapper.Map <TeamViewModel>(result)); }
public async Task <IActionResult> Create([FromBody] TeamInputModel inputModel) { if (!this.ModelState.IsValid) { return(BadRequest(ModelState)); } string loggedUserId = this.User.GetUserId(); TeamViewModel team = await this.teamsService.Create(inputModel, loggedUserId); return(Ok(team)); }
public ActionResult Create(TeamInputModel model) { if (model != null && this.ModelState.IsValid) { var team = Mapper.Map<Team>(model); this.Data.Teams.Add(team); this.Data.SaveChanges(); return this.RedirectToAction("Details", new { id = team.Id }); } //this.LoadCategories(); return this.View(model); }
public ActionResult Create(TeamInputModel teamInput) { if (teamInput != null && this.ModelState.IsValid) { var team = Mapper.Map <Team>(teamInput); this.Data.Teams.Add(team); this.Data.Players.All().Where(p => teamInput.Players.Contains(p.Id)) .Each(p => team.Players.Add(p)); this.Data.SaveChanges(); return(this.RedirectToAction("Details", "Teams", new { id = team.Id })); } return(this.View(teamInput)); }
public async Task <TeamViewModel> CreateAsync(TeamInputModel model) { var existing = await this.repo.All() .FirstOrDefaultAsync(t => t.Name == model.Name); if (existing != null) { throw new InvalidOperationException(string.Format(Constants.ENTITY_ALREADY_EXISTS, nameof(Team))); } var result = await this.repo.SaveAsync(new Team { Name = model.Name }); return(this.mapper.Map <TeamViewModel>(result)); }
public ActionResult Create(TeamInputModel teamInput) { if (teamInput != null && this.ModelState.IsValid) { var team = Mapper.Map<Team>(teamInput); this.Data.Teams.Add(team); this.Data.Players.All().Where(p => teamInput.Players.Contains(p.Id)) .Each(p => team.Players.Add(p)); this.Data.SaveChanges(); return this.RedirectToAction("Details", "Teams", new { id = team.Id }); } return this.View(teamInput); }
public ActionResult Create(TeamInputModel model) { if (model != null && this.ModelState.IsValid) { var team = Mapper.Map<Team>(model); this.Data.Teams.Add(team); this.Data.Players .All() .Where(x => model.PlayersIds.Contains(x.Id)) .Each(x => x.TeamId = team.Id); this.Data.SaveChanges(); return this.RedirectToAction("Details", new { id = team.Id }); } this.LoadPlayers(); return this.View(); }
public ActionResult Create(TeamInputModel model) { if (model != null && this.ModelState.IsValid) { var team = new Team() { Name = model.Name, NickName = model.NickName, DateFounded = model.DateFounded, WebSite = model.WebSite }; this.context.Teams.Add(team); this.context.SaveChanges(); this.AddNotification("Team Created", NotificationType.INFO); return(this.RedirectToRoute("/Teams/Details/" + team.Id)); } return(this.View(model)); }
private bool ValidateTeamInput(TeamInputModel team, out string message) { if (team.username == null && team.teamname == null) { message = "Invalid input: missing teamname and username."; return(false); } if (team.teamname == null) { message = "Invalid input: missing teamname."; return(false); } if (team.username == null) { message = "Invalid input: missing username."; return(false); } message = ""; return(true); }
public IActionResult Edit(string id) { var team = this.teamsService.GetTeamById(id); var usersList = this.usersService.GetAllUsers().Where(u => u.UserName != User.Identity.Name).Where(u => u.TeamId == null); List <string> users = new List <string>(); foreach (var user in usersList) { users.Add(user.UserName); } var inputModel = new TeamInputModel { Id = team.Id, TeamName = team.TeamName, }; ViewBag.Users = users; ViewBag.Data = inputModel; return(View()); }
public ActionResult Add() { var freeTeamLeads = this.employeesService .AllEmployees() .Where(e => e.Position == CompanyRoleType.TeamLeader && e.Team == null && e.Manager != null) .ToList(); //Only Senior(enum 4), Intermediate(enum 5), Junior(enum 6) and Trainee(enum 7) can be added and removed from team. var freeTeamMembers = this.employeesService .AllEmployees() .Where(e => e.Position > CompanyRoleType.TeamLeader && e.Team == null) .ToList(); var teamsViewModel = new TeamInputModel { TeamLeads = this.employeesService.SelectListItemGenerator(freeTeamLeads), TeamMembers = this.employeesService.SelectListItemGenerator(freeTeamMembers) }; return(View(teamsViewModel)); }
public ActionResult Add(TeamInputModel model) { if (!ModelState.IsValid) { return(View(model)); } var teamLeader = this.employeesService.GetEmployeeById(model.ProjectTeamLeadId); if (teamLeader == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var team = this.mappingService.Map <Team>(model); this.teamsService.AddTeam(team, model.ProjectTeamLeadId); this.teamsService.AddTeamMemebers(team, model.TeamMembersIds); return(RedirectToAction(Constants.Index)); }
public ActionResult Create(TeamInputModel model) { if (model != null && this.ModelState.IsValid) { var team = Mapper.Map <Team>(model); this.Data.Teams.Add(team); foreach (var playerId in model.PlayerIds) { var player = this.Data.Players.Find(playerId); player.TeamId = team.Id; this.Data.SaveChanges(); } this.Data.SaveChanges(); return(this.RedirectToAction("Details", new { id = team.Id })); } this.LoadFreePlayers(); return(this.View(model)); }
public ActionResult Create(TeamInputModel model) { if (model != null && this.ModelState.IsValid) { var team = Mapper.Map<Team>(model); this.Data.Teams.Add(team); foreach (var playerId in model.PlayerIds) { var player = this.Data.Players.Find(playerId); player.TeamId = team.Id; this.Data.SaveChanges(); } this.Data.SaveChanges(); return this.RedirectToAction("Details", new { id = team.Id }); } this.LoadFreePlayers(); return this.View(model); }
public async Task <IActionResult> EditAsync(int id, TeamInputModel model) { var result = await this.service.EditAsync(id, model); return(this.Ok(result)); }
public async Task <IActionResult> CreateAsync(TeamInputModel model) { var result = await this.service.CreateAsync(model); return(this.Ok(result)); }
public ActionResult Create(TeamInputModel model) { if (model != null && this.ModelState.IsValid) { Player[] players = new Player[model.PlayersIds.Count]; var team = Mapper.Map<Team>(model); this.Data.Teams.Add(team); this.Data.SaveChanges(); foreach (var playersId in model.PlayersIds) { var player = this.Data.Players.All().FirstOrDefault(p => p.Id == playersId); player.TeamId = team.Id; } this.Data.SaveChanges(); return this.RedirectToAction("Details", new { id = team.Id }); } this.LoadPlayers(); return this.View(model); }
public async Task <IActionResult> Edit(TeamInputModel inputModel) { await this.teamsService.UpdateAsync(inputModel.Id, inputModel.TeamName, inputModel.Users); return(this.Redirect("/Teams/GetUserTeam")); }