Ejemplo n.º 1
0
        public PartialViewResult EditGoal(AssessmentGoalPrimaryKey assessmentGoalPrimaryKey)
        {
            var assessmentGoal = assessmentGoalPrimaryKey.EntityObject;
            var viewModel      = new EditGoalViewModel(assessmentGoal);

            return(ViewEdit(viewModel));
        }
Ejemplo n.º 2
0
        public IActionResult Edit(int goalId)
        {
            Goal goal = logic.GetSingle(goalId);

            int id = Convert.ToInt32(User.Claims.Where(c => c.Type == "Id")
                                     .Select(c => c.Value).SingleOrDefault());

            if (goal.UserId != id)
            {
                return(RedirectToAction("Index"));
            }

            var model = new EditGoalViewModel()
            {
                GoalId   = goal.GoalId,
                UserId   = goal.UserId,
                Title    = goal.Title,
                Info     = goal.Info,
                StartDT  = goal.StartDT,
                EndDT    = goal.EndDT,
                Progress = goal.Progress,
                Status   = goal.Status,
                Strikes  = goal.Strikes
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Creates an instance of the <see cref="ManageGoalsViewModel" /> class.
        /// </summary>
        /// <param name="goals">The goals.</param>
        /// <returns>
        ///     The view model.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     goals
        ///     Exception thrown if the goals are null.
        /// </exception>
        public ManageGoalsViewModel NewManageGoalsViewModel(IList <GoalProxy> goals)
        {
            if (goals == null)
            {
                throw new ArgumentNullException(nameof(goals));
            }

            var addModel = new AddGoalViewModel
            {
                Goal =
                    new GoalViewModel
                {
                    Amount    = 0,
                    Complete  = false,
                    EndDate   = DateTime.Now.AddMonths(6),
                    Name      = string.Empty,
                    Id        = Guid.Empty,
                    StartDate = DateTime.Now
                }
            };

            var editModel = new EditGoalViewModel {
                Goal = new GoalViewModel()
            };

            var retVal = new ManageGoalsViewModel
            {
                AddGoal  = addModel,
                EditGoal = editModel,
                Goals    = goals.Select(ProxyToViewModel).ToList()
            };

            return(retVal);
        }
Ejemplo n.º 4
0
        public IActionResult EditUserGoal(EditGoalViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var goal = new Goal()
            {
                GoalId   = model.GoalId,
                UserId   = model.UserId,
                Title    = model.Title,
                Info     = model.Info,
                StartDT  = model.StartDT,
                EndDT    = model.EndDT,
                Progress = model.Progress,
                Status   = model.Status,
                Strikes  = model.Strikes
            };

            bool edited = logic.Edit(goal);

            if (!edited)
            {
                ModelState.AddModelError("", "Editing failed.");

                return(View(model));
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public static Goal ToModel(this EditGoalViewModel viewModel)
        {
            var date = DateTime.UtcNow;

            return(new Goal
            {
                Id = viewModel.Id,
                Name = viewModel.Name,
                Description = viewModel.Description,
                ModificationDate = date
            });
        }
 private Goal MapEditGoalViewModelToGoal(EditGoalViewModel model)
 {
     return(new Goal
     {
         Id = model.Id,
         Name = model.Name,
         Category = model.Category,
         Progress = model.Progress,
         Description = model.Descirption,
         DueDateTime = model.DueDateTime,
         Duration = model.Duration,
         StartDate = model.StartTime,
     });
 }
Ejemplo n.º 7
0
        public async Task <ActionResult> Edit([Bind("Id", "Name", "Description", "State")] EditGoalViewModel goal)
        {
            if (ModelState.IsValid)
            {
                var g = _goals.Get(x => x.UserId == GetUserId() && x.Id == goal.Id).Single();

                g.Name             = goal.Name;
                g.Description      = goal.Description;
                g.ModificationDate = DateTime.UtcNow;
                g.State            = goal.State;

                await _goals.UpdateAsync(g);

                return(RedirectToAction("Index"));
            }

            return(View(goal));
        }
        public ActionResult Edit(Guid id, EditGoalViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _service.Update(MapEditGoalViewModelToGoal(model));
                }
                // TODO: Add update logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                ModelState.AddModelError(string.Empty, "Unexpected error");
                return(View(model));
            }
        }
Ejemplo n.º 9
0
        public IActionResult EditUserGoal(int GoalId)
        {
            Goal goal = logic.GetSingle(GoalId);

            var model = new EditGoalViewModel()
            {
                GoalId   = goal.GoalId,
                UserId   = goal.UserId,
                Title    = goal.Title,
                Info     = goal.Info,
                StartDT  = goal.StartDT,
                EndDT    = goal.EndDT,
                Progress = goal.Progress,
                Status   = goal.Status,
                Strikes  = goal.Strikes
            };

            return(View(model));
        }
Ejemplo n.º 10
0
        public IActionResult Index(int NewStatus, EditGoalViewModel model)
        {
            var goal = new Goal()
            {
                GoalId   = model.GoalId,
                UserId   = model.UserId,
                Title    = model.Title,
                Info     = model.Info,
                StartDT  = model.StartDT,
                EndDT    = model.EndDT,
                Progress = model.Progress,
                Status   = (GoalStatus)NewStatus,
                Strikes  = model.Strikes
            };

            var edited = logic.Edit(goal);

            if (!edited)
            {
                throw new Exception("Editing failed.");
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 11
0
 public EditGoalPage()
 {
     InitializeComponent();
     BindingContext = new EditGoalViewModel();
 }
Ejemplo n.º 12
0
        private PartialViewResult ViewEdit(EditGoalViewModel viewModel)
        {
            var viewData = new EditGoalViewData();

            return(RazorPartialView <EditGoal, EditGoalViewData, EditGoalViewModel>(viewData, viewModel));
        }
Ejemplo n.º 13
0
        public ActionResult EditGoal(AssessmentGoalPrimaryKey assessmentGoalPrimaryKey, EditGoalViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(ViewEdit(viewModel));
            }
            var goal = assessmentGoalPrimaryKey.EntityObject;

            viewModel.UpdateModel(goal, CurrentFirmaSession);
            return(new ModalDialogFormJsonResult());
        }
Ejemplo n.º 14
0
        public ActionResult NewGoalForm()
        {
            //If no goal found, fetch blank goal page. If existing goal found, fetch existing info into page
            EditGoalViewModel viewModel;
            var    userProfileId      = Helper_Classes.UserHelpers.GetUserProfile().Id;
            string startWeightInputA  = "";
            string startWeightInputB  = "";
            string targetWeightInputA = "";
            string targetWeightInputB = "";

            string weightUnit = Helper_Classes.UserHelpers.GetWeightUnit();
            var    dbGoal     = _context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId);



            //No existing goal
            if (_context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId) == null)
            {
                viewModel = new EditGoalViewModel()
                {
                    Goal = new Goal
                    {
                        UserProfileId = userProfileId,
                        StartDate     = DateTime.Today,
                        EndDate       = DateTime.Today.AddDays(30)
                    },
                    StartWeightInputA  = startWeightInputA,
                    StartWeightInputB  = startWeightInputB,
                    TargetWeightInputA = targetWeightInputA,
                    TargetWeightInputB = targetWeightInputB,
                    WeightUnit         = weightUnit,
                    Title            = "New Goal",
                    CalculationBasis = new SelectList(new List <string> {
                        "Weight", "Body Fat"
                    }, "Weight")
                }
            }
            ;
            //Existing goal
            else
            {
                double startWeight  = _context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId).StartWeightInKg;
                double targetWeight = _context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId).TargetWeightInKg;
                if (weightUnit.Equals(WeightUnits.Kg))
                {
                    startWeightInputA  = Convert.ToInt32(startWeight).ToString();
                    targetWeightInputA = Convert.ToInt32(targetWeight).ToString();
                }
                if (weightUnit.Equals(WeightUnits.Lbs))
                {
                    startWeightInputA  = Convert.ToInt32(Calculators.KgsToLbs(startWeight)).ToString();
                    targetWeightInputA = Convert.ToInt32(Calculators.KgsToLbs(targetWeight)).ToString();
                }
                else if (weightUnit == WeightUnits.LbsAndStone)
                {
                    startWeightInputA  = Convert.ToInt32(Calculators.KgsToStone(startWeight)).ToString();
                    startWeightInputB  = Convert.ToInt32(Calculators.KgsToLbsRemainingFromStone(startWeight)).ToString();
                    targetWeightInputA = Convert.ToInt32(Calculators.KgsToStone(targetWeight)).ToString();
                    targetWeightInputB = Convert.ToInt32(Calculators.KgsToLbsRemainingFromStone(targetWeight)).ToString();
                }

                viewModel = new EditGoalViewModel
                {
                    Goal = dbGoal,
                    StartWeightInputA  = startWeightInputA,
                    StartWeightInputB  = startWeightInputB,
                    TargetWeightInputA = targetWeightInputA,
                    TargetWeightInputB = targetWeightInputB,
                    WeightUnit         = weightUnit,
                    Title            = "Edit Goal",
                    CalculationBasis = new SelectList(new List <string> {
                        "Weight", "Body Fat"
                    }, dbGoal.CalculationBasis)
                };
            }

            viewModel.StartBodyFat  = viewModel.Goal.StartBodyFat;
            viewModel.TargetBodyFat = viewModel.Goal.TargetBodyFat;
            viewModel.TrackBodyFat  = viewModel.Goal.TrackBodyFat;

            return(View(viewModel));
        }
