public ValidarDatosApuesta(ApuestaSolicitud apuestaAEvaluar)
        {
            this.ApuestaAEvaluar = apuestaAEvaluar;
            if (!this.ValidarId(apuestaAEvaluar.ClienteId))
            {
                throw new ApuestaException(Mensajes.Apuesta_ClienteInválido);
            }

            if (!this.ValidarId(apuestaAEvaluar.RuletaId))
            {
                throw new ApuestaException(Mensajes.Ruleta_IdInválido);
            }

            var esValidaLaSeleccion = apuestaAEvaluar.ColorApuesta == Color.NoAsignado ? this.ValidarNumeroSeleccionado(apuestaAEvaluar.NumeroApuesta) : true;

            if (!esValidaLaSeleccion)
            {
                throw new ApuestaException(Mensajes.Apuesta_NumeroInválido);
            }

            var esValidoElSaldo = this.ValidarValorApuesta(apuestaAEvaluar.ValorApuesta);

            if (!esValidoElSaldo)
            {
                var mensaje = string.Format(Mensajes.Apuesta_ValorApuestaInValido, Util.ObtenerValorEnDinero(Util.VALOR_MÍNIMO_APUESTA), Util.ObtenerValorEnDinero(Util.VALOR_MÁXIMO_APUESTA));
                throw new ApuestaException(mensaje);
            }

            ApuestaEsValida = true;
        }
 public IActionResult CrearApuesta([FromHeader] string idUsuario,
                                   [FromBody] ApuestaSolicitud solicitudNuevaApuesta)
 {
     try
     {
         return(new JsonResult(this.ServicioApuesta.AgregarApuesta(solicitudNuevaApuesta, idUsuario))
         {
             StatusCode = (int)HttpStatusCode.Created
         });
     }
     catch (Exception ex)
     {
         return(new JsonResult(ex.Message)
         {
             StatusCode = (int)HttpStatusCode.BadRequest
         });
     }
 }
예제 #3
0
 public bool AgregarApuesta(ApuestaSolicitud nuevaApuesta)
 {
     using (var contextodb = new RuletaContexto()
     {
         CadenaConexion = AppSettings.CadenaConexion
     })
     {
         using (var transaccion = contextodb.Database.BeginTransaction())
         {
             try
             {
                 var nuevaApuestaDB = new Apuesta()
                 {
                     ClienteId     = nuevaApuesta.ClienteId,
                     Color         = (int)nuevaApuesta.ColorApuesta,
                     RuletaId      = nuevaApuesta.RuletaId,
                     Fecha         = nuevaApuesta.Fecha,
                     ValorApuesta  = nuevaApuesta.ValorApuesta,
                     NumeroApuesta = nuevaApuesta.NumeroApuesta
                 };
                 contextodb.Apuestas.Add(nuevaApuestaDB);
                 var registros = contextodb.SaveChanges();
                 if (Util.SeAlteraronRegistros(registros))
                 {
                     transaccion.Commit();
                     return(true);
                 }
                 else
                 {
                     transaccion.Rollback();
                 }
             }
             catch (System.Exception ex)
             {
                 transaccion.Rollback();
                 return(false);
             }
             return(false);
         }
     }
 }
 public bool ActualizarSaldo(ApuestaSolicitud apuestaHecha)
 {
     throw new System.NotImplementedException();
 }
예제 #5
0
 public string AgregarApuesta(ApuestaSolicitud nuevaSolicitudDeApuesta, string idUsario)
 {
     try
     {
         nuevaSolicitudDeApuesta.ClienteId = this.ObtenerIdUsuarioNumerico(idUsario);
         var validacion = new ValidarDatosApuesta(nuevaSolicitudDeApuesta);
         if (validacion.ApuestaEsValida)
         {
             var existeRuletaYEstaHabilitada = this.servicioRuletaDatos.EstaHabilitadaRuleta(nuevaSolicitudDeApuesta.RuletaId);
             if (existeRuletaYEstaHabilitada)
             {
                 var existeCliente = this.servicioClienteDatos.ExisteCliente(nuevaSolicitudDeApuesta.ClienteId);
                 if (existeCliente)
                 {
                     var existeSaldo = this.servicioClienteDatos.ExisteSaldoParaApostar(nuevaSolicitudDeApuesta.ClienteId, nuevaSolicitudDeApuesta.ValorApuesta);
                     if (existeSaldo)
                     {
                         var seRegistroApuesta = this.ServicioApuestaDatos.AgregarApuesta(nuevaSolicitudDeApuesta);
                         if (seRegistroApuesta)
                         {
                             var seActulizoSaldo = this.servicioClienteDatos.ActualizarSaldo(nuevaSolicitudDeApuesta.ClienteId, nuevaSolicitudDeApuesta.ValorApuesta);
                             if (seActulizoSaldo)
                             {
                                 return(Mensajes.Apuesta_AgregadaConExito);
                             }
                             else
                             {
                                 seActulizoSaldo = this.servicioClienteDatos.ActualizarSaldo(nuevaSolicitudDeApuesta.ClienteId, nuevaSolicitudDeApuesta.ValorApuesta);
                                 return(Mensajes.Apuesta_AgregadaConExito);
                             }
                         }
                         else
                         {
                             throw new ApuestaException(Mensajes.Apuesta_ErrorAlCrearApuesta);
                         }
                     }
                     else
                     {
                         var mensaje = string.Format(Mensajes.Cliente_SaldoInSuficiente, nuevaSolicitudDeApuesta.ClienteId);
                         throw new ApuestaException(mensaje);
                     }
                 }
                 else
                 {
                     var mensaje = string.Format(Mensajes.Cliente_NoDisponible, nuevaSolicitudDeApuesta.ClienteId);
                     throw new ApuestaException(mensaje);
                 }
             }
             else
             {
                 var mensaje = string.Format(Mensajes.Ruleta_NoHabilitada, nuevaSolicitudDeApuesta.RuletaId);
                 throw new RuletaException(mensaje);
             }
         }
         else
         {
             throw new RuletaException(Mensajes.Apuesta_DatosGeneralesInválidos);
         }
     }
     catch (RuletaException exe)
     {
         throw exe;
     }
     catch (ApuestaException exe)
     {
         throw exe;
     }
     catch (System.Exception exce)
     {
         throw new Exception(Mensajes.Apuesta_ErrorNoControlado);
     }
 }