public async Task <IActionResult> PutMyTable(int id, MyTable myTable) { if (id != myTable.id) { return(BadRequest()); } _context.Entry(myTable).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MyTableExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> PutCollege(int id, College college) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != college.Id) { return(BadRequest()); } db.Entry(college).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CollegeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("ComentarioId,Titulo,Descricao,DataDoComentario,Autor")] Comentario comentario) { if (ModelState.IsValid) { _context.Add(comentario); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(comentario)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description,Price")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("RollNumber,FirstName,LastName,Phone,Birthday,Gender,Address,Action")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Age,Email,CreatedAt,UpdatedAt,Status")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("Id,Name,StadiumName,City,NumberTitles,CoachId")] Team team) { if (ModelState.IsValid) { _context.Add(team); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CoachId"] = new SelectList(_context.Coach, "Id", "FullName", team.CoachId); return(View(team)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,NumberOfTitles,Country,BirthDate,TeamId")] Coach coach) { if (ModelState.IsValid) { _context.Add(coach); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["TeamId"] = new SelectList(_context.Set <Team>(), "Id", "City", coach.TeamId); return(View(coach)); }
public async Task <IActionResult> Create([Bind("Id,JerseyNumber,FirstName,LastName,Weight,Height,Position,PrefferedLeg,Goals,Country,BirthDate,ContractId")] Player player) { if (ModelState.IsValid) { _context.Add(player); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ContractId"] = new SelectList(_context.Contract, "Id", "Id", player.ContractId); return(View(player)); }
public async Task <IActionResult> Create([Bind("Id,Titulo,Descricao,Data,CategoriaId,ComentarioId")] Mensagem mensagem) { if (ModelState.IsValid) { _context.Add(mensagem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoriaId"] = new SelectList(_context.Categoria, "CategoriaId", "CategoriaId", mensagem.CategoriaId); ViewData["ComentarioId"] = new SelectList(_context.Comentario, "ComentarioId", "ComentarioId", mensagem.ComentarioId); return(View(mensagem)); }
public async Task <IActionResult> Create([Bind("Id,PlayerId,TeamId,Salary,StartingDate,FinishDate")] Contract contract) { if (ModelState.IsValid) { _context.Add(contract); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PlayerId"] = new SelectList(_context.Set <Player>(), "Id", "FirstName", contract.PlayerId); ViewData["TeamId"] = new SelectList(_context.Set <Team>(), "Id", "City", contract.TeamId); return(View(contract)); }
public async Task <IActionResult> Create([Bind("Id,Title,ImageFile,PlayerId")] Image image) { if (ModelState.IsValid) { //Save image to wwwroot/image string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(image.ImageFile.FileName); string extension = Path.GetExtension(image.ImageFile.FileName); image.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; string path = Path.Combine(wwwRootPath + "/Image/", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await image.ImageFile.CopyToAsync(fileStream); } //Insert record _context.Add(image); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PlayerId"] = new SelectList(_context.Player, "Id", "FullName", image.PlayerId); return(View(image)); }