Пример #1
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));
            }
        }
Пример #2
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));
            }
        }
Пример #3
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));
            }
        }
Пример #4
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));
            }
        }
Пример #5
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));
            }
        }