Exemplo n.º 1
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());
                }
            }
        }
Exemplo 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;
        }
Exemplo n.º 3
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());
            }
        }