public ScoreEditCommand(ScoreEdit scoreEdit, object collection, object items, int index) { this.collection = collection; this.scoreEdit = scoreEdit; this.index = index; this.items = items; Execute(); }
/// <summary> /// If inserting a note at a different octave /// </summary> /// <param name="scoreEdit"></param> /// <param name="collection"></param> /// <param name="index"></param> /// <param name="itemA"></param> /// <param name="itemB"></param> public ScoreEditCommand(ScoreEdit scoreEdit, object collection, int index, object itemA, object itemB, object itemC) { this.collection = collection; this.scoreEdit = scoreEdit; this.index = index; this.itemA = itemA; this.itemB = itemB; this.itemC = itemC; Execute(); }
public bool UpdateScore(ScoreEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Scores.Single(e => e.ScoreID == model.ScoreID && e.OwnerID == _userId); entity.Hole1 = model.Hole1; entity.ParHole1 = model.ParHole1; entity.Hole2 = model.Hole2; entity.ParHole2 = model.ParHole2; entity.Hole3 = model.Hole3; entity.ParHole3 = model.ParHole3; entity.Hole4 = model.Hole4; entity.ParHole4 = model.ParHole4; entity.Hole5 = model.Hole5; entity.ParHole5 = model.ParHole5; entity.Hole6 = model.Hole6; entity.ParHole6 = model.ParHole6; entity.Hole7 = model.Hole7; entity.ParHole7 = model.ParHole7; entity.Hole8 = model.Hole8; entity.ParHole8 = model.ParHole8; entity.Hole9 = model.Hole9; entity.ParHole9 = model.ParHole9; entity.Hole10 = model.Hole10; entity.ParHole10 = model.ParHole10; entity.Hole11 = model.Hole11; entity.ParHole11 = model.ParHole11; entity.Hole12 = model.Hole12; entity.ParHole12 = model.ParHole12; entity.Hole13 = model.Hole13; entity.ParHole13 = model.ParHole13; entity.Hole14 = model.Hole14; entity.ParHole14 = model.ParHole14; entity.Hole15 = model.Hole15; entity.ParHole15 = model.ParHole15; entity.Hole16 = model.Hole16; entity.ParHole16 = model.ParHole16; entity.Hole17 = model.Hole17; entity.ParHole17 = model.ParHole17; entity.Hole18 = model.Hole18; entity.ParHole18 = model.ParHole18; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateScoreService(); var detail = service.GetScoreByID(id); var model = new ScoreEdit { Hole1 = detail.Hole1, ParHole1 = detail.ParHole1, Hole2 = detail.Hole2, ParHole2 = detail.ParHole2, Hole3 = detail.Hole3, ParHole3 = detail.ParHole3, Hole4 = detail.Hole4, ParHole4 = detail.ParHole4, Hole5 = detail.Hole5, ParHole5 = detail.ParHole5, Hole6 = detail.Hole6, ParHole6 = detail.ParHole6, Hole7 = detail.Hole7, ParHole7 = detail.ParHole7, Hole8 = detail.Hole8, ParHole8 = detail.ParHole8, Hole9 = detail.Hole9, ParHole9 = detail.ParHole9, Hole10 = detail.Hole10, ParHole10 = detail.ParHole10, Hole11 = detail.Hole11, ParHole11 = detail.ParHole11, Hole12 = detail.Hole12, ParHole12 = detail.ParHole12, Hole13 = detail.Hole13, ParHole13 = detail.ParHole13, Hole14 = detail.Hole14, ParHole14 = detail.ParHole14, Hole15 = detail.Hole15, ParHole15 = detail.ParHole15, Hole16 = detail.Hole16, ParHole16 = detail.ParHole16, Hole17 = detail.Hole17, ParHole17 = detail.ParHole17, Hole18 = detail.Hole18, ParHole18 = detail.ParHole18 }; return(View(model)); }
public ActionResult Edit(int id, ScoreEdit model) { if (!ModelState.IsValid) { return(View(model)); } //if (model.ScoreID != id) //{ // ModelState.AddModelError("", "ID Mismatch!"); // return View(model); //} var service = CreateScoreService(); if (service.UpdateScore(model)) { TempData["SaveResult"] = "Your course was updated!"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your course could not be updated."); return(View(model)); }
// execute public void Execute() { if (scoreEdit == ScoreEdit.EraseNote) { scoreEdit = ScoreEdit.InsertNote; try { ((List <object>)collection).Remove((Note)itemB); } catch { if (itemA != null) { ((List <SPCCommand>)collection).Remove((SPCCommand)itemA); } ((List <SPCCommand>)collection).Remove((SPCCommand)itemB); if (itemC != null) { ((List <SPCCommand>)collection).Remove((SPCCommand)itemC); } } } else if (scoreEdit == ScoreEdit.InsertNote) { scoreEdit = ScoreEdit.EraseNote; try { ((List <object>)collection).Insert(index, (Note)itemB); } catch { if (itemC != null) { ((List <SPCCommand>)collection).Insert(index, (SPCCommand)itemC); } ((List <SPCCommand>)collection).Insert(index, (SPCCommand)itemB); if (itemA != null) { ((List <SPCCommand>)collection).Insert(index, (SPCCommand)itemA); } } } else if (scoreEdit == ScoreEdit.PasteNotes) { scoreEdit = ScoreEdit.DeleteNotes; try { ((List <object>)collection).InsertRange(index, (List <object>)items); } catch { ((List <SPCCommand>)collection).InsertRange(index, (List <SPCCommand>)items); } } else if (scoreEdit == ScoreEdit.DeleteNotes) { scoreEdit = ScoreEdit.PasteNotes; try { ((List <object>)collection).RemoveRange(index, ((List <object>)items).Count); } catch { ((List <SPCCommand>)collection).RemoveRange(index, ((List <SPCCommand>)items).Count); } } else if (scoreEdit == ScoreEdit.AddStaff) { scoreEdit = ScoreEdit.DeleteStaff; ((List <Staff>)collection).Insert(index, (Staff)itemB); } else if (scoreEdit == ScoreEdit.DeleteStaff) { scoreEdit = ScoreEdit.AddStaff; ((List <Staff>)collection).Remove((Staff)itemB); } }