public async Task <ContratoResponse> GraboContrato(Cvmcth contrato, string tipoOperacion) { oCvmcth.instancioObjeto(tipoOperacion); Type typeContrato = contrato.GetType(); System.Reflection.PropertyInfo[] listaPropiedades = typeContrato.GetProperties(); foreach (System.Reflection.PropertyInfo propiedad in listaPropiedades) { if (propiedad.PropertyType == typeof(ICollection <Cvmcti>)) { oCvmcth.limpioGrilla("CVMCTI01"); foreach (Cvmcti item in contrato.Items) { oCvmcth.asignoaTM("CVMCTI01", "", item, 2, Logger); } } else { oCvmcth.asignoaTM("CVMCTH01", propiedad.Name, propiedad.GetValue(contrato, null), 1, Logger); } } Save PerformedOperation = oCvmcth.save(); bool result = PerformedOperation.Result; string mensajeError = PerformedOperation.errorMessage; oCvmcth.closeObjectInstance(); if (result == false) { return(new ContratoResponse("Bad Request", 0, mensajeError)); } return(new ContratoResponse("OK", 0, null, "Contrato generado")); }
public async Task <ContratoResponse> ActualizoContrato(Cvmcth contrato) { Cvmcth contratoAActualizar = await Context.Cvmcth .FindAsync(new object[] { contrato.Cvmcth_Codcon, contrato.Cvmcth_Nrocon, contrato.Cvmcth_Nroext }); if (contratoAActualizar == null) { return(new ContratoResponse("Not Found", 0, $"El contrato no existe")); } Type typeContrato = contrato.GetType(); System.Reflection.PropertyInfo[] listaPropiedades = typeContrato.GetProperties(); foreach (System.Reflection.PropertyInfo propiedad in listaPropiedades) { var value = propiedad.GetValue(contrato, null); if (propiedad.PropertyType == typeof(string)) { if ((string)value != "null" && (string)value != "NULL" && value != null && propiedad.Name != "Cvmcth_Codcon" && propiedad.Name != "Cvmcth_Nrocon" && propiedad.Name != "Cvmcth_Nroext" && propiedad.Name != "Items") { switch (propiedad.Name) { case "Cvmcth_Desfre": short valorAAsignar = 0; switch (value) { case "A": valorAAsignar = 360; break; case "M": valorAAsignar = 30; break; case "B": valorAAsignar = 60; break; case "T": valorAAsignar = 40; break; case "C": valorAAsignar = 30; break; case "S": valorAAsignar = 180; break; default: break; } contratoAActualizar.Cvmcth_Frefac = valorAAsignar; break; case "Cvmcth_Nrocta": case "Cvmcth_Nrosub": string codigoCliente = propiedad.Name == "Cvmcth_Nrocta" ? contrato.Cvmcth_Nrocta : contrato.Cvmcth_Nrosub; bool ExisteCliente = await ValidoVTMCLH(codigoCliente); if (ExisteCliente == false) { return(new ContratoResponse("Bad Request", 0, $"El codigo {codigoCliente} no se encuentra creado como cliente.")); } typeContrato.InvokeMember(propiedad.Name, BindingFlags.SetProperty, null, contratoAActualizar, new object[] { value }); break; case "Cvmcth_Codcvt": bool ExisteComprobante = await ValidoGRCCBH(contrato); if (ExisteComprobante == false) { return(new ContratoResponse("Bad Request", 0, $"El comprobante de ventas {contrato.Cvmcth_Codcvt} no existe.")); } typeContrato.InvokeMember(propiedad.Name, BindingFlags.SetProperty, null, contratoAActualizar, new object[] { value }); break; default: typeContrato.InvokeMember(propiedad.Name, BindingFlags.SetProperty, null, contratoAActualizar, new object[] { value }); break; } } } } contratoAActualizar.Cvmcth_Fecmod = DateTime.Now; contratoAActualizar.Cvmcth_Ultopr = "M"; contratoAActualizar.Cvmcth_Userid = "API"; try { await Context.SaveChangesAsync(); } catch (Exception e) { return(new ContratoResponse("Bad Request", 0, e.InnerException.Message)); } foreach (Cvmcti items in contrato.Items) { items.Cvmcti_Codcon = contrato.Cvmcth_Codcon; items.Cvmcti_Nrocon = contrato.Cvmcth_Nrocon; items.Cvmcti_Nroext = contrato.Cvmcth_Nroext; ContratoResponse response = await this.actualizoItem(items, contrato); if (response.Estado != 200) { return(response); } } return(new ContratoResponse("OK", 0, null, "Contrato actualizado")); }