예제 #1
0
        public void CountUsersElo()
        {
            var allSolutions = _sudokuContext.UserGameSolution
                               .Select(x => new { x.ResolvedGameEntering, x.User, x.Time })
                               .OrderBy(x => x.Time)
                               .ToList();
            var allSolutionsGrouped = allSolutions.GroupBy(x => x.ResolvedGameEntering);

            var partialResults = new List <Tuple <DB.Entity.User, float, float> >();

            foreach (var group in allSolutionsGrouped)
            {
                var i = 1;
                foreach (var item in group)
                {
                    float points = i / (float)group.Count();
                    if (partialResults.Any(m => m.Item1 == item.User))
                    {
                        var index             = partialResults.FindIndex(x => x.Item1 == item.User);
                        var usersPartialScore = partialResults.Find(x => x.Item1 == item.User);
                        partialResults[index] = Tuple.Create(item.User, usersPartialScore.Item2 + points, usersPartialScore.Item3 + 1);
                    }
                    else
                    {
                        partialResults.Add(new Tuple <DB.Entity.User, float, float>(item.User, points, 1));
                    }
                }
            }
            foreach (var partialResult in partialResults)
            {
                partialResult.Item1.Elo = (partialResult.Item2 / partialResult.Item3) * 100;
                _sudokuContext.SaveChanges();
            }
        }
예제 #2
0
        public bool PutProducto(Producto m)
        {
            bool     resultado = false;
            Producto P         = new Producto();

            try
            {
                using (SudokuContext Context = new SudokuContext())
                {
                    P = Context.Producto.Where(x => x.Codigo == m.Codigo).First();
                    if (P != null)
                    {
                        P.Nombre             = m.Nombre;
                        P.Descripcion        = m.Descripcion;
                        P.Precio             = m.Precio;
                        P.Impuesto           = m.Impuesto;
                        P.Moneda             = m.Moneda;
                        P.Estatus            = m.Estatus;
                        P.FechaActualizacion = m.FechaActualizacion;
                        Context.SaveChanges();
                        resultado = true;
                    }
                }
            }
            catch (Exception ex)
            {
                InsertarSucesoLog(Funcion.ConstruirSucesoLog(ex.ToString().Substring(0, 300) + "*EngineDb/PutProducto*" + ""));
            }
            return(resultado);
        }
예제 #3
0
        public GameEntering SaveGameEntering(Game gameRecieved, float time)
        {
            GameEntering game;

            if (gameRecieved.Id == 0)
            {
                game = new GameEntering
                {
                    Id                           = gameRecieved.Id,
                    Name                         = gameRecieved.Name,
                    Entering                     = gameRecieved.Entering,
                    Solution                     = gameRecieved.Solution,
                    DifficulitySettings          = gameRecieved.Difficulity,
                    AvarageTime                  = time,
                    NumberOfSuccessfullSolutions = 1
                };

                _sudokuContext.GameEntering.Add(game);
            }
            else
            {
                game             = _sudokuContext.GameEntering.Find(gameRecieved.Id);
                game.AvarageTime = (game.AvarageTime * game.NumberOfSuccessfullSolutions + time) / (game.NumberOfSuccessfullSolutions + 1);
                game.NumberOfSuccessfullSolutions += 1;

                _sudokuContext.GameEntering.Update(game);
            }
            _sudokuContext.SaveChanges();
            return(game);
        }
예제 #4
0
 public void RemoveRating(string name)
 {
     using (var db = new SudokuContext())
     {
         db.Remove(db.Ratings.Single(c => c.Name == name));
         db.SaveChanges();
     }
 }
예제 #5
0
        public void RemoveComment(string name)
        {
            //var sql="DELETE FROM Comment WHERE Name= {}"

            using (var db = new SudokuContext())
            {
                db.Remove(db.Comments.First(c => c.Name == name));
                db.SaveChanges();
            }
        }
예제 #6
0
        public bool InsertarSucesoLog(SucesoLog model)
        {
            bool resultado = false;

            try
            {
                using (SudokuContext Context = new SudokuContext())
                {
                    Context.SucesoLog.Add(model);
                    Context.SaveChanges();
                    resultado = true;
                }
            }
            catch {}
            return(resultado);
        }
예제 #7
0
        public void AddScore(Score score)
        {
            if (score == null)
            {
                throw new ServiceException("Score must be not null!");
            }
            if (score.Name == null)
            {
                throw new ServiceException("Score contains null Name!");
            }

            using (var db = new SudokuContext())
            {
                db.Add(score);
                db.SaveChanges();
            }
        }
