Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        public async Task <ActionResult <Coaches> > PostCoaches(Coaches coaches)
        {
            _context.Coaches.Add(coaches);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCoaches", new { id = coaches.Coaches_Id }, coaches));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 6
0
 internal void DeleteCoach()
 {
     if (Coach.Delete())
     {
         Coaches.Remove(Coach);
     }
 }
Esempio n. 7
0
        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));
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        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"));
        }
Esempio n. 12
0
 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));
 }
Esempio n. 13
0
 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));
 }
Esempio n. 14
0
        /// <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));
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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));
        }
Esempio n. 18
0
        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));
        }
Esempio n. 19
0
        /// <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!");
        }
Esempio n. 20
0
        internal bool AddCoach()
        {
            bool res = false;

            if ((Coach.CC != 0))
            {
                if (Coach.Create())
                {
                    Coaches.Add(Coach);
                    res = true;
                }
            }
            return(res);
        }
Esempio n. 21
0
        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
     {
     }
 }
Esempio n. 23
0
        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);
            }
        }
Esempio n. 25
0
        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());
            }
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        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));
        }
Esempio n. 29
0
        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());
        }
Esempio n. 30
0
        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);
        }