public async Task <IActionResult> PutSport(int id, [FromBody] Sport sport) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != sport.Id) { return(BadRequest()); } context.Entry(sport).State = EntityState.Modified; context.Entry(sport.Languages[0]).State = EntityState.Modified; try { await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SportExists(id)) { return(NotFound()); } else { throw; } } return(CreatedAtAction("PutSport", new { id = sport.Id }, sport)); }
public ActionResult Edit(Sport sport) { try { if (ModelState.IsValid) { db.Entry(sport).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Sport)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes.The sport was deleted by another user."); } else { var databaseValues = (Sport)databaseEntry.ToObject(); if (databaseValues.Head1 != clientValues.Head1) { ModelState.AddModelError("Head1", "Current Value:" + databaseValues.Head1); } if (databaseValues.Head2 != clientValues.Head2) { ModelState.AddModelError("Head2", "Current Value:" + databaseValues.Head2); } if (databaseValues.Description != clientValues.Description) { ModelState.AddModelError("Description", "Current Value:" + databaseValues.Description); } if (databaseValues.Image != clientValues.Image) { ModelState.AddModelError("Image", "Current Value:" + databaseValues.Image); } ModelState.AddModelError(string.Empty, "The record you attempted to edit" + " Was modified by another user after you got the original value." + " The edit operation was cancelled and the current values in the database" + " Have been displayed.If you still want to edit this record" + " Click,the save button again.Otherwise click the back to list hyperlink"); sport.RowVersion = databaseValues.RowVersion; } } catch (RetryLimitExceededException) { ModelState.AddModelError(string.Empty, "Unable to save changes.Try again,and if the problem is persists contact your system administrator. "); } return(View(sport)); }
public ActionResult Edit(TypeOfSport typeOfSport) { try { db.Entry(typeOfSport).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (TypeOfSport)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes,the typeofsport was deleted by another user."); } else { var databaseValues = (TypeOfSport)databaseEntry.ToObject(); if (databaseValues.Head != clientValues.Head) { ModelState.AddModelError("Head", "Current Value:" + databaseValues.Head); } if (databaseValues.Description != clientValues.Description) { ModelState.AddModelError("Description", "Current Value:" + databaseValues.Description); } if (databaseValues.Image != clientValues.Image) { ModelState.AddModelError("Image", "Current Value:" + databaseValues.Image); } if (databaseValues.Image1 != clientValues.Image1) { ModelState.AddModelError("Image1", "Current Value:" + databaseValues.Image1); } if (databaseValues.SportID != clientValues.SportID) { ModelState.AddModelError("SportID", "Current Value:" + db.TypesOfSports.Find(databaseValues.SportID)); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); typeOfSport.RowVersion = databaseValues.RowVersion; } } catch (RetryLimitExceededException) { ModelState.AddModelError(string.Empty, "Unable to save changes. Try again, and if the problem persists contact your system administrator."); } ViewBag.SportID = new SelectList(db.Sports, "SportID", "SportID", typeOfSport.SportID); return(View(typeOfSport)); }
public ActionResult Edit(PricingPlan pricingPlan) { try { db.Entry(pricingPlan).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (PricingPlan)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes.The pricingplan was deleted by another user."); } else { var databaseValues = (PricingPlan)databaseEntry.ToObject(); if (databaseValues.Title != clientValues.Title) { ModelState.AddModelError("Title", "Current Value:" + databaseValues.Title); } if (databaseValues.Head != clientValues.Head) { ModelState.AddModelError("Head", "Current Value:" + databaseValues.Head); } if (databaseValues.Price != clientValues.Price) { ModelState.AddModelError("Price", "Curent Value:" + string.Format("{0:c}", databaseValues.Price)); } if (databaseValues.Head1 != clientValues.Head1) { ModelState.AddModelError("Head1", "Current Value:" + databaseValues.Head1); } if (databaseValues.Head2 != clientValues.Head2) { ModelState.AddModelError("Head2", "Current Value:" + databaseValues.Head2); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); pricingPlan.RowVersion = databaseValues.RowVersion; } } catch (RetryLimitExceededException) { ModelState.AddModelError(string.Empty, "Unable to save changes. Try again, and if the problem persists contact your system administrator."); } return(View(pricingPlan)); }
public ActionResult Edit([Bind(Include = "HobbyID,Name,TypeOfSportID,ClientID,RowVersion")] Hobby hobby) { try { db.Entry(hobby).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Hobby)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes.The hobby was deleted by another user. "); } else { var databaseValues = (Hobby)databaseEntry.ToObject(); if (databaseValues.TypeOfSportID != clientValues.TypeOfSportID) { ModelState.AddModelError("TypeOfSportID", "Current Value:" + db.TypesOfSports.Find(databaseValues.TypeOfSportID)); } if (databaseValues.ClientID != clientValues.ClientID) { ModelState.AddModelError("ClientID", "Current Value:" + db.Clients.Find(databaseValues.ClientID)); } ModelState.AddModelError(string.Empty, "The record you attempted to edit" + " Was modified by another user after you got the original value." + " The edit operation was cancelled and the current values in the database" + " Have been displayed.If you still want to edit this record" + " Click,the save button again.Otherwise click the back to list hyperlink"); } } catch (RetryLimitExceededException) { ModelState.AddModelError(string.Empty, "Unable to save changes.Try again, and if the problem persists contact your system administrator. "); } ViewBag.ClientID = new SelectList(db.Clients, "ClientID", "ClientID", hobby.ClientID); ViewBag.TypeOfSportID = new SelectList(db.TypesOfSports, "TypeOfSportID", "TypeOfSportID", hobby.TypeOfSportID); return(View(hobby)); }
public async Task <IActionResult> PutWorkoutExcerciseCategories(Guid id, WorkoutExcerciseCategories workoutExcerciseCategories) { if (id != workoutExcerciseCategories.Workout_excercise_categories_id) { return(BadRequest()); } _context.Entry(workoutExcerciseCategories).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkoutExcerciseCategoriesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutPlayer(int id, Player player) { if (id != player.Id) { return(BadRequest()); } _context.Entry(player).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlayerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutTeam([FromRoute] int id, [FromBody] Team team) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != team.Id) { return(BadRequest()); } _context.Entry(team).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeamExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(Enrollment enrollment) { try { db.Entry(enrollment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Enrollment)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes.The Enrollment was deleted by another user."); } else { var databaseValues = (Enrollment)databaseEntry.ToObject(); if (databaseValues.FullName != clientValues.FullName) { ModelState.AddModelError("FullName", "Current Value:" + databaseValues.FullName); } if (databaseValues.Email != clientValues.Email) { ModelState.AddModelError("Email", "Current Value:" + databaseValues.Email); } if (databaseValues.Age != clientValues.Age) { ModelState.AddModelError("Age", "Current Value:" + databaseValues.Age); } if (databaseValues.Grade != clientValues.Grade) { ModelState.AddModelError("Grade", "Current Value:" + databaseValues.Grade); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); enrollment.RowVersion = databaseValues.RowVersion; } } catch (RetryLimitExceededException) { ModelState.AddModelError(string.Empty, "Unable to save changes.Try again ,and if the problem persists contact your system administrator."); } return(View(enrollment)); }
public ActionResult Edit([Bind(Include = "SportsmanID,SurName,Name,BirthDay")] Sportsman sportsman) { if (ModelState.IsValid) { db.Entry(sportsman).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sportsman)); }
public ActionResult Edit(Team team) { if (team.Name != null && team.City != null) { db.Entry(team).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(team)); }
public ActionResult Edit([Bind(Include = "DisciplineID,Name,AgeGroup")] Discipline discipline) { if (ModelState.IsValid) { db.Entry(discipline).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(discipline)); }
public ActionResult Edit([Bind(Include = "Id,Nombre")] Categoria categoria) { if (ModelState.IsValid) { db.Entry(categoria).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categoria)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Number")] Player player) { if (ModelState.IsValid) { db.Entry(player).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(player)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Founded")] Team team) { if (ModelState.IsValid) { db.Entry(team).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(team)); }
public ActionResult Edit([Bind(Include = "Id,Nombre,Descripcion,Precio,CategoriaId,Weight,color,ImgUrl")] Producto producto) { if (ModelState.IsValid) { db.Entry(producto).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoriaId = new SelectList(db.Categorias, "Id", "Nombre", producto.CategoriaId); return(View(producto)); }
public ActionResult Edit([Bind(Include = "DeliveryID,DisciplineID,SportsmanID")] Delivery delivery) { if (ModelState.IsValid) { db.Entry(delivery).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DisciplineID = new SelectList(db.Disciplines, "DisciplineID", "Name", delivery.DisciplineID); ViewBag.SportsmanID = new SelectList(db.Sportsmans, "SportsmanID", "SurName", delivery.SportsmanID); return(View(delivery)); }
public ActionResult Edit(AddAndEditPlayerModel player) { var p = db.Players.Find(player.PlayerId); p.FirstName = player.FirstName; p.LastName = player.LastName; var con = db.Contracts.Select(c => c).Where(c => c.PlayerId == p.PlayerId); db.Contracts.RemoveRange(con); var newCon = player.SelctedTeamIds.Select(idTeam => new Contract { TeamId = idTeam, PlayerId = p.PlayerId }); db.Contracts.AddRange(newCon); db.Entry(p).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task UpdateAsync(TEntity entity) { Context.Entry(entity).State = EntityState.Modified; await Context.SaveChangesAsync(); }