Esempio n. 1
0
        public async Task <WorkoutDTO> CreateWorkoutAsync(WorkoutDTO workoutDTO)
        {
            workoutDTO.EstimatedMin = 60;
            var result = await _workoutRepository.AddAsync(_mapper.Map <Workout>(workoutDTO));

            return(_mapper.Map <WorkoutDTO>(result));
        }
Esempio n. 2
0
        public async Task <WorkoutDTO> UpdateWorkoutDescriptionAsync(WorkoutDTO workoutDTO)
        {
            var workout = await _workoutRepository.GetByIdAsync(workoutDTO.Id);

            workout.WorkoutComments = workoutDTO.WorkoutComments;
            await _workoutRepository.SaveChangesAsync();

            return(await GetWorkoutAsync(workoutDTO.Id));
        }
Esempio n. 3
0
        public WorkoutDTO GetWorkouts(string text)
        {
            WorkoutDTO dto = new WorkoutDTO();

            dto.Workouts       = dao.GetWorkouts(text);
            dto.ActivityLevels = activityLevelDAO.GetLevels();
            dto.Categories     = workoutCatDAO.GetCategories();
            return(dto);
        }
Esempio n. 4
0
        public IHttpActionResult Post(WorkoutDTO workoutDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var result = _workoutBAL.AddWorkout(workoutDTO);

            return(Ok(result));
        }
Esempio n. 5
0
 public override void OnNavigatedTo(NavigationParameters parameters)
 {
     if (parameters[NavigationParamterKeys.WorkoutId] is string workoutId)
     {
         Workout = new WorkoutDTO(_context.Workouts
                                  .Include(w => w.ExerciseItems)
                                  .ThenInclude(e => e.Exercise)
                                  .SingleOrDefault(w => w.Id.Equals(workoutId)));
     }
     SubscribeEvents();
 }
Esempio n. 6
0
        public bool AddWorkout(WorkoutDTO workoutDTO)
        {
            var workout = Mapper.Map <WorkoutCollection>(workoutDTO);

            using (var unitOfWork = new UnitOfWork(new WorkoutTrackerContext()))
            {
                unitOfWork.WorkoutCollection.Add(workout);
                var result = unitOfWork.Complete();
                return(result == 1);
            }
        }
 private void LoadComboBox()
 {
     workoutDTO               = workoutBLL.GetWorkouts();
     cmbWorkout.DataSource    = workoutDTO.Workouts;
     cmbWorkout.DisplayMember = "Name";
     cmbWorkout.ValueMember   = "ID";
     if (IsUpdate)
     {
         cmbWorkout.SelectedValue = detailDTO.ID;
     }
 }
Esempio n. 8
0
        public IHttpActionResult Put(int id, WorkoutDTO workoutDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var result = _workoutBAL.UpdateWorkout(id, workoutDTO);

            return(Ok(result));
        }
Esempio n. 9
0
        private WorkoutDTO MapWorkout(Workout model)
        {
            var modelDTO = new WorkoutDTO
            {
                Id              = model.Id,
                WorkoutDate     = model.WorkoutDate,
                Exercises       = new List <Exercise>(model.Exercises),
                ApplicationUser = model.ApplicationUser
            };

            return(modelDTO);
        }
Esempio n. 10
0
        public void ValidateWorkoutModel_InvalidWorkoutTitle_ReturnsFalse()
        {
            var categoryDTO = new WorkoutDTO()
            {
                WorkoutTitle = string.Empty
            };

            var context           = new System.ComponentModel.DataAnnotations.ValidationContext(categoryDTO, null, null);
            var results           = new List <ValidationResult>();
            var isModelStateValid = Validator.TryValidateObject(categoryDTO, context, results, true);

            Assert.IsFalse(isModelStateValid);
        }
Esempio n. 11
0
        public async Task <IActionResult> SaveWorkout([FromBody] WorkoutDTO item)
        {
            _logger.LogInformation("Saving Workout");
            WorkoutDTO savedWorkout = await _mediator.Send <WorkoutDTO>(new SaveWorkoutCommand()
            {
                Workout = item
            });

            await _mediator.Send <Unit>(new SaveWorkoutToEventBusCommand()
            {
                Workout = savedWorkout
            });                                                                                         // send to event bus

            return(Ok(savedWorkout));
        }
 public CreateWorkoutPageViewModel(INavigationService navigationService, IDatabaseService dbService) :
     base(navigationService, dbService)
 {
     IsValidModel = false;
     NewWorkout   = new WorkoutDTO()
     {
         User = CurrentUser,
     };
     NewWorkout.ValidName.Value = string.Empty;
     NewWorkout.ValidName.Validations.Add(new MinimumSixCharRule <string>()
     {
         ValidationMessage = ValidationMessages.StringMustBeSixLengthLong
     });
     AllExercise      = _context.Exercises.Include(e => e.MuscleGroup).ToList();
     DisplayExercises = new ObservableCollection <Exercise>(AllExercise);
     AddedExercises   = new ObservableCollection <ExerciseItemDTO>();
 }
Esempio n. 13
0
        public bool UpdateWorkout(int id, WorkoutDTO workoutDTO)
        {
            int result = 0;

            using (var unitOfWork = new UnitOfWork(new WorkoutTrackerContext()))
            {
                var workoutInDB = unitOfWork.WorkoutCollection.Get(id);

                if (workoutInDB != null)
                {
                    workoutDTO.WorkoutId = id;
                    Mapper.Map(workoutDTO, workoutInDB);
                    result = unitOfWork.Complete();
                }

                return(result == 1);
            }
        }
Esempio n. 14
0
        private WorkoutViewModel MapWorkoutDTO(WorkoutDTO model)
        {
            var exercises = new List <ExerciseViewModel>();

            foreach (var exercise in model.Exercises)
            {
                exercises.Add(MapExercise(exercise));
            }
            var viewModel = new WorkoutViewModel
            {
                Id          = model.Id,
                WorkoutDate = model.WorkoutDate,
                Exercises   = exercises,
                TotalWeight = String.Format("{0:0.##}", Math.Round(model.TotalWeight, 2))
            };

            return(viewModel);
        }
 public override void OnNavigatedTo(NavigationParameters parameters)
 {
     base.OnNavigatedTo(parameters);
     SubscribeForEvents();
     if (parameters[NavigationParamterKeys.WorkoutId] is string workoutId)
     {
         isEditMode = true;
         NewWorkout = new WorkoutDTO(_context.Workouts
                                     .Include(w => w.ExerciseItems)
                                     .ThenInclude(e => e.Exercise)
                                     .SingleOrDefault(w => w.Id.Equals(workoutId)));
         foreach (var item in NewWorkout.ExerciseItems)
         {
             item.IsEditable = true;
         }
         NewWorkout.ValidName.Value = NewWorkout.Name;
         AddedExercises             = new ObservableCollection <ExerciseItemDTO>(NewWorkout.ExerciseItems);
     }
 }
 public void ShowWorkouts()
 {
     bll = new WorkoutBLL();
     if (isSearch)
     {
         dto = bll.GetWorkouts(keyword);
     }
     else
     {
         dto = bll.GetWorkouts();
     }
     dataGridView1.DataSource = dto.Workouts;
     dataGridView1.Columns["ID"].HeaderText            = "編號";
     dataGridView1.Columns["Name"].HeaderText          = "名稱";
     dataGridView1.Columns["Calories"].HeaderText      = "卡路里";
     dataGridView1.Columns["ActivityLevel"].HeaderText = "活動強度";
     dataGridView1.Columns["CategoryName"].HeaderText  = "類別";
     dataGridView1.Columns["CategoryID"].Visible       = false;
     dataGridView1.Columns["ActivityLevelID"].Visible  = false;
     isSearch = false;
 }
Esempio n. 17
0
 private void SubscribeEvents()
 {
     MessagingCenter.Subscribe <ExerciseItem, ExerciseItem>(this, MessagingKeys.EditExerciseItem, (s, a) =>
     {
         Workout.ExerciseItems[Workout.ExerciseItems.FindIndex(e => e.Id == a.Id)] = new ExerciseItemDTO(a);
         var cWorkout = _context.Workouts.SingleOrDefault(w => w.Id.Equals(Workout.Id));
         _context.Workouts.Update(cWorkout);
         RaisePropertyChanged(nameof(Workout.ExerciseItems));
     });
     MessagingCenter.Subscribe <ExerciseItem, ExerciseItem>(this, MessagingKeys.DeleteExerciseItem, (s, a) =>
     {
         var toDeleteItem = Workout.ExerciseItems.SingleOrDefault(e => e.Id == a.Id);
         Workout.ExerciseItems.Remove(toDeleteItem);
         RaisePropertyChanged(nameof(Workout.ExerciseItems));
         var cWorkout = _context.Workouts.SingleOrDefault(w => w.Id.Equals(Workout.Id));
         _context.Workouts.Update(cWorkout);
     });
     MessagingCenter.Subscribe <CreateWorkoutPageViewModel, Workout>(this, MessagingKeys.BackPressed, (s, a) =>
     {
         Workout = new WorkoutDTO(a);
     });
 }
Esempio n. 18
0
        public void AddNewWorkout_ValidWorkout_ReturnsTrue()
        {
            IHttpActionResult actionResult = _categoryController.Get();
            var contentResult = actionResult as OkNegotiatedContentResult <IOrderedEnumerable <CategoryDTO> >;

            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);

            var category = contentResult.Content.FirstOrDefault();

            var workout = new WorkoutDTO()
            {
                WorkoutTitle = "Workout Title",
                WorkoutNote  = "Workout Note",
                CategoryId   = category.CategoryId
            };

            IHttpActionResult postActionResult = _workoutController.Post(workout);
            var postContentResult = postActionResult as OkNegotiatedContentResult <bool>;

            Assert.IsNotNull(postActionResult);
            Assert.IsNotNull(postContentResult.Content);
            Assert.IsTrue(postContentResult.Content);
        }
Esempio n. 19
0
 public WorkoutDetailPageViewModel(INavigationService navigationService, IDatabaseService dbService) :
     base(navigationService, dbService)
 {
     Workout = new WorkoutDTO();
 }
Esempio n. 20
0
        public async Task <IActionResult> UpdateWorkoutDescription([FromBody] WorkoutDTO workoutDTO)
        {
            var result = await _workoutService.UpdateWorkoutDescriptionAsync(workoutDTO);

            return(Ok(result));
        }
Esempio n. 21
0
        public async Task <IActionResult> Post([FromBody] WorkoutDTO workoutDTO)
        {
            var result = await _workoutService.CreateWorkoutAsync(workoutDTO);

            return(Ok(result));
        }