Beispiel #1
0
        public SaveResult SaveTune(UserTuneViewModel userTuneViewModel)
        {
            SaveResult saveResult = new SaveResult();

            try
            {
                pidhubEntities entity = new pidhubEntities();
                Tune           tune;

                // if Tune ID is not present then create a new Tune, else get the existing entity
                if (userTuneViewModel.TuneID == 0)
                {
                    tune = new Tune();
                }
                else
                {
                    tune = (from t in entity.Tunes
                            where t.Tune_ID == userTuneViewModel.TuneID
                            select t).FirstOrDefault();
                }

                // update values in entity
                tune.Quad_ID       = userTuneViewModel.QuadID;
                tune.TuneName      = userTuneViewModel.TuneName;
                tune.Roll_P        = userTuneViewModel.Roll_P;
                tune.Pitch_P       = userTuneViewModel.Pitch_P;
                tune.Yaw_P         = userTuneViewModel.Yaw_P;
                tune.Roll_I        = userTuneViewModel.Roll_I;
                tune.Pitch_I       = userTuneViewModel.Pitch_I;
                tune.Yaw_I         = userTuneViewModel.Yaw_I;
                tune.Roll_D        = userTuneViewModel.Roll_D;
                tune.Pitch_D       = userTuneViewModel.Pitch_D;
                tune.Yaw_D         = userTuneViewModel.Yaw_D;
                tune.Roll_Rate     = userTuneViewModel.Roll_Rate;
                tune.Pitch_Rate    = userTuneViewModel.Pitch_Rate;
                tune.Pitch_RCRate  = userTuneViewModel.Pitch_RCRate;
                tune.Yaw_Rate      = userTuneViewModel.Yaw_Rate;
                tune.Yaw_RCRate    = userTuneViewModel.Yaw_RCRate;
                tune.Roll_RCRate   = userTuneViewModel.Roll_RCRate;
                tune.Roll_RCCurve  = userTuneViewModel.Roll_RCCurve;
                tune.Pitch_RCCurve = userTuneViewModel.Pitch_RCCurve;
                tune.Yaw_RCCurve   = userTuneViewModel.Yaw_RCCurve;
                tune.Roll_RCExpo   = userTuneViewModel.Roll_RCExpo;
                tune.Pitch_RCExpo  = userTuneViewModel.Pitch_RCExpo;
                tune.Yaw_RCExpo    = userTuneViewModel.Yaw_RCExpo;

                // if this is a new Tune then must 'Add' to entity
                if (userTuneViewModel.TuneID == 0)
                {
                    entity.Tunes.Add(tune);
                }

                entity.SaveChanges();
            }
            catch (Exception ex)
            {
                saveResult.ErrorMessage = String.Format("There was an error saving your tune: {0}.", ex.Message);
            }
            return(saveResult);
        }
Beispiel #2
0
        public UserAccountViewModel CreateUserAccount(UserAccountViewModel userViewModel)
        {
            try
            {
                pidhubEntities entity      = new pidhubEntities();
                UserAccount    userAccount = new UserAccount()
                {
                    PilotName = userViewModel.PilotName,
                    Email     = userViewModel.Email,
                    Password  = userViewModel.Password
                };

                entity.UserAccounts.Add(userAccount);
                entity.SaveChanges();


                userViewModel.UserID = userAccount.User_ID;
            }
            catch (Exception ex)
            {
                //TODO Change method to return SaveResult
                //saveResult.ErrorMessage = String.Format("There was an error creating your account {0}.", ex.Message);
            }
            return(userViewModel);
        }
Beispiel #3
0
        public SaveResult SaveQuad(QuadDetailViewModel quadDetailsViewModel)
        {
            SaveResult saveResult = new SaveResult();

            try
            {
                pidhubEntities entity = new pidhubEntities();
                Quad           quad;

                if (quadDetailsViewModel.QuadID == 0)
                {
                    quad = new Quad();
                }
                else
                {
                    quad = (from q in entity.Quads
                            where q.Quad_ID == quadDetailsViewModel.QuadID
                            select q).FirstOrDefault();
                }

                quad.User_ID  = quadDetailsViewModel.UserID;
                quad.QuadName = quadDetailsViewModel.QuadName;
                quad.FlightControllerSoftwareID = quadDetailsViewModel.SelectedFCSoftwareID;
                quad.FlightControllerHardwareID = quadDetailsViewModel.SelectedFCHardwareID;
                quad.FrameID   = quadDetailsViewModel.SelectedFrameID;
                quad.MotorID   = quadDetailsViewModel.SelectedMotorID;
                quad.ESCID     = quadDetailsViewModel.SelectedESCID;
                quad.PropID    = quadDetailsViewModel.SelectedPropID;
                quad.BatteryID = quadDetailsViewModel.SelectedBatteryID;

                if (quadDetailsViewModel.QuadID == 0)
                {
                    entity.Quads.Add(quad);
                }

                entity.SaveChanges();
            }
            catch (Exception ex)
            {
                saveResult.ErrorMessage = String.Format("There was an error saving your quad: {0}.", ex.Message);
            }
            return(saveResult);
        }
Beispiel #4
0
        public SaveResult DeleteTune(int tuneID)
        {
            SaveResult saveResult = new SaveResult();

            try
            {
                pidhubEntities entity = new pidhubEntities();
                var            tune   = (from t in entity.Tunes
                                         where t.Tune_ID == tuneID
                                         select t).FirstOrDefault();

                entity.Tunes.Remove(tune);
                entity.SaveChanges();
            }
            catch (Exception ex)
            {
                saveResult.ErrorMessage = String.Format("There was an error deleting your Tune: {0}", ex.Message);
            }
            return(saveResult);
        }
Beispiel #5
0
        public SaveResult DeleteQuad(int quadID)
        {
            SaveResult saveResult = new SaveResult();

            try
            {
                pidhubEntities entity = new pidhubEntities();

                var quad = (from q in entity.Quads
                            where q.Quad_ID == quadID
                            select q).FirstOrDefault();

                entity.Tunes.RemoveRange(quad.Tunes);
                entity.Quads.Remove(quad);
                entity.SaveChanges();
            }
            catch (Exception ex)
            {
                saveResult.ErrorMessage = String.Format("There was an error deleting your quad: {0}.", ex.Message);
            }
            return(saveResult);
        }