public async void CompleteTreino(int id)
        {
            var diario = _context.Diario.Where(x => x.DiarioID == id).FirstOrDefault();

            diario.CompletoTreino = true;
            _context.Update(diario);
            await _context.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int?id, [Bind("PlanoID,TreinoID,DietaID,SemanaInicio,Selecionado,PlanoNome,Duracao,Completo")] Plano param)
        {
            if (id != param.PlanoID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var user = await _userManager.GetUserAsync(HttpContext.User);

                    param.UserID = user.Id;
                    _context.Update(param);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlanoExists(param.PlanoID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(param));
        }
        public async Task <IActionResult> Edit(int?id, string salvar, [Bind("SemanaID,TreinoID,TreinoNome,Texto,DataTreino,Completo")] TreinoSemanaViewModel vm)
        {
            if (id != vm.TreinoID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Treino treino = new Treino
                    {
                        TreinoID   = vm.TreinoID,
                        Completo   = vm.Completo,
                        DataTreino = vm.DataTreino,
                        TreinoNome = vm.TreinoNome
                    };
                    _context.Update(treino);

                    TreinoSemana treinoSemana = new TreinoSemana
                    {
                        SemanaID   = vm.SemanaID,
                        DescTreino = vm.Texto,
                        TreinoID   = vm.TreinoID
                    };

                    if (_context.TreinoSemana.Any(o => o.SemanaID == vm.SemanaID))
                    {
                        _context.Update(treinoSemana);
                    }

                    else
                    {
                        if (_context.Semana.Any(o => o.SemanaID == vm.SemanaID))
                        {
                            AddOneWeek();
                        }

                        _context.TreinoSemana.Add(treinoSemana);
                    }


                    await _context.SaveChangesAsync();

                    if (salvar.Equals("Próxima Semana"))
                    {
                        if (vm.SemanaID == null)
                        {
                            vm.SemanaID = 1;
                        }
                        TempData["SemanaID"] = vm.SemanaID + 1;
                        return(View(Edit(vm.TreinoID, null)));
                    }

                    else if (salvar.Equals("Salvar"))
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TreinoExists(vm.TreinoID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction(nameof(Index));
            }

            return(View(vm));
        }
        public async Task <IActionResult> Edit(int?id, string salvar, [Bind("SemanaID,DietaID,DietaNome,Texto,DataDieta,Completo")] DietaSemanaViewModel vm)
        {
            if (id != vm.DietaID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Dieta dieta = new Dieta
                    {
                        DietaID   = vm.DietaID,
                        Completo  = vm.Completo,
                        DataDieta = vm.DataDieta,
                        DietaNome = vm.DietaNome
                    };
                    _context.Update(dieta);

                    DietaSemana dietaSemana = new DietaSemana
                    {
                        SemanaID  = vm.SemanaID,
                        DescDieta = vm.Texto,
                        DietaID   = vm.DietaID
                    };

                    if (_context.DietaSemana.Any(o => o.SemanaID == vm.SemanaID))
                    {
                        _context.Update(dietaSemana);
                    }

                    else
                    {
                        if (_context.Semana.Any(o => o.SemanaID == vm.SemanaID))
                        {
                            AddOneWeek();
                        }

                        _context.DietaSemana.Add(dietaSemana);
                    }

                    await _context.SaveChangesAsync();

                    if (salvar.Equals("Próxima Semana"))
                    {
                        if (vm.SemanaID == null)
                        {
                            vm.SemanaID = 1;
                        }
                        TempData["SemanaID"] = vm.SemanaID + 1;
                        vm.SemanaID++;
                        return(RedirectToAction("Edit", new { id = vm.DietaID, semana = vm.SemanaID }));
                    }

                    else if (salvar.Equals("Salvar"))
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DietaExists(vm.DietaID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction(nameof(Index));
            }
            return(View(vm));
        }