/// <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(); } }
protected void Page_Load(object sender, EventArgs e) { if (dbInitialized == false) { using (TravelBookingEntities context = new TravelBookingEntities()) { context.CreateDatabase(); context.SeedData(); } dbInitialized = true; } }
/// <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(); }
public TravelBookingForm() { InitializeComponent(); // create new context, do not dispose context = new TravelBookingEntities(); // initialize the database using extension methods context.CreateDatabase(); // make sure you add code to the SeedData() method to add the data to the db context.SeedData(); this.Load += (s, e) => TravelBookingForm_Load(); buttonFilter.Click += ButtonFilter_Click; buttonUpdateDatabase.Click += ButtonUpdateDatabase_Click; }
/// <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(); } } }
/// <summary> /// Get all client /// </summary> public IEnumerable <Client> GetClients() { TravelBookingEntities context = new TravelBookingEntities(); return(context.Clients.ToList()); }