public ActionResult Create([Bind(Include = "FootballersID,kitnumber,club,position,nationality,name,Password,ConfirmPassword,username")] Footballers footballers) { if (ModelState.IsValid) { // before saving to databse // need to hash password // add confirm password // make username unique var HashedPassword = Crypto.HashPassword(footballers.Password); footballers.Password = HashedPassword; footballers.ConfirmPassword = HashedPassword; db.Footballers.Add(footballers); db.SaveChanges(); //catch (DbEntityValidationException dbEx) //{ // foreach (var validationErrors in dbEx.EntityValidationErrors) // { // foreach (var validationError in validationErrors.ValidationErrors) // { // Trace.TraceInformation("Property: {0} Error: {1}", // validationError.PropertyName, // validationError.ErrorMessage); // } // } //} return(RedirectToAction("Index")); } return(View(footballers)); }
public string SaveItem(string footBaller) { string result = ""; try { Footballers footballers = JsonConvert.DeserializeObject <Footballers>(footBaller); if (footballers.Id == 0) { FC.Add(footballers); FC.SaveChanges(); result = JsonConvert.SerializeObject(new { status = "OK" }); } else { FC.Entry(footballers).State = Microsoft.EntityFrameworkCore.EntityState.Modified; FC.SaveChanges(); result = JsonConvert.SerializeObject(new { status = "OK" }); } } catch (Exception ex) { result = JsonConvert.SerializeObject(new { status = "Error", Error = ex.ToString() }); } return(result); }
public ActionResult DeleteConfirmed(int id) { Footballers footballers = db.Footballers.Find(id); db.Footballers.Remove(footballers); db.SaveChanges(); return(RedirectToAction("Index")); }
public void IntByParamsIncializeCorrectData() { Footballers footballers = new Footballers( new Footballer("Footballer0", FootballClub.None, 0), new Footballer("Footballer1", FootballClub.None, 0)); Assert.AreEqual(2, footballers.Count); }
public void TryAccessToFootballerOnIllegallPositionThrowException() { Footballers footballers = new Footballers(); Assert.Throws <IndexOutOfRangeException>(() => { Footballer temp = footballers[0]; }); }
public void AfterInsertFootballersHadCorrectOrder() { Footballers footballers = GetFilledFootballersToCapacity(); for (uint i = 0; i < footballers.Count; i++) { Assert.AreEqual(new Footballer($"footballer{i.ToString()}", FootballClub.None, 0), footballers[i]); } }
public Footballers UpdatePlayers(Footballers footballers) { using (var fteamDb = new FteamDbContext()) { fteamDb.players.Update(footballers); fteamDb.SaveChanges(); return(footballers); } }
public void TrySetFootballerOnIllegallPositionThrowException() { Footballers footballers = new Footballers(); Assert.Throws <IndexOutOfRangeException>(() => { footballers[0] = null; }); }
public ActionResult Edit([Bind(Include = "FootballersID,kitnumber,club,position,nationality,name,Password")] Footballers footballers) { if (ModelState.IsValid) { db.Entry(footballers).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(footballers)); }
public IHttpActionResult PostFootballers(Footballers footballers) { if (ModelState.IsValid) { repo.PostFootballers(footballers); } var returnables = _factory.CreateFootballerDTO(footballers); return(CreatedAtRoute("DefaultApi", new { id = footballers.FootballersID }, returnables)); }
public Footballers GetFootballers(int id) { Footballers footballer = db.Footballers.Find(id); if (footballer != null) { return(footballer); } return(null); }
private Footballers GetFilledFootballersToCapacity() { Footballers footballers = new Footballers(); for (uint i = 0; i < Footballers.FOOTBALLERS_CAPACITY; i++) { footballers.Add(new Footballer($"footballer{i.ToString()}", FootballClub.None, 0)); Assert.IsTrue(footballers.Count == i + 1); } return(footballers); }
public FootballerDTO CreateFootballerDTO(Footballers footballers) { FootballerDTO _footDto = new FootballerDTO { name = footballers.name, club = footballers.club, footballfans = footballers.fans }; return(_footDto); }
// GET: FootballersMVC/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Footballers footballers = db.Footballers.Find(id); if (footballers == null) { return(HttpNotFound()); } return(View(footballers)); }
public IHttpActionResult PutFootballers(int id, Footballers footballers) { if (ModelState.IsValid && (id == footballers.FootballersID)) { repo.Put(footballers); var returnItems = _factory.CreateFootballerDTO(footballers); return(CreatedAtRoute("DefaultApi", new { id = footballers.FootballersID }, returnItems)); } else { return(BadRequest()); } }
//Delete public bool Delete(int id) { Footballers footballer = db.Footballers.Find(id); if (footballer != null) { db.Footballers.Remove(footballer); db.SaveChanges(); return(true); } else { return(false); } }
public void AfterRemoveFootballersHadCorrectOrder(uint index) { Footballers footballers = GetFilledFootballersToCapacity(); uint previousCount = footballers.Count; Footballer removedFootballer = footballers[index]; string expectedNextFootballerName = $"footballer{(index + 1).ToString()}"; footballers.Remove(index); Assert.AreEqual(previousCount - 1, footballers.Count); if (index == footballers.Count) { return; } Assert.AreNotEqual(removedFootballer, footballers[index]); Assert.AreEqual(footballers[index].Name, expectedNextFootballerName); }
public IActionResult Item(int?Id) { Footballers footBallers = FC.Footballers.Where(f => f.Id == Id).FirstOrDefault(); ViewBag.Teams = JsonConvert.SerializeObject(FC.Footballers.Select(s => s.NameTeam).ToList()); if (Id != null) { ViewBag.TypePage = "Edit"; } else if (Id == null) { ViewBag.TypePage = "New"; } return(View(footBallers)); }
public void InitByArrayInicializeCorrectData() { Footballer[] footballersSource = new Footballer[5] { new Footballer("Footballer0", FootballClub.None, 0), new Footballer("Footballer1", FootballClub.None, 0), new Footballer("Footballer2", FootballClub.None, 0), new Footballer("Footballer3", FootballClub.None, 0), new Footballer("Footballer4", FootballClub.None, 0), }; Footballers footballers = new Footballers(footballersSource); Assert.AreEqual(footballersSource.Length, footballers.Count); for (uint i = 0; i < footballers.Count; i++) { Assert.AreEqual(footballersSource[i], footballers[i]); } }
public ActionResult SignIn(Footballers footballers) { try { Footballers userIndatabase = db.Footballers.Where(u => u.username == footballers.username).FirstOrDefault(); bool verify = Crypto.VerifyHashedPassword(userIndatabase.Password, footballers.Password); if (verify) { FormsAuthentication.SetAuthCookie(footballers.username, false); Session["userId"] = userIndatabase.FootballersID; // return View("partialshared"); return(RedirectToAction("Index", "Home")); } } catch { return(RedirectToAction("SignIn")); } return(RedirectToAction("Index", "Home")); }
public void RemoveFootballerFromEmptyFootballersThrowException() { Footballers footballers = new Footballers(); Assert.Throws <ArgumentOutOfRangeException>(() => footballers.Remove(0)); }
public ChampionsLeagueForm() { footballers = new Footballers(); InitializeComponent(); RefillFootballersView(); }
//Put public void Put(Footballers footballers) { db.Entry(footballers).State = EntityState.Modified; db.SaveChanges(); }
public void PostFootballers(Footballers footballers) { db.Footballers.Add(footballers); db.SaveChanges(); }
public void TryRemoveFootballerOnIlegallPositionThrowException() { Footballers footballers = GetFilledFootballersToCapacity(); Assert.Throws <IndexOutOfRangeException>(() => footballers.Remove(Footballers.FOOTBALLERS_CAPACITY)); }
public void InitFootballersAreEmpty() { Footballers footballers = new Footballers(); Assert.IsTrue(footballers.Count == 0); }
public void InsertUnderFootballerCapacityThrowException() { Footballers footballers = GetFilledFootballersToCapacity(); Assert.Throws <ArgumentOutOfRangeException>(() => footballers.Add(new Footballer("Under capacity", FootballClub.None, 0))); }
public Footballers UpdatePlayers(Footballers footballers) { return(_footballTeamRepository.UpdatePlayers(footballers)); }
public Footballers Put([FromBody] Footballers footballers) { return(_footballTeamService.UpdatePlayers(footballers)); }