//protected void Add_Click(object sender, EventArgs e)
        //{
        //    var isValid = Validation(sender, e);
        //    if (isValid)
        //    {
        //        try
        //        {
        //            ProductController sysmgr = new ProductController();
        //            Product item = new Product();
        //            //No ProductID here as the database will give a new one back when we add
        //            item.ProductName = Name.Text.Trim(); //NOT NULL in Database
        //            if (SupplierList.SelectedValue == "0") //NULL in Database
        //            {
        //                item.SupplierID = null;
        //            }
        //            else
        //            {
        //                item.SupplierID = int.Parse(SupplierList.SelectedValue);
        //            }
        //            //CategoryID can be NULL in Database but NOT NULL when record is added in this CRUD page
        //            item.CategoryID = int.Parse(CategoryList.SelectedValue);
        //            //UnitPrice can be NULL in Database but NOT NULL when record is added in this CRUD page
        //            item.UnitPrice = decimal.Parse(UnitPrice.Text);
        //            item.Discontinued = Discontinued.Checked; //NOT NULL in Database
        //            int newID = sysmgr.Add(item);
        //            ID.Text = newID.ToString();
        //            ShowMessage("Record has been ADDED", "alert alert-success");
        //            AddButton.Enabled = false;
        //            UpdateButton.Enabled = true;
        //            DeleteButton.Enabled = true;
        //            Discontinued.Enabled = true;
        //        }
        //        catch (Exception ex)
        //        {
        //            ShowMessage(GetInnerException(ex).ToString(), "alert alert-danger");
        //        }
        //    }
        //}
        protected void Update_Click(object sender, EventArgs e)
        {
            var isValid = Validation(sender, e);

            if (isValid)
            {
                try
                {
                    ProgramsController sysmgr = new ProgramsController();
                    Programs           item   = new Programs();
                    item.ProgramID            = int.Parse(ID.Text);
                    item.ProgramName          = Name.Text.Trim();
                    item.DiplomaName          = Diploma.Text.Trim();
                    item.SchoolCode           = SchoolsList.SelectedValue;
                    item.Tuition              = decimal.Parse(Tuition.Text);
                    item.InternationalTuition = decimal.Parse(IntTuition.Text);

                    int rowsaffected = sysmgr.Update(item);
                    if (rowsaffected > 0)
                    {
                        ShowMessage("Record has been UPDATED", "alert alert-success");
                    }
                    else
                    {
                        ShowMessage("Record was not found", "alert alert-warning");
                    }
                }
                catch (Exception ex)
                {
                    ShowMessage(GetInnerException(ex).ToString(), "alert alert-danger");
                }
            }
        }
        public void ProgramCRUDTest()
        {
            var account    = App.Config.Content.ContentProviders[0].MediaServicesSets[0].MediaServicesAccounts[0];
            var controller = new ProgramsController();
            var context    = account.GetContext();

            var channel      = context.Channels.FirstOrDefault();
            int programCount = context.Programs.Count();
            var name         = string.Format("New-Program-{0}", DateTime.UtcNow.ToOADate().ToString().Replace(".", "-"));

            var settings = new ProgramSettings
            {
                Name                = name,
                Description         = name,
                ArchiveWindowLength = TimeSpan.FromHours(1)
            };

            controller.Create(account.AccountName, channel.Id.NimbusIdToRawGuid(), settings);
            Assert.AreEqual(programCount + 1, context.Programs.Count());

            var program = context.Programs.ToList().First(o => o.Name == name);

            //update the channel.
            var updateSettings = new ProgramUpdateSettings
            {
                Description = "SomeDescription"
            };

            controller.Update(account.AccountName, program.Id.NimbusIdToRawGuid(), updateSettings);

            // create new context to avoid cache issue.
            context = account.GetContext();
            program = context.Programs.Where(p => p.Id == program.Id).FirstOrDefault();
            Assert.IsNotNull(program);

            Assert.AreEqual(updateSettings.Description, program.Description);

            controller.Delete(account.AccountName, program.Id.NimbusIdToRawGuid());
            Assert.AreEqual(programCount, context.Programs.Count());
        }