public IActionResult Create([Bind("InstructorID,Name,Surname,Midname,Experience,Aducation")] Instructor instructor) { if (ModelState.IsValid) { _context.Add(instructor); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(instructor)); }
public IActionResult Create([Bind("VisitorID,GroupID,Name,Surname,Midname,Passport")] Visitor visitor) { if (ModelState.IsValid) { _context.Add(visitor); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } ViewData["GroupID"] = new SelectList(_context.Groups, "GroupID", "GroupID", visitor.GroupID); return(View(visitor)); }
public IActionResult Create([Bind("TimeTableID,GroupID,Time_visits,Days_of_the_week")] TimeTable timeTable) { if (ModelState.IsValid) { _context.Add(timeTable); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } ViewData["GroupID"] = new SelectList(_context.Groups, "GroupID", "GroupID", timeTable.GroupID); return(View(timeTable)); }
public async Task <IActionResult> Create([Bind("SportID,SportTitle,Description")] Sport sport) { if (ModelState.IsValid) { _context.Add(sport); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(sport)); }
public IActionResult Create([Bind("GroupID,InstructorID,Name,Count_of_visitor")] Group @group) { if (ModelState.IsValid) { _context.Add(@group); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } ViewData["InstructorID"] = new SelectList(_context.Instructors, "InstructorID", "InstructorID", @group.InstructorID); return(View(@group)); }
public async Task <IActionResult> Create([Bind("Id,Email,Password,RoleId")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RoleId"] = new SelectList(_context.Roles, "Id", "Id", user.RoleId); return(View(user)); }
public async Task <IActionResult> Create([Bind("EnrollmentID,SportID,ContestantID")] Enrollment enrollment) { if (ModelState.IsValid) { _context.Add(enrollment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ContestantID"] = new SelectList(_context.Contestants, "ID", "ID", enrollment.ContestantID); ViewData["SportID"] = new SelectList(_context.Sports, "SportID", "SportID", enrollment.SportID); return(View(enrollment)); }
public async Task <IActionResult> Create([FromBody][Bind("Username,Email,FirstName,LastName,Phone")] User user) { try { _context.Add(user); await _context.SaveChangesAsync(); return(Ok(user)); } catch (Exception e) { return(Conflict(new { errorText = e.Message })); } }
static void Main(string[] args) { var firstTeam = new Team { Name = "Реал мадрид" }; var secondTeam = new Team { Name = "Барсилона" }; var firstPlayer = new Player { FullName = "Месси", Number = 5, TeamId = secondTeam.Id }; var secondPlayer = new Player { FullName = "Роналду", Number = 17, TeamId = firstTeam.Id }; using (var context = new SportContext()) { context.Add(firstTeam); context.Add(secondTeam); context.Add(firstPlayer); context.Add(secondPlayer); foreach (var team in context.Teams) { Console.WriteLine($"\nКоманда {team.Name}"); Console.WriteLine("Игроки:"); foreach (var player in context.Players.Where(player => player.TeamId == team.Id).ToList()) { Console.WriteLine($"[{player.Number}] {player.FullName}"); } } var result = context.Players.First(); var teamIdForRemove = result.TeamId; result.TeamId = context.Teams.Where(team => team.Id != result.TeamId).First().Id; context.Update(result); context.Remove(context.Teams.Where(team => team.Id == teamIdForRemove).First()); foreach (var team in context.Teams) { Console.WriteLine($"\nКоманда {team.Name}"); Console.WriteLine("Игроки:"); foreach (var player in context.Players.Where(player => player.TeamId == team.Id).ToList()) { Console.WriteLine($"[{player.Number}] {player.FullName}"); } } } }