Ejemplo n.º 15
0
        public ActionResult AddNewGoal(EditGoalViewModel newGoal)
        {
            currentUserProfile = Helper_Classes.UserHelpers.GetUserProfile();
            var userProfileId = Helper_Classes.UserHelpers.GetUserProfile().Id;
            var dbGoal        = _context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId);

            newGoal.CalculationBasis = _context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId) == null
                ? new SelectList(new List <string> {
                "Weight", "Body Fat"
            }, newGoal.CalculationBasisChoice)
                : new SelectList(new List <string> {
                "Weight", "Body Fat"
            }, dbGoal.CalculationBasis);
            newGoal.Title = "Edit Goal";

            if (!ModelState.IsValid)
            {
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        System.Diagnostics.Debug.WriteLine(error);
                    }
                }
                return(View("NewGoalForm", newGoal));
            }

            newGoal.Goal.StartBodyFat  = newGoal.StartBodyFat;
            newGoal.Goal.TargetBodyFat = newGoal.TargetBodyFat;
            newGoal.Goal.TrackBodyFat  = newGoal.TrackBodyFat;

            var trackBf = newGoal.Goal.TrackBodyFat;

            var calculationBasis = newGoal.CalculationBasisChoice;


            double startWeight  = 0.0;
            double targetWeight = 0.0;

            if (newGoal.AddAsCheckIn && newGoal.Goal.StartDate <= DateTime.Today)
            {
                var checkInModel = new CheckInFormViewModel
                {
                    WeightUnit      = newGoal.WeightUnit,
                    WeightInputA    = newGoal.StartWeightInputA,
                    WeightInputB    = newGoal.StartWeightInputB,
                    UserProgressLog = new UserProgressLog
                    {
                        Date    = newGoal.Goal.StartDate,
                        BodyFat = newGoal.Goal.StartBodyFat
                    }
                };
                UpdateDbWithNewCheckIn(checkInModel);
            }


            if (Helper_Classes.UserHelpers.GetWeightUnit().Equals(WeightUnits.Kg))
            {
                startWeight  = Convert.ToDouble(newGoal.StartWeightInputA);
                targetWeight = Convert.ToDouble(newGoal.TargetWeightInputA);
            }
            else if (Helper_Classes.UserHelpers.GetWeightUnit().Equals(WeightUnits.Lbs))
            {
                startWeight  = Calculators.LbsToKG(Convert.ToDouble(newGoal.StartWeightInputA));
                targetWeight = Calculators.LbsToKG(Convert.ToDouble(newGoal.TargetWeightInputA));
            }
            else if (Helper_Classes.UserHelpers.GetWeightUnit().Equals(WeightUnits.LbsAndStone))
            {
                startWeight = Calculators.StToKg(Convert.ToDouble(newGoal.StartWeightInputA)) +
                              Calculators.LbsToKG(Convert.ToDouble(newGoal.StartWeightInputB));

                targetWeight = Calculators.StToKg(Convert.ToDouble(newGoal.TargetWeightInputA)) +
                               Calculators.LbsToKG(Convert.ToDouble(newGoal.TargetWeightInputB));
            }


            newGoal.Goal.StartWeightInKg  = startWeight;
            newGoal.Goal.TargetWeightInKg = targetWeight;

            //TODO latest checkin always updates final weight on goal

            newGoal.Goal.CalculationBasis = (string)calculationBasis;

            //No Goal Id on user profile. Add it
            if (_context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId) == null)
            {
                newGoal.Goal.UserProfileId = userProfileId;
                _context.Goals.Add(newGoal.Goal);
            }
            else
            {
                //Update the existing Goal record
                _context.Entry(_context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId))
                .CurrentValues
                .SetValues(newGoal.Goal);
            }
            _context.SaveChanges();


            //Overwrite new target weight with estimated one if using body fat to calculate goal - ordering is important here as the db needs to have been updated already
            if (calculationBasis.Equals(CalculationBasis.BodyFat))
            {
                targetWeight = Calculators.CalculateEstimatedGoalWeight((double)Helper_Classes.UserHelpers.GetCurrentWeight(),
                                                                        (int)Helper_Classes.UserHelpers.GetCurrentBodyFat(), (int)newGoal.Goal.TargetBodyFat);

                newGoal.Goal.TargetWeightInKg = targetWeight;

                _context.Entry(_context.Goals.SingleOrDefault(g => g.UserProfileId == userProfileId))
                .CurrentValues
                .SetValues(newGoal.Goal);

                _context.SaveChanges();
            }



            return(RedirectToAction("Index", new { controller = "Home" }));
        }
Ejemplo n.º 16
0
        public welcome_page3()
        {
            InitializeComponent();

            BindingContext = new EditGoalViewModel();
        }