public ActionResult Create([Bind(Include = "Id,Nome")] Categoria categoria) { if (ModelState.IsValid) { db.Tcategorias.Add(categoria); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categoria)); }
public ActionResult Create([Bind(Include = "ID,Name,Image,Description")] Item item) { try { if (ModelState.IsValid) { db.Item.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception) { ModelState.AddModelError("", "Unable to save changes. Please try something different."); } return(View(item)); }
public ActionResult Create([Bind(Include = "ID,Username,Password,LastLogin,AccountCreationDate")] Login login) { try { if (ModelState.IsValid) { db.Login.Add(login); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Please try something different."); } return(View(login)); }
public ActionResult Create([Bind(Include = "ID,LoginID,Name,Level,Class,Experience,Next,CharacterCreationDate")] Character character) { try { if (ModelState.IsValid) { db.Character.Add(character); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Please try something different."); } return(View(character)); }
public ActionResult Create([Bind(Include = "CharacterID,ItemID,Quantity")] Inventory inventory) { try { if (ModelState.IsValid) { db.Inventory.Add(inventory); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Please try something different. (Player probably already has an index of that item.)"); } ViewBag.CharacterID = new SelectList(db.Character, "ID", "Name", inventory.CharacterID); ViewBag.ItemID = new SelectList(db.Item, "ID", "Name", inventory.ItemID); return(View(inventory)); }
private void button4_Click(object sender, EventArgs e) { var school = new School { Id = 5, Name = "Hitachi School" }; using (var context = new CPContext()) { context.Schools.Add(school); context.SaveChanges(); } MessageBox.Show("New School created."); }
private void button3_Click(object sender, EventArgs e) { Student student = new Student { SchoolId = 5, Name = "Test student", DOB = DateTime.Now, Address = "Bangalore" }; using (var context = new CPContext()) { context.Students.Add(student); context.SaveChanges(); } MessageBox.Show("New student created."); }
public void SaveChanges() { _dbContext.SaveChanges(); }