public async Task <IActionResult> Create([Bind("Id,User_Id,Created_At,Updated_At")] Boat_crew_leader boat_crew_leader, string boat_Crew) { /* To return the selected boat team name from the database if it exists*/ var get_boat_team = _context.Boat_Crews.SingleOrDefault(x => x.Id == Convert.ToInt32(boat_Crew)); boat_crew_leader.boat_Crew = get_boat_team; if (ModelState.IsValid) { // To pass the creation date on system time boat_crew_leader.Created_At = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Trim()); _context.Add(boat_crew_leader); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index)).WithSuccess("Success", "Successfully Inserted Boat Team Leader Details")); } return(View(boat_crew_leader)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,User_Id,Created_At,Updated_At")] Boat_crew_leader boat_crew_leader, string boat_Crew) { if (id != boat_crew_leader.Id) { return(NotFound()); } /* To return the selected boat team name from the database if it exists*/ var get_boat_team = _context.Boat_Crews.SingleOrDefault(x => x.Id == Convert.ToInt32(boat_Crew)); boat_crew_leader.boat_Crew = get_boat_team; if (ModelState.IsValid) { try { // To set the system time for record update boat_crew_leader.Updated_At = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Trim()); _context.Update(boat_crew_leader); _context.Entry(boat_crew_leader).Property(x => x.Created_At).IsModified = false; // To prevent the datetime property to be set as null on update operation await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Boat_crew_leaderExists(boat_crew_leader.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index)).WithSuccess("Success", "Successfully Updated Boat Leader Details")); } return(View(boat_crew_leader)); }