public async Task <IActionResult> AddPenalty(int?id) { //if (id != null) //{ // var currentEmployee = await context.Employees.Where(x => x.Id == id).FirstOrDefaultAsync(); // Bonus penalty = new Bonus(); // if (id != null) { penalty.EmployeesId = Convert.ToInt32(id); } // return View(penalty); //} //return View(); if (id != null) { var currentEmployee = await context.Employees.Where(x => x.Id == id).FirstOrDefaultAsync(); PenaltyViewModel vm = new PenaltyViewModel { Name = currentEmployee.Name, Surname = currentEmployee.Surname, EmployeesId = currentEmployee.Id }; return(View(vm)); } return(View()); }
public ActionResult Edit(PenaltyViewModel model) { if (ModelState.IsValid) { Penalty penaltyToUpdate = penaltyService.Get(model.Penalty.Id); TryUpdateModel(penaltyToUpdate, "Penalty"); penaltyToUpdate.League = leagueService.Get(model.LeagueId); penaltyToUpdate.Team = teamService.Get(model.TeamId); penaltyService.Save(penaltyToUpdate); UpdateTeamLeaguePenaltiesAndStats(model.LeagueId, model.TeamId); penaltyService.Commit(); SuccessMessage(FormMessages.SaveSuccess); return(RedirectToAction("Index")); } PopulateStaticData(model); return(View(model)); }
public ActionResult Create() { PenaltyViewModel model = new PenaltyViewModel(); PopulateStaticData(model); return(View(model)); }
public ActionResult Edit(int id) { PenaltyViewModel model = new PenaltyViewModel(); model.MapToModel(penaltyService.Get(id)); PopulateStaticData(model); return(View(model)); }
public async Task <IActionResult> AddPenalty([Bind("Amount,Date,EmployeesId,Name,Surname")] PenaltyViewModel model) { if (ModelState.IsValid) { Penalty new_penalty = new Penalty() { Amount = model.Amount, Date = model.Date, EmployeesId = model.EmployeesId }; await context.Penalties.AddAsync(new_penalty); await context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public ActionResult Create(PenaltyViewModel model) { if (ModelState.IsValid) { model.Penalty.League = leagueService.Get(model.LeagueId); model.Penalty.Team = teamService.Get(model.TeamId); penaltyService.Save(model.Penalty); penaltyService.Commit(); // Seems to have to be committed before updating points/stats UpdateTeamLeaguePenaltiesAndStats(model.LeagueId, model.TeamId); penaltyService.Commit(); SuccessMessage(FormMessages.SaveSuccess); return(RedirectToAction("Index")); } PopulateStaticData(model); return(View(model)); }
private void PopulateStaticData(PenaltyViewModel model) { model.Teams = teamService.GetTeamsForCurrentSeason().ToSelectList(x => x.ToString(), x => x.Id.ToString(), model.TeamId.ToString()); model.Leagues = leagueService.Get(orderBy: q => q.OrderByDescending(s => s.Id)).ToSelectList(x => x.Season.ToString() + " " + x.ToString(), x => x.Id.ToString(), model.LeagueId.ToString()); }