Exemple #1
0
        public IHttpActionResult PutCustomer(int id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.CustomerID)
            {
                return(BadRequest());
            }

            db.Entry(customer).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            MyCustomer.CustomerID = Convert.ToInt32(textBox2.Text);
            MyCustomer.Name       = textBox3.Text;
            DateTime dt;

            string[] formats = { "yyyy-MM-dd" };
            if (!DateTime.TryParseExact(textBox4.Text, formats,
                                        System.Globalization.CultureInfo.InvariantCulture,
                                        DateTimeStyles.None, out dt))
            {
                MyCustomer.BirthDate = Convert.ToDateTime(textBox3.Text);
            }
            else
            {
                MessageBox.Show("Please insert a valid birthday");
                this.Hide();
                RegisterNewCar registerNewCar = new RegisterNewCar();
                registerNewCar.ShowDialog();
                this.Close();
            }
            MyCustomer.Location = textBox5.Text;

            using (var MyDbEntities = new CustomerModel())
            {
                MyDbEntities.Entry(MyCustomer).State = System.Data.Entity.EntityState.Modified;
                MyDbEntities.SaveChanges();
            }
            this.Hide();
            Menu menu = new Menu();

            menu.ShowDialog();
            this.Close();
        }
Exemple #3
0
 public ActionResult Edit([Bind(Include = "CustomerID,Name,Age")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
 public ActionResult Edit([Bind(Include = "Id,UserId,Name,PhoneNumber,City,occupation,zipCode,suburb")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }