public ActionResult <MovieTransaction> PostMovieTransaction(MovieTransaction oMovieTransaction) { try { int iUserTransactionID = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);; string sErrorMessage = ""; int iResult = oRepository.CreateTransaction(iUserTransactionID, oMovieTransaction, out sErrorMessage); if (!string.IsNullOrEmpty(sErrorMessage)) { return(BadRequest(new { Message = sErrorMessage })); } if (iResult == 0) { return(BadRequest(new { Message = "Unable to create Movie Transaction" })); } else { return(CreatedAtAction("GetMovieTransaction", new { iMovieTransactionId = oMovieTransaction.MovieTransactionID }, oMovieTransaction)); } } catch (Exception ex) { return(BadRequest(new { ex.Message })); } }
public IActionResult Edit(int id, [Bind("Id,MovieId,CustomerId")] MovieTransaction movieTransaction) { if (id != movieTransaction.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(movieTransaction); _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MovieTransactionExists(movieTransaction.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "CustomerName", movieTransaction.CustomerId); ViewData["MovieId"] = new SelectList(_context.Movie, "Id", "MovieName", movieTransaction.MovieId); return(View(movieTransaction)); }
public IActionResult Create([Bind("Id,MovieId,CustomerId")] MovieTransaction movieTransaction) { if (ModelState.IsValid) { _context.Add(movieTransaction); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "CustomerName", movieTransaction.CustomerId); ViewData["MovieId"] = new SelectList(_context.Movie, "Id", "MovieName", movieTransaction.MovieId); return(View(movieTransaction)); }
public IActionResult PutMovieTransaction(int iMovieTransactionId, MovieTransaction oMovieTransaction) { if (iMovieTransactionId != oMovieTransaction.MovieTransactionID) { return(BadRequest()); } try { oRepository.Update(oMovieTransaction); } catch (Exception ex) { throw ex; } return(NoContent()); }