Example #1
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);
            }
        }
Example #2
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));
            }
        }
Example #3
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));
            }
        }
Example #4
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));
            }
        }
Example #5
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));
            }
        }
Example #6
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));
            }
        }
Example #7
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));
            }
        }
Example #8
0
        /// <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));
            }
        }
Example #9
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));
            }
        }
Example #10
0
        public OperationResponse <bool> DeletePair()
        {
            var result = new OperationResponse <bool>();

            try
            {
                using (DB_SpeedforceEntities entities = new DB_SpeedforceEntities())
                {
                    UpdateEntity();
                    entities.TB_AtletaEntrenador.Attach(PairEntity);
                    entities.TB_AtletaEntrenador.Remove(PairEntity);
                    entities.SaveChanges();
                    return(result.Complete(true));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(result.Failed(false));
            }
        }