Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(TableWeightLogViewModel weightLogViewModel)
        {
            var user = await _applicationUserService.GetUserByName(this.User.Identity.Name);

            if (user.MeasureType == Enums.MeasureType.lbs)
            {
                weightLogViewModel.WeightValue = WeightConverter.ConvertToKg(_mapper.Map <WeightLog>(weightLogViewModel)).WeightValue;
            }

            await _weigtLogManageService.UpdateWeightLog(weightLogViewModel);

            return(RedirectToAction(nameof(TableController.Index), "Table"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(WeightLogViewModel weightLogViewModel)
        {
            if (ModelState.IsValid)
            {
                WeightLog newWeightLog = _mapper.Map <WeightLog>(weightLogViewModel);

                var user = await _applicationUserService.GetUserByName(this.User.Identity.Name);

                newWeightLog.User = user;
                newWeightLog      = user.MeasureType == Enums.MeasureType.lbs ? WeightConverter.ConvertToKg(newWeightLog) : newWeightLog;

                await _weigtLogManageService.Add(newWeightLog);

                return(RedirectToAction(nameof(TableController.Index), "Table"));;
            }

            return(View(weightLogViewModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var newLog = _mapper.Map <FC_MVVC.Data.Models.WeightLog>(Input);

                ApplicationUser user = await GetUser();

                if (user.MeasureType == MeasureType.lbs)
                {
                    newLog = WeightConverter.ConvertToKg(newLog);
                }

                newLog.User = user;

                await _weigtLogService.Add(newLog);

                return(RedirectToPage("/Table/Index"));
            }
            return(Page());
        }