private void BtnRemovePiece_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (cboPerformance.SelectedItem != null && dgvPerformancePieces.SelectedItem != null)
                {
                    int index           = cboPerformance.SelectedIndex;
                    PerformancePiece pp = performances[index].PerfromancePieces[dgvPerformancePieces.SelectedIndex];

                    //Call the API if the selected item isn't null to delete it and its related PieceWriters and PieceGenres
                    HttpClient          client   = InitializeClient();
                    HttpResponseMessage response = new HttpResponseMessage();


                    response = client.DeleteAsync("PerformancePiece/" + pp.Id).Result;
                    performances[index].PerfromancePieces.Remove(pp);

                    Rebind();
                    cboPerformance.SelectedIndex = index;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("PerformancePieceId,PerformanceId,PieceId")] PerformancePiece performancePiece)
        {
            if (id != performancePiece.PerformancePieceId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(performancePiece);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PerformancePieceExists(performancePiece.PerformancePieceId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PerformanceId"] = new SelectList(_context.Performance, "PerformanceId", "PerformanceId", performancePiece.PerformanceId);
            ViewData["PieceId"]       = new SelectList(_context.Piece, "PieceId", "PieceId", performancePiece.PieceId);
            return(View(performancePiece));
        }
        // GET: api/PerformancePiece/5
        public PerformancePiece Get(Guid id)
        {
            PerformancePiece performancePiece = new PerformancePiece {
                Id = id
            };

            performancePiece.LoadById();
            return(performancePiece);
        }
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (btnSubmit.Content.ToString() == "Submit")
                {
                    PerformancePiece performancePiece = new PerformancePiece();

                    if (cboPiece.SelectedItem != null)
                    {
                        performancePiece.DirectorId = directors[cboDirector.SelectedIndex].Id;
                    }

                    performancePiece.PieceId       = pieces[cboPiece.SelectedIndex].Id;
                    performancePiece.GroupId       = groups[cboGroup.SelectedIndex].Id;
                    performancePiece.PerformanceId = PerformanceId;
                    performancePiece.Notes         = txtNotes.Text;

                    //Send it to the API
                    HttpClient client = InitializeClient();
                    string     serializedPerformancePiece = JsonConvert.SerializeObject(performancePiece);
                    var        content = new StringContent(serializedPerformancePiece);
                    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    HttpResponseMessage response = client.PostAsync("PerformancePiece", content).Result;

                    this.Close();
                }
                else
                {
                    if (cboPiece.SelectedItem != null)
                    {
                        performancePiece.DirectorId = directors[cboDirector.SelectedIndex].Id;
                    }

                    performancePiece.PieceId       = pieces[cboPiece.SelectedIndex].Id;
                    performancePiece.GroupId       = groups[cboGroup.SelectedIndex].Id;
                    performancePiece.PerformanceId = PerformanceId;
                    performancePiece.Notes         = txtNotes.Text;

                    //Send it to the API
                    HttpClient client = InitializeClient();
                    string     serializedPerformancePiece = JsonConvert.SerializeObject(performancePiece);
                    var        content = new StringContent(serializedPerformancePiece);
                    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    HttpResponseMessage response = client.PutAsync("PerformancePiece/" + performancePiece.Id, content).Result;

                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Create(PerformancePiece performancePiece)
        {
            Piece piece = await _context.Piece.FindAsync(performancePiece.PieceId);

            piece.LastPerformedDate = DateTime.Now;
            _context.Update(piece);
            await _context.SaveChangesAsync();

            _context.Add(performancePiece);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Performances"));
        }
        public void LoadById()
        {
            //Load up Guids
            PieceList pieces = new PieceList();
            Piece     piece  = new Piece();

            pieces.Load();
            piece = pieces.FirstOrDefault(p => p.Name == "Rock Music");

            GroupList groups = new GroupList();
            Group     group  = new Group();

            groups.Load();
            group = groups.FirstOrDefault(c => c.Name == "Jazz Ensemble");

            PerformanceList performances = new PerformanceList();
            Performance     performance  = new Performance();

            performances.Load();
            performance = performances.FirstOrDefault(c => c.Name == "Dream Concert");

            DirectorList directors = new DirectorList();
            Director     director  = new Director();

            directors.Load();
            director = directors.FirstOrDefault(c => c.FirstName == "Eric");

            PerformancePiece     performancePiece  = new PerformancePiece();
            PerformancePieceList performancePieces = new PerformancePieceList();

            performancePieces.Load();
            performancePiece         = performancePieces.FirstOrDefault(p => p.GroupId == group.Id && p.PieceId == piece.Id && p.PerformanceId == performance.Id);
            performancePiece.Notes   = "BL Test";
            performancePiece.MP3Path = "BL Test";

            PerformancePiece newperformancePiece = new PerformancePiece {
                Id = performancePiece.Id
            };

            newperformancePiece.LoadById();

            Assert.AreEqual(performancePiece.DirectorId, newperformancePiece.DirectorId);
        }
        public void UpdateTest()
        {
            //Load up Guids
            PieceList pieces = new PieceList();
            Piece     piece  = new Piece();

            pieces.Load();
            piece = pieces.FirstOrDefault(p => p.Name == "Rock Music");

            GroupList groups = new GroupList();
            Group     group  = new Group();

            groups.Load();
            group = groups.FirstOrDefault(c => c.Name == "Jazz Ensemble");

            PerformanceList performances = new PerformanceList();
            Performance     performance  = new Performance();

            performances.Load();
            performance = performances.FirstOrDefault(c => c.Name == "Dream Concert");

            DirectorList directors = new DirectorList();
            Director     director  = new Director();

            directors.Load();
            director = directors.FirstOrDefault(c => c.FirstName == "Eric");

            PerformancePiece     performancePiece  = new PerformancePiece();
            PerformancePieceList performancePieces = new PerformancePieceList();

            performancePieces.Load();
            performancePiece         = performancePieces.FirstOrDefault(p => p.GroupId == group.Id && p.PieceId == piece.Id && p.PerformanceId == performance.Id);
            performancePiece.Notes   = "BL Test";
            performancePiece.MP3Path = "BL Test";

            performancePiece.DirectorId = director.Id;
            int results = performancePiece.Update();

            Assert.IsTrue(results == 1);
        }
        public ManagePerformancePiece(Guid performanceId, string performanceName, PerformancePiece pp)
        {
            InitializeComponent();
            pieces    = new PieceList();
            groups    = new GroupList();
            directors = new DirectorList();

            PerformanceId   = performanceId;
            PerformanceName = performanceName;

            Load();
            Rebind();

            lblPerformance.Content = PerformanceName;

            performancePiece          = pp;
            cboDirector.SelectedValue = pp.DirectorId;
            cboGroup.SelectedValue    = pp.GroupId;
            cboPiece.SelectedValue    = pp.PieceId;
            txtNotes.Text             = pp.Notes;

            btnSubmit.Content = "Update";
        }
 // Put: api/PerformancePiece
 public void Put(Guid id, PerformancePiece performancePiece)
 {
     performancePiece.Update();
 }
 // POST: api/PerformancePiece
 public void Post(PerformancePiece performancePiece)
 {
     performancePiece.Insert();
 }