예제 #8
0
        public bool InsertarTransaccionPaypal(TransaccionPaypal model)
        {
            bool resultado = false;

            try
            {
                using (SudokuContext Context = new SudokuContext())
                {
                    Context.TransaccionPaypal.Add(model);
                    Context.SaveChanges();
                    resultado = true;
                }
            }
            catch (Exception ex)
            {
                InsertarSucesoLog(Funcion.ConstruirSucesoLog(ex.ToString().Substring(0, 300) + "*EngineDb/InsertarTransaccionPaypal*"));
            }
            return(resultado);
        }
예제 #9
0
        public bool InsertarNuevoGerente(Gerente model)
        {
            bool resultado = false;

            try
            {
                using (SudokuContext Context = new SudokuContext())
                {
                    Context.Gerente.Add(model);
                    Context.SaveChanges();
                    resultado = true;
                }
            }
            catch (Exception ex)
            {
                InsertarSucesoLog(Funcion.ConstruirSucesoLog(ex.ToString().Substring(0, 300) + "*EngineDb/InsertarNuevoGerente*" + ""));
            }
            return(resultado);
        }
예제 #10
0
        public bool InsertarResetPassword(ResetPassword model)
        {
            bool resultado = false;

            try
            {
                using (SudokuContext Context = new SudokuContext())
                {
                    Context.ResetPassword.Add(model);
                    Context.SaveChanges();
                    resultado = true;
                }
            }
            catch (Exception ex)
            {
                InsertarSucesoLog(Funcion.ConstruirSucesoLog(ex.ToString().Substring(0, 300) + "*EngineDb/InsertarResetPassword*" + model.Email));
            }
            return(resultado);
        }
예제 #11
0
        public void AddRating(Rating rate)
        {
            if (rate == null)
            {
                throw new ServiceException("Rating must be not null!");
            }

            if (rate.Name == null)
            {
                throw new ServiceException("Rating contains null Name!");
            }

            if (rate.Mark > 5 || rate.Mark < 0)
            {
                throw new ServiceException("Rating must be from 0 to 5");
            }

            using (var db = new SudokuContext())
            {
                //db.Add(rate);
                //db.SaveChanges();


                var name = rate.Name;
                if (db.Ratings.Any(e => e.Name == name))
                {
                    //var currentRating = db.Ratings.First(e => e.Name == name);
                    //currentRating.Name = name;

                    db.Ratings.Attach(rate);
                    db.Entry(rate).State = EntityState.Modified;
                }
                else
                {
                    db.Ratings.Add(rate);
                    db.Entry(rate).State = EntityState.Added;
                }

                db.SaveChanges();
            }
        }
예제 #12
0
        public void AddComment(Comment comment)
        {
            if (comment == null)
            {
                throw new ServiceException("Comment must be not null!");
            }
            if (comment.Name == null)
            {
                throw new ServiceException("Comment contains null Name!");
            }
            if (comment.Message == null)
            {
                throw new ServiceException("Comment contains null Message!");
            }

            using (var db = new SudokuContext())
            {
                db.Add(comment);
                db.SaveChanges();
            }
        }
예제 #13
0
        public bool InsertarClienteTest(IEngineProyect Funcion, string email)
        {
            bool    resultado = false;
            Cliente model     = new Cliente();

            model = Funcion.ConstruirInsertarClienteTest(email);
            using (SudokuContext Context = new SudokuContext())
            {
                try
                {
                    Context.Cliente.Add(model);
                    Context.SaveChanges();
                    resultado = true;
                }
                catch (Exception ex)
                {
                    InsertarSucesoLog(Funcion.ConstruirSucesoLog(ex.ToString().Substring(0, 300) + "*EngineDb/InsertarClienteTest*" + email));
                }
            };
            return(resultado);
        }
예제 #14
0
        public bool PutGerente(Gerente m, string subEjecutada)
        {
            bool    resultado = false;
            Gerente P         = new Gerente();

            try
            {
                using (SudokuContext Context = new SudokuContext())
                {
                    P = Context.Gerente.Where(x => x.Email == m.Email).First();
                    if (P != null)
                    {
                        if (subEjecutada == "Alto")
                        {
                            P.NombreUsuario      = m.NombreUsuario;
                            P.FechaActualizacion = m.FechaActualizacion;
                            P.Estatus            = m.Estatus;
                            P.Rol = m.Rol;
                        }
                        else
                        {
                            P.Nombre             = m.Nombre;
                            P.NombreUsuario      = m.NombreUsuario;
                            P.FechaActualizacion = m.FechaActualizacion;
                            P.Email    = m.Email;
                            P.Password = m.Password;
                            P.Estatus  = m.Estatus;
                        }
                        Context.SaveChanges();
                        resultado = true;
                    }
                }
            }
            catch (Exception ex)
            {
                InsertarSucesoLog(Funcion.ConstruirSucesoLog(ex.ToString().Substring(0, 300) + "*EngineDb/PutGerente*" + ""));
            }
            return(resultado);
        }