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)); }
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)); }
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")); } }
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(); } }
public static void Update(Entity entity) { if (entity.Id == 0) { Insert(entity); return; } using (var context = new CovidContext()) { context.Update(entity); context.SaveChanges(); } }
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")); } }
//public ICourseRepository Courses { get; private set; } //public IAuthorRepository Authors { get; private set; } public int Complete() { return(_context.SaveChanges()); }
public void Commit() { _context.SaveChanges(); }
public void ApplyOffer(UserAppliedOffer userAppliedOffer) { userAppliedOffer.CreatedAt = DateTime.Now; _context.UserAppliedOffer.Add(userAppliedOffer); _context.SaveChanges(); }
public int SaveChanges() { return(Db.SaveChanges()); }