public ActionResult Inscrever(AtletaVM model)
        {
            //var inscricao = model.Inscricoes;
            //inscricao.IdAtleta = model.Atleta.Id;
            //inscricao.IdCampanha = model.Campanha.Id;

            //db.Inscricoes.Add(inscricao);
            db.Inscricoes.Add(model.Inscricao);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult Salvar(Campanha model)
        {
            if (model.Id != 0)
            {
                db.Entry <Campanha>(model).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                model.Criacao = DateTime.Today;
                db.Campanhas.Add(model);
            }

            db.SaveChanges();
            return(RedirectToAction("../Campanhas"));
        }
Exemplo n.º 3
0
        public ActionResult Novo(AtletaVM model)
        {
            var usuarioExistente = db.Usuarios.Where(x => x.Login == model.Usuario.Login).FirstOrDefault();

            if (usuarioExistente == null)
            {
                string senha = FormsAuthentication.HashPasswordForStoringInConfigFile(model.Usuario.Senha, "md5");
                model.Usuario.Senha        = senha;
                model.Usuario.DataCadastro = DateTime.Today;
                model.Atleta.DataInscricao = DateTime.Today;


                //db.Atletas.Add(model.Atleta);
                //db.Usuarios.Add(model.Usuario);
                //db.SaveChanges();
                try
                {
                    db.Usuarios.Add(model.Usuario);
                    db.SaveChanges();
                    model.Usuario          = db.Usuarios.Where(x => x.Login == model.Usuario.Login && x.Senha == senha).FirstOrDefault();
                    model.Atleta.IdUsuario = model.Usuario.Id;

                    db.Atletas.Add(model.Atleta);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    ViewBag.Erro = "Erro ao tentar salvar cadastro do atleta. " + ex.Message;
                }


                Session["usuario"] = model;
                return(RedirectToAction("Index"));
                //return View(model);
            }
            else
            {
                //ModelState.AddModelError("erro", "Usuário já existente. Escolha outro antes de salvar novamente.");
                ViewBag.Erro = "Usuário já existente. Escolha outro antes de salvar novamente.";
                return(View(model));
            }
        }
Exemplo n.º 4
0
        public static async Task AddAsync(User user, BPContext context)
        {
            if (string.IsNullOrEmpty(user?.Username) || string.IsNullOrEmpty(user?.Password))
            {
                throw new Exception("Invalid username or password");
            }


            user.Password = ComputeHash(user.Password);
            await context.Users.AddAsync(user);

            context.SaveChanges();
        }
Exemplo n.º 5
0
 public void TogglePaid(int id)
 {
     using (var context = new BPContext())
     {
         var perf = context.Performances.FirstOrDefault(g => g.ID == id);
         if (perf != null)
         {
             perf.Paid = !perf.Paid;
             context.SaveChanges();
         }
         else
         {
             throw new System.Exception("Could not find performance");
         }
     }
 }
Exemplo n.º 6
0
 public int Commit()
 {
     return(_db.SaveChanges());
 }