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(); } }
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); }
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); }
public void RemoveRating(string name) { using (var db = new SudokuContext()) { db.Remove(db.Ratings.Single(c => c.Name == name)); db.SaveChanges(); } }
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(); } }
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); }
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(); } }
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); }
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); }
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); }
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(); } }
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(); } }
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); }
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); }