Ejemplo n.º 1
0
        public static ExerciseModel Convert(DbExerciseModel inputModel)
        {
            ExerciseModel outputModel = new ExerciseModel();

            outputModel.titleExcercice   = inputModel.Title;
            outputModel.trainingId       = inputModel.trainingId;
            outputModel.lastTrainingDate = inputModel.lastTrainingDate;
            outputModel.isDoneToday      = inputModel.isDoneToday;
            outputModel.amountOfSets     = inputModel.amountOfSets;


            return(outputModel);
        }
        public async Task <int> SaveItemAsync(DbExerciseModel item)
        {
            if (item.Id != 0)
            {
                await database.UpdateAsync(item);

                return(item.Id);
            }
            else
            {
                await database.InsertAsync(item);

                return(item.Id);
            }
        }
        public async void Add()
        {
            DbSetModel setModel = new DbSetModel();

            setModel.Date    = DateTime.Now;
            setModel.comment = comment;
            string trainingData = "";

            foreach (var a in repsKgsList)
            {
                trainingData += "| " + a.Reps + "*" + a.Kgs + " |";
            }
            //setModel.trainingData = "3*23 | 13*0 | 12*2";
            string[] ids = exerciseModel.trainingId.Split('_');
            setModel.trainingData = trainingData;
            setModel.trainingId   = exerciseModel.trainingId;


            bool answer = await App.Current.MainPage.DisplayAlert("Is data correct?", trainingData + "\n\n" + comment, "Yes", "No");

            if (!answer)
            {
                return;
            }

            if (setsList.Count != 0)
            {
                if (setsList.First().setDate.Date == DateTime.Now.Date)
                {
                    bool dateAnswer = await App.Current.MainPage.DisplayAlert("Caution!", "You have already done this exercise today, do you want to add else one entry?", "Yes", "No");

                    if (!dateAnswer)
                    {
                        return;
                    }
                }
            }


            try
            {
                await App.SetDatabase.SaveItemAsync(setModel);

                //changing data in workout
                DbWorkoutModel tmpWorkModel = new DbWorkoutModel();
                await App.WorkoutDatabase.CreateTable();

                foreach (var a in await App.WorkoutDatabase.GetItemsAsync())
                {
                    if (a.Id == Convert.ToInt32(ids[0]))
                    {
                        tmpWorkModel = a;
                        break;
                    }
                }
                tmpWorkModel.lastTrainingDate = DateTime.Now;
                await App.WorkoutDatabase.SaveItemAsync(tmpWorkModel);

                //changing data in exercise
                DbExerciseModel tmpExModel = new DbExerciseModel();
                tmpExModel.trainingId       = exerciseModel.trainingId;
                tmpExModel.Title            = exerciseModel.titleExcercice;
                tmpExModel.Id               = Convert.ToInt32(ids[1]);
                tmpExModel.lastTrainingDate = DateTime.Now;
                tmpExModel.amountOfSets     = exerciseModel.amountOfSets;
                //tmpExModel.comment = exerciseModel.comment;
                await App.ExerciseDatabase.SaveItemAsync(tmpExModel);
            }
            catch
            {
                await App.Current.MainPage.DisplayAlert("Oops, something wrong!", "We couldn't save expression to dataBase, write to developer", "OK");
            }

            Comment = "";
            List <RepsKgsModel> tmpKgList = new List <RepsKgsModel>(repsKgsList);

            foreach (var a in tmpKgList)
            {
                a.Kgs  = "";
                a.Reps = "";
            }
            RepsKgsList = tmpKgList;

            OnAppearing(new object(), new EventArgs());
        }
 public async Task <int> DeleteItemAsync(DbExerciseModel item)
 {
     return(await database.DeleteAsync(item));
 }