Exemple #1
0
        public TrainingSession(string sessionID)
        {
            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    var obj = entities.TB_SesionEntrenamiento.Find(sessionID);

                    SessionID          = obj.ID_Sesion;
                    RouteID            = obj.ID_Ruta;
                    UserID             = obj.ID_Usuario;
                    AverageBPM         = Math.Round(obj.RitmoCardiacoMedio, 2);
                    BurntCalories      = Math.Round(obj.CaloriasQuemadas, 2);
                    RelativeHumidity   = Math.Round(obj.HumedadRelativa, 2);
                    Distance           = Math.Round(obj.DistanciaRecorrida, 2);
                    StartTime          = obj.MomentoInicio;
                    EndTime            = obj.MomentoInicio;
                    Temperature        = Math.Round(obj.Temperatura, 2);
                    ClimateConditionID = obj.ID_Condicion;
                    TrainingTypeID     = obj.ID_TipoEntrenamiento;
                    SessionStatusID    = obj.ID_StatusSesion;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("---DB/Entity Problem---");
                Console.WriteLine();
                Console.WriteLine(ex);
            }
        }
Exemple #2
0
        public OperationResponse <Person> AddPerson()
        {
            var result = new OperationResponse <Person>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    if (!entities.TB_Personas.Any(cred => cred.Email == this.Email))
                    {
                        UpdateEntity();
                        entities.Entry(PersonEntity).State = System.Data.Entity.EntityState.Added;
                        entities.SaveChanges();
                        return(result.Complete(this));
                    }
                    else
                    {
                        return(result.Failed("Email ya está siendo usado."));
                    }
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
Exemple #3
0
        public void UpdateSession()
        {
            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    var obj = entities.TB_SesionEntrenamiento.SingleOrDefault(cred => cred.ID_Sesion == SessionID);
                    if (obj != null)
                    {
                        obj.CaloriasQuemadas     = this.BurntCalories;
                        obj.HumedadRelativa      = this.RelativeHumidity;
                        obj.ID_Ruta              = this.RouteID;
                        obj.ID_Sesion            = this.SessionID;
                        obj.ID_Condicion         = this.ClimateConditionID;
                        obj.ID_StatusSesion      = this.SessionStatusID;
                        obj.ID_TipoEntrenamiento = this.TrainingTypeID;
                        obj.ID_Usuario           = this.UserID;
                        obj.MomentoInicio        = this.StartTime;
                        obj.MomentoTermino       = this.EndTime;
                        obj.RitmoCardiacoMedio   = this.AverageBPM;
                        obj.DistanciaRecorrida   = this.Distance;
                        obj.Temperatura          = this.Temperature;

                        entities.SaveChanges();
                        UpdateEntity();
                        entities.TB_SesionEntrenamiento.Add(TrainingEntity);
                        entities.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #4
0
        public OperationResponse <TrainingSession> AddSession(BIEntryModel model)
        {
            var result = new OperationResponse <TrainingSession>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    this.SessionID          = System.Guid.NewGuid().ToString();
                    this.UserID             = model.UserID;
                    this.RouteID            = model.RouteID;
                    this.AverageBPM         = 0;
                    this.BurntCalories      = 0;
                    this.ClimateConditionID = 1;
                    this.Distance           = 0;
                    this.EndTime            = DateTime.Now;
                    this.StartTime          = DateTime.Now;
                    this.Temperature        = 0;
                    this.TrainingTypeID     = 1;
                    this.SessionStatusID    = 1;
                    this.RelativeHumidity   = 0;


                    UpdateEntity();
                    entities.Entry(TrainingEntity).State = System.Data.Entity.EntityState.Added;
                    entities.SaveChanges();
                    return(result.Complete(this));
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
Exemple #5
0
        public OperationResponse <TrainingSession> AddSession()
        {
            var result = new OperationResponse <TrainingSession>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    if (!entities.TB_SesionEntrenamiento.Any(cred => cred.ID_Sesion == SessionID))
                    {
                        UpdateEntity();
                        entities.TB_SesionEntrenamiento.Add(TrainingEntity);
                        entities.SaveChanges();
                        return(result.Complete(this));
                    }
                    else
                    {
                        UpdateSession();
                        return(result.Complete(this));
                    }
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
Exemple #6
0
        public OperationResponse <Person> UpdatePerson()
        {
            var result = new OperationResponse <Person>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    var obj = entities.TB_Personas.SingleOrDefault(cred => cred.Email == Email);
                    if (obj != null)
                    {
                        obj.Email           = Email;
                        obj.Apellidos       = LastName;
                        obj.ID_Sexo         = Sex;
                        obj.Nombre          = Name;
                        obj.ID_Ciudad       = CityID;
                        obj.NumeroTelefono  = TelephoneNumber;
                        obj.FechaNacimiento = BirthDate;

                        entities.SaveChanges();
                        return(result.Complete(this));
                    }
                    else
                    {
                        return(result.Failed("Usuario no encontrado."));
                    }
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
        /// <summary>
        /// Method that update an the objects data according to an existing user.
        /// </summary>
        /// <param name="username">The username of the searched User</param>
        public OperationResponse <User> GetUser(string username)
        {
            var result = new OperationResponse <User>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    var requestedUser = entities.TB_Usuarios.Find(username);
                    if (requestedUser != null)
                    {
                        Username = requestedUser.ID_Usuario;
                        Password = requestedUser.Contraseña;
                        Role     = requestedUser.ID_Rol;
                        Email    = requestedUser.Email;

                        return(result.Complete(this));
                    }
                    return(result.Failed("Usuario no encontrado."));
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
        /// <summary>
        /// Method to update information about an athlete on the DB
        /// </summary>
        public OperationResponse <Athlete> UpdateAthlete()
        {
            var result = new OperationResponse <Athlete>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    var obj = entities.TB_Atletas.SingleOrDefault(cred => cred.ID_Usuario == Username);
                    if (obj != null)
                    {
                        obj.ID_Usuario      = Username;
                        obj.ID_TipoCiclista = BikerType;
                        obj.Peso            = Math.Round(Weight, 2);
                        obj.Altura          = Math.Round(Height, 2);
                        obj.ID_Bicicleta    = 1;


                        entities.SaveChanges();
                        return(result.Complete(this));
                    }
                    else
                    {
                        return(result.Failed("Atleta no encontrado."));
                    }
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
Exemple #9
0
        public OperationResponse <Person> GetPerson(string email)
        {
            var result = new OperationResponse <Person>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    var requestedUser = entities.TB_Personas.Find(email);
                    if (requestedUser != null)
                    {
                        Email           = requestedUser.Email;
                        Name            = requestedUser.Nombre;
                        LastName        = requestedUser.Apellidos;
                        BirthDate       = requestedUser.FechaNacimiento;
                        Sex             = requestedUser.ID_Sexo;
                        CityID          = requestedUser.ID_Ciudad;
                        TelephoneNumber = requestedUser.NumeroTelefono;

                        return(result.Complete(this));
                    }
                    return(result.Failed("Atleta no encontrado."));
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
Exemple #10
0
        public OperationResponse <TrainerAthlete> AddPair()
        {
            var result = new OperationResponse <TrainerAthlete>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    if (!entities.TB_AtletaEntrenador.Any(cred => cred.ID_Atleta == this.AthleteID && cred.ID_Entrenador == this.TrainerID))
                    {
                        UpdateEntity();
                        entities.Entry(PairEntity).State = System.Data.Entity.EntityState.Added;
                        entities.SaveChanges();
                        return(result.Complete(this));
                    }
                    else
                    {
                        return(result.Failed("Entrenador y Atleta ya trabajan juntos."));
                    }
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
Exemple #11
0
        /// <summary>
        /// Method that adds an user into the DB
        /// </summary>
        public OperationResponse <User> AddUser()
        {
            var result = new OperationResponse <User>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    if (!entities.TB_Usuarios.Any(cred => cred.ID_Usuario == Username))
                    {
                        UpdateEntity();
                        entities.Entry(UserEntity).State = System.Data.Entity.EntityState.Added;
                        entities.SaveChanges();
                        return(result.Complete(this));
                    }
                    else
                    {
                        return(result.Failed("Usuario ya existe."));
                    }
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
 public static bool Login(string username, string password)
 {
     using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
     {
         entities.Configuration.ProxyCreationEnabled = false;
         return(entities.TB_Usuarios.Any(user => user.ID_Usuario.Equals(username, StringComparison.OrdinalIgnoreCase) && user.Contraseña == password));
     }
 }
 public static string GetEmail(string id)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             string value = entities.TB_Usuarios.SingleOrDefault(cred => cred.ID_Usuario == id).Email;
             return(value);
         }
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
 /// <summary>
 /// Method to retrieve the BikerType's descripcion.
 /// </summary>
 /// <param name="id">The ID of the BikerType</param>
 public static string GetBikerTypeString(int id)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             string value = entities.TB_TipoCiclista.SingleOrDefault(cred => cred.ID_TipoCiclista == id).DescripcionCiclista;
             return(value);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(ex.Message);
     }
 }
 /// <summary>
 /// Method to retrieve the BikerType's ID
 /// </summary>
 /// <param name="s">A string with the description fo the BikerType</param>
 /// <returns>The ID of the Biker Type</returns>
 public static int GetBikerTypeID(string s)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             int idvalue = entities.TB_TipoCiclista.SingleOrDefault(cred => cred.DescripcionCiclista == s).ID_TipoCiclista;
             return(idvalue);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(0);
     }
 }
 /// <summary>
 /// Method to retrieve a Role's ID.
 /// </summary>
 /// <param name="s">A string with the Role's description</param>
 /// <returns>The ID of the role.</returns>
 public static int GetRoleID(string s)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             int idvalue = entities.TB_Roles.SingleOrDefault(cred => cred.NombreRol == s).ID_Rol;
             return(idvalue);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(0);
     }
 }
 public static string GetClimateString(int id)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             string value = entities.TB_CondicionClimatica.SingleOrDefault(cred => cred.ID_Condicion == id).Clima;
             return(value);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(ex.Message);
     }
 }
 /// <summary>
 /// Method to retrieve the training type's ID
 /// </summary>
 /// <param name="s">The climate condition's name</param>
 /// <returns>The cimate condition's ID</returns>
 public static int GetClimateConditionID(string s)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             int idvalue = entities.TB_CondicionClimatica.SingleOrDefault(cred => cred.Clima == s).ID_Condicion;
             return(idvalue);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(0);
     }
 }
 public static string GetTrainingTyeString(int id)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             string value = entities.TB_TipoEntrenamiento.SingleOrDefault(cred => cred.ID_TipoEntrenamiento == id).DescripcionEntrenamiento;
             return(value);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(ex.Message);
     }
 }
 /// <summary>
 /// Method to retrieve the Session's status description.
 /// </summary>
 /// <param name="id">The ID of the session status</param>
 /// <returns>A string with the Description of the session.</returns>
 public static string GetSessionStatusString(int id)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             string value = entities.TB_StatusSesion.SingleOrDefault(cred => cred.ID_StatusSesion == id).DescripcionStatus;
             return(value);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return("Failed");
     }
 }
 /// <summary>
 /// Method to look for a City's ID from the DB
 /// </summary>
 /// <param name="city">The name of the city.</param>
 /// <param name="country">The ID of the country the city is in</param>
 /// <returns>The ID of the searched City</returns>
 public static int GetCityID(string city, int country)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             int idvalue = entities.TB_Ciudad.SingleOrDefault(cred => cred.NombreCiudad == city && cred.ID_Pais == country).ID_Ciudad;
             return(idvalue);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(0);
     }
 }
 public static int GetCountryFromCity(int cityid)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             int idvalue = entities.TB_Ciudad.SingleOrDefault(cred => cred.ID_Ciudad == cityid).ID_Pais;
             return(idvalue);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(0);
     }
 }
 /// <summary>
 /// Method to retrieve the sex ID.
 /// </summary>
 /// <param name="s">The string representing with the sex description</param>
 /// <returns>The ID of the corresponding sex</returns>
 public static int GetSexID(string s)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             int idvalue = entities.TB_Sexo.SingleOrDefault(cred => cred.Descripcion == s).ID_Sexo;
             return(idvalue);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(0);
     }
 }
 /// <summary>
 /// Method to retrieve the training type's ID
 /// </summary>
 /// <param name="s">The training type's name</param>
 /// <returns>The training type's ID</returns>
 public static int GetTrainingTypeID(string s)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             int idvalue = entities.TB_TipoEntrenamiento.SingleOrDefault(cred => cred.DescripcionEntrenamiento == s).ID_TipoEntrenamiento;
             return(idvalue);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(0);
     }
 }
 public static string GetCityString(int city)
 {
     try
     {
         using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
         {
             string value = entities.TB_Ciudad.SingleOrDefault(cred => cred.ID_Ciudad == city).NombreCiudad;
             return(value);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(ex.Message);
     }
 }
        public static List <Route> isRouteSimilar(ValidationModel route)
        {
            List <Route> routeList = new List <Route>();
            var          response  = new OperationResponse <List <Route> >();

            using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
            {
                var startList = entities.sp_StartList(route.StartPoint.lng, route.StartPoint.lat);
                var endList   = entities.sp_EndList(route.EndPoint.lng, route.EndPoint.lat);



                List <Location> locList1 = new List <Location>();

                foreach (var item in startList)
                {
                    Location loc = new Location();

                    loc.ID_Route = item.ID;

                    locList1.Add(loc);
                }

                List <Location> locList2 = new List <Location>();

                foreach (var item2 in endList)
                {
                    Location loc2 = new Location();

                    loc2.ID_Route = item2.ID;

                    locList2.Add(loc2);
                }

                locList1.Intersect(locList2);

                foreach (var item3 in locList1)
                {
                    Route r = new Route(item3.ID_Route);

                    routeList.Add(r);
                }


                return(routeList);
            }
        }
Exemple #27
0
        public OperationResponse <String> GetPhoto()
        {
            var result = new OperationResponse <String>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    Photo = entities.TB_Personas.SingleOrDefault(cred => cred.Email == Email).Foto;
                    return(result.Complete(entities.TB_Personas.SingleOrDefault(cred => cred.Email == Email).Foto));
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
        public static OperationResponse <List <AthleteUser> > GetAthletes(string userid)
        {
            List <AthleteUser> listModel = new List <AthleteUser>();
            var response = new OperationResponse <List <AthleteUser> >();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    var listofUsers = (from c in entities.TB_AtletaEntrenador where c.ID_Entrenador == userid select c);

                    foreach (var item in listofUsers)
                    {
                        var athleteEntity = entities.TB_Atletas.SingleOrDefault(cred => cred.ID_Usuario == item.ID_Atleta);

                        AthleteUser athlete = new AthleteUser();
                        athlete.Username        = athleteEntity.ID_Usuario;
                        athlete.Email           = athleteEntity.TB_Usuarios.Email;
                        athlete.Bike            = (int)athleteEntity.ID_Bicicleta;
                        athlete.BikerType       = GetBikerTypeString((int)athleteEntity.ID_TipoCiclista);
                        athlete.BirthDate       = athleteEntity.TB_Usuarios.TB_Personas.FechaNacimiento;
                        athlete.CityName        = athleteEntity.TB_Usuarios.TB_Personas.TB_Ciudad.NombreCiudad;
                        athlete.CountryName     = athleteEntity.TB_Usuarios.TB_Personas.TB_Ciudad.TB_Pais.NombrePais;
                        athlete.Height          = (double)athleteEntity.Altura;
                        athlete.LastName        = athleteEntity.TB_Usuarios.TB_Personas.Apellidos;
                        athlete.Name            = athleteEntity.TB_Usuarios.TB_Personas.Nombre;
                        athlete.Weight          = (double)athleteEntity.Peso;
                        athlete.Sex             = athleteEntity.TB_Usuarios.TB_Personas.TB_Sexo.Descripcion;
                        athlete.Password        = "******";
                        athlete.TelephoneNumber = athleteEntity.TB_Usuarios.TB_Personas.NumeroTelefono;
                        athlete.Role            = athleteEntity.TB_Usuarios.TB_Roles.NombreRol;

                        //Add object to list
                        listModel.Add(athlete);
                    }
                    return(response.Complete(listModel));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(response.Failed(ex));
            }
        }
Exemple #29
0
        /// <summary>
        /// Method to add a location to the DB.
        /// </summary>
        /// <returns></returns>
        public OperationResponse <Location> AddLocation()
        {
            var result = new OperationResponse <Location>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    UpdateLocation();
                    entities.Entry(LocationEntity).State = System.Data.Entity.EntityState.Added;
                    entities.SaveChanges();
                    return(result.Complete(this));
                }
            }
            catch (Exception ex)
            {
                return(result.Failed(ex));
            }
        }
        public static OperationResponse <List <Route> > FilteredRoutes(List <Route> list, double dist)
        {
            List <Route> listR    = new List <Route>();
            var          response = new OperationResponse <List <Route> >();


            using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
            {
                var ts = entities.TB_SesionEntrenamiento.Where(cred => cred.DistanciaRecorrida - dist <= 0.01 && cred.DistanciaRecorrida - dist >= -0.01);

                foreach (var item in ts)
                {
                    Route r = new Route(item.ID_Ruta);
                    listR.Add(r);
                }

                return(response.Complete(listR));
            }
        }