Exemple #1
0
        public ActionResult Create([Bind(Include = "Customer_ID,FirstName,LastName,Email,Phone")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customer.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Exemple #2
0
        /// <summary>
        /// Save changes to the database, and update the controls
        /// </summary>
        private void SaveChanges()
        {
            foreach (Booking booking in context.Bookings)
            {
                if (booking.Client == null || booking.Flight == null)
                {
                    context.Bookings.Remove(booking);
                }
            }

            // update the database

            try
            {
                context.SaveChanges();
            }
            catch (Exception e)
            {
                MessageBox.Show("Error updating the database: " + e.Message);
                Environment.Exit(1);
            }

            // refresh the controls

            dataGridViewClients.Refresh();
            dataGridViewFlights.Refresh();
            dataGridViewReport.Refresh();
        }
        /// <summary>
        /// Delete the client
        /// </summary>
        /// <param name="clientId">Inventory key - CarId</param>
        public void GridViewClient_DeleteItem(int clientId)
        {
            using (TravelBookingEntities context = new TravelBookingEntities())
            {
                Client item = context.Clients.Find(clientId);

                context.Clients.Remove(item);
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Add a client
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButtonAddClient_Click(object sender, EventArgs e)
        {
            using (TravelBookingEntities context = new TravelBookingEntities())
            {
                Client client = new Client
                {
                    ClientName = textBoxClientName.Text,
                };

                context.Clients.Add(client);
                context.SaveChanges();
            }

            clientsGridView.DataBind();
        }
        /// <summary>
        /// Update an item from gridview.
        /// </summary>
        /// <param name="clientId">
        public void GridViewClient_UpdateItem(int clientId)
        {
            using (TravelBookingEntities context = new TravelBookingEntities())
            {
                Client item = context.Clients.Find(clientId);
                //listBoxThings.Items.Add(item.ToString());

                if (item == null)
                {
                    // The item wasn't found
                    ModelState.AddModelError("", String.Format("Item with id {0} was not found", clientId));
                    return;
                }

                TryUpdateModel(item);
                if (ModelState.IsValid)
                {
                    // everthing is ok, so save the changes and update the filter list
                    context.SaveChanges();
                }
            }
        }