public PhysicalActivityViewModel GetPhysicalActivityViewModel(PhysicalActivity physicalActivity)
        {
            var result = new PhysicalActivityViewModel
            {
                Name            = physicalActivity.Name,
                Date            = DateTime.Now,
                DistanceCovered = physicalActivity.DistanceCovered,
                TimeEnded       = physicalActivity.TimeEnded,
                TimeStarted     = physicalActivity.TimeStarted,
            };

            return(result);
        }
        public PhysicalActivity GetPhysicalActivity(PhysicalActivityViewModel viewModel)
        {
            var result = new PhysicalActivity
            {
                Name            = viewModel.Name,
                Date            = DateTime.Now,
                DistanceCovered = viewModel.DistanceCovered,
                TimeEnded       = viewModel.TimeEnded,
                TimeStarted     = viewModel.TimeStarted,
            };

            return(result);
        }
예제 #3
0
        public IActionResult CyclingCounter(PhysicalActivityViewModel viewModel, DateTime startedDate, string startedHour, DateTime endedDate, string endedHour)
        {
            startedDate = startedDate.AddHours(double.Parse(startedHour.Substring(0, 2)));
            startedDate = startedDate.AddMinutes(double.Parse(startedHour.Substring(3)));

            endedDate = endedDate.AddHours(double.Parse(endedHour.Substring(0, 2)));
            endedDate = endedDate.AddMinutes(double.Parse(endedHour.Substring(3)));

            var username = this.User.Identity.Name;

            viewModel.Name        = "Cycling";
            viewModel.TimeStarted = startedDate;
            viewModel.TimeEnded   = endedDate;
            this.dbManager.RecordActivity(viewModel, username);

            return(this.View());
        }
예제 #4
0
        public void RecordActivity(PhysicalActivityViewModel viewModel, string username)
        {
            var user = dbContext.Users
                       .Include(u => u.PhyiscalActivities)
                       .Where(u => u.UserName == username)
                       .FirstOrDefault();

            var physicalActivity = this.adaptor.GetPhysicalActivity(viewModel);

            user.PhyiscalActivities.Add(physicalActivity);
            dbContext.SaveChanges();

            //if (user.PhyiscalActivities.Where(p => p.Date.Day == DateTime.Now.Day && p.Name == "Run").ToList().Count == 0)
            //{

            //}
            //else
            //{
            //    user.PhyiscalActivities[user.PhyiscalActivities.FindIndex(p => p.UserId == physicalActivity.UserId)] = physicalActivity;
            //    dbContext.SaveChanges();
            //}
        }