public ActionResult Create([Bind(Include = "ID,Code,Name")] Country country)
        {
            if (ModelState.IsValid)
            {
                db.Countries.Add(country);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(country));
        }
Example #2
0
        public ActionResult Create([Bind(Include = "ID,CountryID,Confirmed,Deaths,Recovered,Active,Date")] Case @case)
        {
            if (ModelState.IsValid)
            {
                db.Cases.Add(@case);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CountryID = new SelectList(db.Countries, "ID", "Name", @case.CountryID);
            return(View(@case));
        }
Example #3
0
        public IActionResult Criar(string pais, string casos, string mortes, string recuperados)
        {
            using (var db = new CovidContext())
            {
                // Se existir o paĆ­s:
                if (db.Infeccoes.Where(infeccao => infeccao.Pais.Nome == pais).Any())
                {
                    var inf = db.Infeccoes.Where(infeccao => infeccao.Pais.Nome == pais).First();
                    inf.CasosConfirmados = int.Parse(casos);
                    inf.Mortes           = int.Parse(mortes);
                    inf.Recuperados      = int.Parse(recuperados);
                    db.Update(inf);
                }
                else
                {
                    var novopais = new PaisModel();
                    novopais.Nome = pais;
                    var novainfection = new InfeccaoModel();
                    novainfection.CasosConfirmados = int.Parse(casos);
                    novainfection.Mortes           = int.Parse(mortes);
                    novainfection.Recuperados      = int.Parse(recuperados);

                    novopais.Infeccao = novainfection;
                    db.Infeccoes.Add(novainfection);
                    db.Paises.Add(novopais);
                }
                db.SaveChanges();

                var infeccoes = db.Infeccoes.ToList();
                db.Paises.ToList();
                ViewData["Infeccoes"] = infeccoes;
                return(View("Painel"));
            }
        }
Example #4
0
 public void InsertUser(User user)
 {
     if (user != null)
     {
         user.CreatedAt = DateTime.Now;
         user.UpdatedAt = DateTime.Now;
         user.Password  = CryptPassword(user.Password);
         _context.User.Add(user);
         _context.SaveChanges();
     }
 }
Example #5
0
        public static void Update(Entity entity)
        {
            if (entity.Id == 0)
            {
                Insert(entity);
                return;
            }

            using (var context = new CovidContext())
            {
                context.Update(entity);
                context.SaveChanges();
            }
        }
Example #6
0
        public IActionResult Remover(string infeccaoId)
        {
            using (var db = new CovidContext())
            {
                db.Infeccoes.Remove(db.Infeccoes.Where(i => i.InfeccaoId == int.Parse(infeccaoId)).First());

                db.SaveChanges();

                var infeccoes = db.Infeccoes.ToList();
                db.Paises.ToList();

                ViewData["Infeccoes"] = infeccoes;
                return(View("Painel"));
            }
        }
Example #7
0
        //public ICourseRepository Courses { get; private set; }
        //public IAuthorRepository Authors { get; private set; }

        public int Complete()
        {
            return(_context.SaveChanges());
        }
Example #8
0
 public void Commit()
 {
     _context.SaveChanges();
 }
Example #9
0
 public void ApplyOffer(UserAppliedOffer userAppliedOffer)
 {
     userAppliedOffer.CreatedAt = DateTime.Now;
     _context.UserAppliedOffer.Add(userAppliedOffer);
     _context.SaveChanges();
 }
Example #10
0
 public int SaveChanges()
 {
     return(Db.SaveChanges());
 }