public async Task <IActionResult> Edit(int id, [Bind("Id,Type")] TripTypeEntity tripTypeEntity) { if (id != tripTypeEntity.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tripTypeEntity); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TripTypeEntityExists(tripTypeEntity.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tripTypeEntity)); }
public async Task <IActionResult> Create(TripTypeEntity tripTypeEntity) { if (ModelState.IsValid) { _context.Add(tripTypeEntity); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "There is already a record with the same name."); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } } return(View(tripTypeEntity)); }
private TripTypeResponse ToTripTypeResponse(TripTypeEntity TripType) { if (TripType == null) { return(null); } return(new TripTypeResponse { Id = TripType.Id, Type = TripType.Type }); }