public void DeletarTreino() { try { using (var db = new VitaClubContext()) { DivisaoTreino.DeletarDivisaoTreino(this.Id); db.Treinos.Attach(this.TreinoDO); db.Entry(this.TreinoDO).State = EntityState.Deleted; db.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public void Update() { try { using (var db = new VitaClubContext()) { var entity = db.Treinos.Find(this.Id); if (entity != null) { db.Entry(entity).CurrentValues.SetValues(this.TreinoDO); db.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public static void DeletarExercicioTreino(int divisaoId, int sequencia) { try { using (var db = new VitaClubContext()) { var delExercicio = db.ExerciciosTreino.Where(a => a.DivisaoId == divisaoId && a.DivisaoSeq == sequencia).ToList(); foreach (var item in delExercicio) { db.ExerciciosTreino.Attach(item); db.Entry(item).State = EntityState.Deleted; } db.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public static void DeletarDivisaoTreino(int treinoId) { try { using (var db = new VitaClubContext()) { var delDivisao = db.DivisoesTreino.Where(a => a.TreinoId == treinoId).ToList(); foreach (var item in delDivisao) { ExercicioTreino.DeletarExercicioTreino((int)item.TreinoId, (int)item.Sequencia); db.DivisoesTreino.Attach(item); db.Entry(item).State = EntityState.Deleted; } db.SaveChanges(); } } catch (Exception ex) { throw ex; } }