public IHttpActionResult PutTowns(int id, Towns towns) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != towns.ID) { return(BadRequest()); } db.Entry(towns).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TownsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// POST: api/Registration public IHttpActionResult Post([FromBody] M_UserRegistration user) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } budegetdbcontext.M_UserRegistration.Add(user); budegetdbcontext.SaveChanges(); return(Ok()); }
public ActionResult Create(PaymentTypes model) { var t = new PaymentType(); //var payment = collection.Keys t.PaymentName = model.PaymentName; t.Active = true; db.PaymentTypes.Add(t); db.SaveChanges(); return(RedirectToAction("../Transactions/Create")); }
public ActionResult Create(Models.Transactions model)//FormCollection collection) { try { // TODO: Add insert logic here var t = new Transaction(); //var payment = collection.Keys t.Name = model.Name; t.Amount = model.Amount; t.PaymentDate = model.PaymentDate; t.PaymentType = model.ID; t.Active = true; db.Transactions.Add(t); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
private void button1_Click(object sender, EventArgs e) { if (txtName.Text == "" || txtPassword.Text == "" || txtKeyword.Text == "") { errorProvider1.SetError(txtName, "Please enter a name"); errorProvider2.SetError(txtPassword, "Please enter a password"); errorProvider3.SetError(txtKeyword, "Please enter a keyword"); } else { errorProvider1.Dispose(); errorProvider2.Dispose(); errorProvider3.Dispose(); using (var budgetContext = new BudgetEntities()) { var user = budgetContext.Accounts.Where(acc => acc.Name.Equals(txtName.Text) && acc.KeyWord.Equals(txtKeyword.Text)).FirstOrDefault(); if (user != null) { user.Password = txtPassword.Text; budgetContext.Entry(user).State = EntityState.Modified; budgetContext.SaveChanges(); MessageBox.Show("Success!"); } else { label4.Text = "Invalid keyword or name !"; } } } }
private void buttonUpdate_Click(object sender, EventArgs e) { if (this.dataGridUsers.SelectedRows.Count > 0) { using (var budgetContext = new BudgetEntities()) { foreach (DataGridViewRow item in this.dataGridUsers.SelectedRows) { var id = Convert.ToInt32(item.Cells[0].Value); var user = budgetContext.Accounts.Where(u => u.Id == id).FirstOrDefault(); user.Name = Convert.ToString(item.Cells[1].Value); user.Password = Convert.ToString(item.Cells[2].Value); user.KeyWord = Convert.ToString(item.Cells[3].Value); budgetContext.Entry(user).State = EntityState.Modified; } budgetContext.SaveChanges(); MessageBox.Show("Users have been edited !"); } } else { MessageBox.Show("Please select one row"); } }
private void button1_Click(object sender, EventArgs e) { if (txtName.Text == "" || txtPassword.Text == "" || txtKeyWord.Text == "") { errorProvider1.SetError(txtName, "Please enter a name"); errorProvider2.SetError(txtPassword, "Please enter a password"); errorProvider3.SetError(txtKeyWord, "Please enter a keyword"); } else { errorProvider1.Dispose(); errorProvider2.Dispose(); errorProvider3.Dispose(); using (var budgetContext = new BudgetEntities()) { var user = new Account(); user.Name = txtName.Text; user.Password = txtPassword.Text; user.KeyWord = txtKeyWord.Text; user.Enabled = true; budgetContext.Accounts.Add(user); budgetContext.SaveChanges(); EmptyFields(); MessageBox.Show("User successful registered !"); } } }
// POST: api/Bank public IHttpActionResult Post([FromBody] M_Bank bank) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } budegetdbcontext.M_Bank.Add(bank); budegetdbcontext.SaveChanges(); return(Ok()); }