public Plano UpdateByCodigoPlano(Plano plano) { var planoEntity = dataset.Where(p => p.CodigoPlano == plano.CodigoPlano).FirstOrDefault(); if (planoEntity != null) { plano.Id = planoEntity.Id; _context.Entry(planoEntity).CurrentValues.SetValues(plano); foreach (var item in plano.PlanoDDDs) { if (planoEntity.PlanoDDDs.Where(p => p.PlanoId == item.PlanoId && p.DDDId == item.DDDId).FirstOrDefault() == null) { var planoDDD = new PlanoDDD() { DDDId = item.DDDId, PlanoId = planoEntity.Id }; planoEntity.PlanoDDDs.Add(planoDDD); } } _context.SaveChanges(); return(plano); } else { return(new Plano()); } }
public PlanoDDD Insert(PlanoDDD itm) { var sql = @"INSERT INTO PlanoDDD (PlanoId, DDDId) VALUES (@PlanoId, @DDDId)"; Context.ExecuteNonQuery(sql, itm); return(itm); }
public Plano Parse(PlanoVO origem) { if (origem == null) { return(new Plano()); } else { var plano = new Plano() { Id = origem.Id, CodigoPlano = origem.CodigoPlano, FranquiaInternet = origem.FranquiaInternet, Minutos = origem.Minutos, OperadoraId = origem.Operadora.Id, Tipo = origem.Tipo, Valor = origem.Valor }; var listaDDDs = origem.DDDs; var planosDDDs = new List <PlanoDDD>(); foreach (var item in listaDDDs) { var planoDDD = new PlanoDDD() { DDDId = item.Id, PlanoId = origem.Id }; planosDDDs.Add(planoDDD); } plano.PlanoDDDs = planosDDDs; return(plano); } }
public void Delete(PlanoDDD itm) { var sql = "DELETE FROM PlanoDDD WHERE PlanoId = @PlanoId AND DDDId = @DDDId"; Context.ExecuteNonQuery(sql, itm); }
public IEnumerable <PlanoDDD> ListByPlano(PlanoDDD itm) { var sql = @"SELECT PlanoId, DDDId FROM PlanoDDD WHERE PlanoId = @PlanoId"; return(Context.Query <PlanoDDD>(sql, itm)); }