Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int?id, CardioViewModel viewModel)
        {
            if (id == null)
            {
                id = 0;
            }
            try
            {
                if (ModelState.IsValid)
                {
                    var saving1 = await _cardioRepository.AddOrEditCardioAsync(viewModel, (int)id);

                    if (saving1 != 0)
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            return(View(viewModel));
        }
        // GET: CardiovascularFitness
        public ActionResult Index()
        {
            string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            //Func<BaseModel, bool> predicate = a => a.Owner == owner; // THis doesn't work in linq to entities
            var vm = new CardioViewModel()
            {
                HalfMile  = db.HalfMileTimes.Where(a => a.Owner == owner).OrderByDescending(x => x.Logged).ToList(),
                HeartRate = db.HeartRates.Where(a => a.Owner == owner).OrderByDescending(x => x.Logged).ToList(),
                Mile      = db.MileTimes.Where(a => a.Owner == owner).OrderByDescending(x => x.Logged).ToList(),
                Pacer     = db.Pacers.Where(a => a.Owner == owner).OrderByDescending(x => x.Logged).ToList(),
                StepTest  = db.StepTests.Where(a => a.Owner == owner).OrderByDescending(x => x.Logged).ToList()
            };

            return(View(vm));
        }
Ejemplo n.º 3
0
        public async Task <int> AddOrEditCardioAsync(CardioViewModel viewModel, int id = 0)
        {
            var Cardio = await GetCardioAsync(id) ?? new Cardio();

            Cardio.Name       = viewModel.Name;
            Cardio.CalPerHour = viewModel.CalPerHour;
            if (id == 0)
            {
                context.Cardio.Add(Cardio);
                context.SaveChanges();

                return(GetCardio(Cardio.Name).CardioID);
            }

            context.SaveChanges();
            return(id);
        }
Ejemplo n.º 4
0
        // GET: Cardio/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(View());
            }
            var cardio = await _cardioRepository.GetCardioAsync((int)id);

            if (cardio == null)
            {
                return(View());
            }

            var viewModel = new CardioViewModel
            {
                Name       = cardio.Name,
                CalPerHour = cardio.CalPerHour,
            };

            return(View(viewModel));
        }