Esempio n. 1
0
        public Object Create(JuegoDTO juego)
        {
            try
            {
                using (ModelosDBContainer context = new ModelosDBContainer())
                {
                    JuegoRepository repositorio = new JuegoRepository(context);

                    var juegoEntity = this._mapper.Map <Juego>(juego);
                    repositorio.Create(juegoEntity);

                    context.SaveChanges();



                    juegoEntity.Uuid = StringExtensions.Slugify(juegoEntity.Id.ToString() + "-" + juegoEntity.Nombre);

                    context.SaveChanges();

                    /**
                     * https://stackoverflow.com/questions/5212751/how-can-i-get-id-of-inserted-entity-in-entity-framework
                     */

                    return(this._mapper.Map <JuegoDTO>(repositorio.Get(juegoEntity.Id)));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public static JuegoEN Convert(JuegoDTO dto)
        {
            JuegoEN newinstance = null;

            try
            {
                if (dto != null)
                {
                    newinstance = new JuegoEN();



                    newinstance.Id         = dto.Id;
                    newinstance.ItemActual = dto.ItemActual;
                    newinstance.Aciertos   = dto.Aciertos;
                    newinstance.Fallos     = dto.Fallos;
                    newinstance.Puntuacion = dto.Puntuacion;
                    if (dto.Usuarios_oid != -1)
                    {
                        ReciclaUAGenNHibernate.CAD.ReciclaUA.IUsuarioCAD usuarioCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.UsuarioCAD();

                        newinstance.Usuarios = usuarioCAD.ReadOIDDefault(dto.Usuarios_oid);
                    }
                    newinstance.IntentosItemActual = dto.IntentosItemActual;
                    newinstance.Finalizado         = dto.Finalizado;
                    newinstance.NivelActual        = dto.NivelActual;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
Esempio n. 3
0
 public JuegoDTO Apostar([FromBody] JuegoDTO juego)
 {
     try
     {
         ChanceDAO chance = new ChanceDAO();
         JuegoDTO  result = chance.Apostar(juego);
         return(result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 4
0
        public JuegoDTO Apostar(JuegoDTO juego)
        {
            try
            {
                ChanceDAO chance = new ChanceDAO();
                JuegoDTO  result = chance.Apostar(juego);

                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 5
0
        public ActionResult Apostar(JuegoDTO juego)
        {
            try
            {
                UsuarioDTO usuarioDTO = (UsuarioDTO)Session["usuario"];
                ChanceDAO  chance     = new ChanceDAO(this);

                JuegoDTO juegoCreado = chance.Apostar(juego, usuarioDTO);

                return(Json(juegoCreado));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 6
0
        public JuegoDTO Apostar(JuegoDTO juego)
        {
            try
            {
                Chance model = ApuestaBase(juego);

                db.chances.Add(model);
                db.SaveChanges();

                return(juego);
            }
            catch (Exception ex)
            {
                juego.codigoDeValidacion = "Error en apuesta " + ex.Message;
                return(juego);
            }
        }
Esempio n. 7
0
 public ActionResult Ticket(string id)
 {
     try
     {
         UsuarioDTO usuarioDTO = (UsuarioDTO)Session["usuario"];
         if (usuarioDTO == null)
         {
             return(View("Index"));
         }
         ChanceDAO chance      = new ChanceDAO(this);
         JuegoDTO  juegoCreado = chance.getBySerial(id);
         return(View(juegoCreado));
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 8
0
        public JuegoDTO Apostar(JuegoDTO juego, UsuarioDTO usuarioDTO)
        {
            try
            {
                UsuarioDTO usuario = (UsuarioDTO)controller.Session["usuario"];
                juego.vendedorId = usuario.id;
                Chance model = ApuestaBase(juego);

                db.chances.Add(model);
                db.SaveChanges();

                return(juego);
            }
            catch (Exception ex)
            {
                juego.codigoDeValidacion = "Error en apuesta";
                return(juego);
            }
        }
Esempio n. 9
0
        private Chance ApuestaBase(JuegoDTO juego)
        {
            int loteriaint = 0;

            Int32.TryParse(juego.loteria, out loteriaint);
            List <Loteria> lot = db.loterias.ToList();
            Loteria        loteriaSeleccionada = lot.FirstOrDefault(x => x.id == loteriaint);



            Chance model     = new Chance();
            int    cifrasint = 0;

            Int32.TryParse(juego.cifras, out cifrasint);
            model.cifras             = cifrasint;
            model.codigoDeValidacion = Guid.NewGuid().ToString();
            model.fecha      = DateTime.Now;
            model.serial     = Guid.NewGuid().ToString();
            model.sorteo     = loteriaSeleccionada.ultimoSorteo;
            model.loteriaId  = loteriaSeleccionada.id;
            model.telefono   = juego.telefono;
            model.vendedorId = juego.vendedorId;

            juego.apuestas.ForEach(x =>
            {
                if (x.número != 0)
                {
                    Apuesta item   = new Apuesta();
                    item.combinado = x.combinado;
                    item.directo   = x.directo;
                    item.numero    = x.número.ToString();
                    item.pata      = x.pata;
                    item.una       = x.uña;
                    model.apuestas.Add(item);
                }
            });

            model.totalApuesta       = model.apuestas.Sum(x => x.pata + x.una + x.directo + x.combinado).Value;
            juego.codigoDeValidacion = model.codigoDeValidacion;
            juego.serial             = model.serial;
            return(model);
        }
Esempio n. 10
0
        public JuegoDTO getBySerial(string id)
        {
            try
            {
                var model = db.chances.Include(x => x.apuestas).Include(x => x.loteria).Include(x => x.vendedor).FirstOrDefault(x => x.serial == id.Trim());
                if (model == null)
                {
                    throw new Exception("serial no existe");
                }

                JuegoDTO result = new JuegoDTO();
                result.cifras             = model.cifras.ToString();
                result.codigoDeValidacion = model.codigoDeValidacion;
                result.loteria            = model.loteria.nombre;
                result.fecha       = model.fecha;
                result.fechaSorteo = model.loteria.proximoSorteo;
                result.sorteo      = model.sorteo;

                result.serial     = id;
                result.telefono   = model.telefono;
                result.vendedorId = model.vendedorId;
                result.vendedor   = model.vendedor.nombre;
                model.apuestas.ForEach(x => {
                    ApuestaDTO item = new ApuestaDTO();
                    item.combinado  = x.combinado.Value;
                    item.directo    = x.directo;
                    item.número     = int.Parse(x.numero);
                    item.pata       = x.pata.Value;
                    item.uña        = x.una.Value;
                    result.apuestas.Add(item);
                });
                result.totalApuesta = model.totalApuesta;
                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 11
0
        public Object Post(JuegoDTO juego)
        {
            string BASE_URL  = System.Configuration.ConfigurationManager.AppSettings["BASE_URL"].ToString();
            string BASE_PATH = System.Configuration.ConfigurationManager.AppSettings["BASE_IMAGES_PATH"].ToString();

            juego.Caratula = BASE_URL + BASE_PATH + "/default.png";
            try
            {
                BusinessLogic.Controllers.JuegoController juegoController = new BusinessLogic.Controllers.JuegoController();
                var created = juegoController.Create(juego);
                return(Content(HttpStatusCode.Created, new ResponseDTO(created, "Se ha creado el juego correctamente.", true)));
            }
            catch (Exception e)
            {
                switch (e.Message)
                {
                case "Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.":
                    return(Content(HttpStatusCode.BadRequest, new ResponseDTO(null, "Por favor, ingrese correctamente todos los datos.", false)));

                default:
                    return(Content(HttpStatusCode.InternalServerError, new ResponseDTO(null, e.Message, false)));
                }
            }
        }
Esempio n. 12
0
        public HttpResponseMessage Modificar(int idJuego, [FromBody] JuegoDTO dto)
        {
            // CAD, CEN, returnValue
            JuegoRESTCAD juegoRESTCAD = null;
            JuegoCEN     juegoCEN     = null;
            JuegoDTOA    returnValue  = null;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();
                string token = "";
                if (Request.Headers.Authorization != null)
                {
                    token = Request.Headers.Authorization.ToString();
                }
                int id = new UsuarioCEN().CheckToken(token);



                juegoRESTCAD = new JuegoRESTCAD(session);
                juegoCEN     = new JuegoCEN(juegoRESTCAD);

                // Modify
                juegoCEN.Modificar(idJuego,
                                   dto.ItemActual
                                   ,
                                   dto.Aciertos
                                   ,
                                   dto.Fallos
                                   ,
                                   dto.Puntuacion
                                   ,
                                   dto.IntentosItemActual
                                   ,
                                   dto.Finalizado
                                   ,
                                   dto.NivelActual
                                   );

                // Return modified object
                returnValue = JuegoAssembler.Convert(juegoRESTCAD.ReadOIDDefault(idJuego), session);

                SessionCommit();
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 404 - Not found
            if (returnValue == null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
            // Return 200 - OK
            else
            {
                response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue);

                return(response);
            }
        }
Esempio n. 13
0
        public HttpResponseMessage Crear([FromBody] JuegoDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            JuegoRESTCAD juegoRESTCAD = null;
            JuegoCEN     juegoCEN     = null;
            JuegoDTOA    returnValue  = null;
            int          returnOID    = -1;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();
                string token = "";
                if (Request.Headers.Authorization != null)
                {
                    token = Request.Headers.Authorization.ToString();
                }
                int id = new UsuarioCEN().CheckToken(token);



                juegoRESTCAD = new JuegoRESTCAD(session);
                juegoCEN     = new JuegoCEN(juegoRESTCAD);

                // Create
                returnOID = juegoCEN.Crear(
                    //Atributo OID: p_usuarios
                    // attr.estaRelacionado: true
                    dto.Usuarios_oid                     // association role

                    );
                SessionCommit();

                // Convert return
                returnValue = JuegoAssembler.Convert(juegoRESTCAD.ReadOIDDefault(returnOID), session);
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 201 - Created
            response = this.Request.CreateResponse(HttpStatusCode.Created, returnValue);

            // Location Header

            /*
             * Dictionary<string, object> routeValues = new Dictionary<string, object>();
             *
             * // TODO: y rolPaths
             * routeValues.Add("id", returnOID);
             *
             * uri = Url.Link("GetOIDJuego", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }