public void Inserir(string param) { ParceiroFilial filial = new ParceiroFilial(); try { filial = JsonConvert.DeserializeObject <ParceiroFilial>(param); if (!(val.ValidaChaveEstrangeira((int)filial.fkParceiro))) { retorno.erro = true; retorno.response = "202"; } else { db.ParceiroFilial.Add(filial); db.SaveChanges(); retorno.erro = false; retorno.response = "200"; } } catch (Exception ex) { retorno.erro = true; retorno.response = "202"; } Context.Response.Write(retorno); }
public void Alterar(string param) { ParceiroFilial filial = new ParceiroFilial(); // Deserializa o Objeto json filial = JsonConvert.DeserializeObject <ParceiroFilial>(param); try { // Validação de Integridade do Cliente com a Carteira if (filial.fkParceiro > 0 && filial.idFilial > 0) { if (!(val.ValidaChaveEstrangeira((int)filial.fkParceiro))) { retorno.erro = true; retorno.response = "202"; } else { var update = db.ParceiroFilial.Where(m => m.idFilial == filial.idFilial).FirstOrDefault(); update.fkParceiro = filial.fkParceiro; update.desconto = filial.desconto; if (db.SaveChanges() <= 0) { retorno.erro = false; retorno.response = "200"; } } } } catch (DbUpdateException ex) { retorno.erro = true; retorno.response = "202"; } Context.Response.Write(retorno); }