public async Task <IActionResult> OnGetAsync() { Input = new WeightLogViewModel() { LogDate = DateTime.Now }; ApplicationUser user = await GetUser(); MeasureType = user.MeasureType; return(Page()); }
public async Task <IActionResult> Edit(Guid id) { WeightLog weightLog = await _weigtLogManageService.FindWeightLogById(id); var user = await _applicationUserService.GetUserByName(this.User.Identity.Name); ViewBag.MeasureType = user.MeasureType; if (user.MeasureType == Enums.MeasureType.lbs) { weightLog = WeightConverter.ConvertToLbs(weightLog); } WeightLogViewModel weightLogViewModel = _mapper.Map <WeightLogViewModel>(weightLog); return(View(weightLogViewModel)); }
public async Task <IActionResult> OnGet(Guid id) { var log = await _weigtLogService.FindWeightLogById(id); var user = await GetUser(); MeasureType = user.MeasureType; if (user.MeasureType == MeasureType.lbs) { log = WeightConverter.ConvertToLbs(log); } Input = _mapper.Map <WeightLogViewModel>(log); return(Page()); }
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)); }