public async Task <IActionResult> PutCoaches(int id, Coaches coaches) { if (id != coaches.Coaches_Id) { return(BadRequest()); } _context.Entry(coaches).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CoachesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Add() { isAdding = true; CoachDisplayModel e = Coaches.Where(x => x.FirstName == FirstName && x.LastName == LastName).FirstOrDefault(); if (e == null) { SqlDataAccess sql = new SqlDataAccess(); sql.SaveData <dynamic>("dbo.spCoach_Insert", new { FirstName = _firstName, LastName = _lastName, Phone = _phone, Email = _email }, "ADBData"); Coaches = new BindingList <CoachDisplayModel>(GetAllCoaches()); NotifyOfPropertyChange(() => Coaches); Clear(); _events.PublishOnUIThread(new CoachChangedEvent()); } else { msg = $"Error: An Coach named ({SelectedCoach.FullName}) already exist!!!"; MessageBox.Show(msg, "Error"); } isAdding = false; }
public async Task <ActionResult <Coaches> > PostCoaches(Coaches coaches) { _context.Coaches.Add(coaches); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCoaches", new { id = coaches.Coaches_Id }, coaches)); }
public async Task <IActionResult> Edit(int id, [Bind("CoachID,Availability,ContactNumber,FirstName,GardaVetExpDate,LastName")] Coaches coaches) { if (id != coaches.CoachID) { return(NotFound()); } if (ModelState.IsValid) { try { // Query the database with values of drop down lists to get the text // Get the day name and assign to coach int dayId = Convert.ToInt32(coaches.Availability); var day = _context.Days.Where(d => d.DayID == dayId).First(); coaches.Availability = day.DayName; _context.Update(coaches); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CoachesExists(coaches.CoachID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(coaches)); }
private decimal PercentNumberOfSeatsBooked(int nbSeat) { decimal numberOfSeatsBooked = Coaches.Select(c => c.NumberOfSeatsBooked).Sum(); decimal numberOfSeats = Coaches.Select(c => c.NumberOfSeats).Sum(); return(((numberOfSeatsBooked + nbSeat) / numberOfSeats) * 100); }
internal void DeleteCoach() { if (Coach.Delete()) { Coaches.Remove(Coach); } }
public void Update() { CoachDisplayModel exists = Coaches.Where(x => x.Id == SelectedCoach.Id).FirstOrDefault(); if (exists != null) { if (SelectedCoach != null && Coaches.Count > 0) { isUpdating = true; CoachModel e = new CoachModel { Id = SelectedCoach.Id, FirstName = _firstName, LastName = _lastName, Phone = _phone, Email = _email }; SqlDataAccess sql = new SqlDataAccess(); sql.UpdateData <CoachModel>("dbo.spCoach_Update", e, "ADBData"); msg = $"Coach ({SelectedCoach.FullName}) was successfully updated."; MessageBox.Show(msg, "Coach Updated"); Coaches = new BindingList <CoachDisplayModel>(GetAllCoaches()); Clear(); isUpdating = false; _events.PublishOnUIThread(new CoachChangedEvent()); } } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Team")] Coaches coaches) { if (id != coaches.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(coaches); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CoachesExists(coaches.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(coaches)); }
public void GetCoachByName() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "GetCoachByNameDB") .Options; var data = new List <Coaches>() { new Coaches { Id = 1, Name = "Coach1" }, new Coaches { Id = 2, Name = "Coach2" }, new Coaches { Id = 3, Name = "Coach3" }, }.AsQueryable(); using (OlympicGamesDBContext context = new OlympicGamesDBContext(options)) { CoachesBusiness business = new CoachesBusiness(context); data.ToList().ForEach(c => business.AddCoach(c)); Coaches c = business.GetCoachByName("Coach1"); Assert.AreEqual("Coach1", c.Name); } }
public async Task <IActionResult> Edit(int id, [Bind("Coaches_Id,FirstName,LastName,Title,Team_Id")] Coaches coaches) { if (id != coaches.Coaches_Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(coaches); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CoachesExists(coaches.Coaches_Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Team_Id"] = new SelectList(_context.Set <Teams>(), "Team_Id", "Team_Name"); return(View(coaches)); }
public ActionResult DeleteConfirmed(int id) { Coaches coaches = db.Coaches.Include(nameof(User)).ToList().Find(c => c.Id == id); db.Coaches.Remove(coaches); db.SaveChanges(); return(RedirectToAction("Index")); }
private void PrintCoach(Coaches coach, Sports sport) { Console.WriteLine(new string('-', 40)); Console.WriteLine($"ID: {coach.Id}"); Console.WriteLine($"Name: {coach.Name}"); Console.WriteLine($"Sport Name: {sport.Name}"); Console.WriteLine(new string('-', 40)); }
public ActionResult Edit(Coaches coaches) //в форму добавл. скрыт. поля model.UserId + model.User.Id { if (ModelState.IsValid) { db.Entry(coaches).State = EntityState.Modified; //здесь coaches.UserId == coaches.User.Id db.SaveChanges(); return(RedirectToAction("Index")); } return(View(coaches)); }
/// <summary> /// Updates a coach in the database. /// </summary> /// <param name="coach">The coach that is being updated.</param> public void UpdateCoach(Coaches coach) { var item = olympicGamesDBContext.Coaches.Find(coach.Id); if (item != null) { olympicGamesDBContext.Entry(item).CurrentValues.SetValues(coach); olympicGamesDBContext.SaveChanges(); } }
public async Task <IActionResult> Create([Bind("Id,Name,Team")] Coaches coaches) { if (ModelState.IsValid) { _context.Add(coaches); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(coaches)); }
private Coach SelectAvailableCoach(int nbSeat) { var availableCoach = Coaches.FirstOrDefault(c => c.HasSeatAvailable(nbSeat)) ?? Coaches.FirstOrDefault(c => !c.TotallyFull(nbSeat) ); if (availableCoach == null) { throw new ApplicationException("No coach has the enough seat "); } return(availableCoach); }
public async Task <IActionResult> Create([Bind("Coaches_Id,FirstName,LastName,Title,Team_Id")] Coaches coaches) { if (ModelState.IsValid) { _context.Add(coaches); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Team_Id"] = new SelectList(_context.Set <Teams>(), "Team_Id", "Team_Name"); return(View(coaches)); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Coaches coaches = db.Coaches.Include(nameof(User)).ToList().Find(c => c.Id == id); if (coaches == null) { return(HttpNotFound()); } return(View(coaches)); }
/// <summary> /// Makes the user to input data about the coach. /// Passes the information to CoachesBusinessiness, using the method "AddCoach" /// </summary> public void AddCoach() { var coach = new Coaches(); Console.Write("Enter Coach Name: "); coach.Name = Console.ReadLine(); Console.Write("Enter Sport Name: "); string sportName = Console.ReadLine(); coach.SportId = sportsBusiness.GetSportByName(sportName).Id; coachesBusiness.AddCoach(coach); Console.WriteLine($"New coach successfully added!"); }
internal bool AddCoach() { bool res = false; if ((Coach.CC != 0)) { if (Coach.Create()) { Coaches.Add(Coach); res = true; } } return(res); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.SpecList = new SelectList(db.Specializations.ToList(), "Id", "Title"); Coaches coaches = db.Coaches.Include(nameof(User)).ToList().Find(c => c.Id == id); if (coaches == null) { return(HttpNotFound()); } return(View(coaches)); }
//Removing coach form list and Listbox private void btnRemove_Click(object sender, EventArgs e) { sog.UpdateDelete(); try { Coaches.RemoveAt(lbCoaches.SelectedIndex); lbCoaches.Items.Remove(lbCoaches.SelectedItem); lbCoaches.SelectedIndex = 0; lblInfo.Text = ""; DefaultValues(); } catch { } }
public async Task <IActionResult> Create([Bind("CoachID,Availability,ContactNumber,FirstName,GardaVetExpDate,LastName")] Coaches coaches) { if (ModelState.IsValid) { // Query the database with values of drop down lists to get the text // Get the day name and assign to coach int dayId = Convert.ToInt32(coaches.Availability); var day = _context.Days.Where(d => d.DayID == dayId).First(); coaches.Availability = day.DayName; _context.Add(coaches); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(coaches)); }
public bool CreateCoach(CoachCreate model) { var entity = new Coaches { FirstName = model.FirstName, LastName = model.LastName, PositionCoach = model.PositionCoach, }; using (var ctx = new ApplicationDbContext()) { ctx.Coaches.Add(entity); return(ctx.SaveChanges() == 1); } }
public void Delete() { CoachDisplayModel e = Coaches.Where(x => x.Id == SelectedCoach.Id).FirstOrDefault(); if (e != null) { SqlDataAccess sql = new SqlDataAccess(); sql.DeleteData <dynamic>("dbo.spCoach_Delete", new { Id = SelectedCoach.Id }, "ADBData"); Coaches = new BindingList <CoachDisplayModel>(GetAllCoaches()); SelectedCoach = null; Clear(); _events.PublishOnUIThread(new CoachChangedEvent()); } }
public async void EditWrongIdTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new CoachesController(db); var coach = new Coaches { Coaches_Id = 2, FirstName = "Edwin", LastName = "Mar", Title = "Head", Team_Id = 2 }; //Act await c.Create(coach); var r = await c.Edit(db.Coaches.Find(1).Coaches_Id, coach); //Assert Assert.IsType <NotFoundResult>(r); }
public async void CreateButtonTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new CoachesController(db); var coach = new Coaches { Coaches_Id = 2, FirstName = "Edwin", LastName = "Mar", Title = "Head", Team_Id = 2 }; //Act await c.Create(coach); var r = c.Create(); //Assert Assert.IsType <ViewResult>(r); }
public ActionResult Create(Coaches coaches) { if (coaches == null) { return(HttpNotFound()); } if (coaches.UserId == 0) { return(new HttpNotFoundResult("User is null!")); } if (ModelState.IsValid) { db.Coaches.Add(coaches); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(coaches)); }
public async void TestAddCoach() { //Arrange var db = MockDb.CreateMockDb(); var c = new CoachesController(db); var coach = new Coaches { Coaches_Id = 2, FirstName = "Mike", LastName = "Mar", Title = "Head", Team_Id = 2 }; //Act var r = await c.Create(coach); //Assert var result = Assert.IsType <RedirectToActionResult>(r); Assert.Equal("Index", result.ActionName); Assert.Equal(1, db.Coaches.Where(x => x.Coaches_Id == coach.Coaches_Id && x.FirstName == coach.FirstName && x.LastName == coach.LastName && x.Title == coach.Title && x.Team_Id == coach.Team_Id).Count()); }
public async void DeleteConfirmTest() { //Arrange var db = MockDb.CreateMockDb(); var c = new CoachesController(db); var coach = new Coaches { Coaches_Id = 2, LastName = "Mar", Title = "Head", Team_Id = 2 }; //Act var r = await c.Create(coach); //Finds the second element stores in a tmp variable var elementToDelete = db.Coaches.Find(2); await c.DeleteConfirmed(elementToDelete.Coaches_Id); Assert.DoesNotContain(elementToDelete, db.Coaches); }