# Modify events

Sitefinity CMS allows you to modify an event through the Events API.

When modifying an event, you must perform the following:

1. Get the master version.\
   Get the master version of the event. When you modify an event, you must not work on its live version.
2. Get a temp version.\
   Check out the master version to get a temp version of the event. This is the version you must modify.
3. Modify the temp version.\
   Use the temp version to modify the event.
4. Update the master version.\
   Check in the temp version to transfer the changes to the master version.
5. Update the live version.\
   Publish the master version to transfer the changes to the live version.

The examples below modify an event by the *ID* of its master version. For more information about working with the ID of the live version, see [For developers: Edit content](https://www.progress.com/documentation/sitefinity-cms/for-developers-edit-content).

## Modify an event by its ID

The following examples modify an event by the ID of its master version:

**Native API**

```C#
using System;
using Telerik.Sitefinity.Events.Model;
using Telerik.Sitefinity.Modules.Events;

namespace SitefinityWebApp
{
   public class ModifyEventByID
   {
       public void ModifyEventNativeAPI(Guid eventId, string newContent)
       {
           EventsManager eventsManager = EventsManager.GetManager();
           Event @event = eventsManager.GetEvent(eventId);
           if (@event != null)
           {
               // Get the master version
               Event master = eventsManager.Lifecycle.GetMaster(@event) as Event;

               if (master != null)
               {
                   // Check out the master to get a temp version
                   Event temp = eventsManager.Lifecycle.CheckOut(master) as Event;

                   // Make the modifications to the temp version
                   temp.Content = newContent;

                   // Check in the temp and get the updated master version. 
                   // After the check in the temp version is deleted.
                   master = eventsManager.Lifecycle.CheckIn(temp) as Event;

                   // Publish the master
                   eventsManager.Lifecycle.Publish(master);

                   eventsManager.SaveChanges();
               }
           }
       }
   }
}
```

First, you get an instance of the `EventsManager` class. Then, you get the event corresponding to the `ID`. If the event exists, you get its master version by calling the `Lifecycle.GetMaster` method.

For more information about querying events, see [For developers: Query events](https://www.progress.com/documentation/sitefinity-cms/for-developers-query-events).\
For more information about finding specific events, see [For developers: Find events](https://www.progress.com/documentation/sitefinity-cms/for-developers-find-events).

Then, you call `Lifecycle.CheckOut` with the master version as argument to get a temp version of the item. You modify the content of the temp version with `newContent`. Then, you call `Lifecycle.CheckIn` with the temp version as argument to transfer the changes to the master version. By default, calling the `CheckIn` method deletes the temp version. Then, you call `Lifecycle.Publish` with the master version as argument to transfer the changes to the live version. Finally, you call `SaveChanges` to save all changes.

**Fluent API**

```C#
using System;
using Telerik.Sitefinity;

namespace SitefinityWebApp
{
   public class ModifyEventByIDFluentAPI
   {
       public void ModifyEventFluentAPI(Guid masterEventId, string newContent)
       {
           int count = 0;

           // Check whether the item exists
           App.WorkWith().Events().Where(ev => ev.Id == masterEventId).Count(out count);

           if (count > 0)
           {
               // Use the singular facade to modify the master by the master ID
               App.WorkWith().Event(masterEventId).CheckOut().Do(ev =>
               {
                   ev.Content = newContent;
                   ev.LastModified = DateTime.UtcNow;
               })
               .CheckIn().Publish().SaveChanges();
           }
       }
   }
}
```

First, you check whether an item with the specified ID exists. Then, you get the master version with the specified ID using the singular facade of the event.

> info \*\*NOTE:\*\*If there is no item with the specified `Id`, `Event(masterEventId)` throws an exception of type `ItemNotFoundException`.

For more information about querying events, see [For developers: Query events](https://www.progress.com/documentation/sitefinity-cms/for-developers-query-events).\
For more information about finding specific events, see [For developers: Find events](https://www.progress.com/documentation/sitefinity-cms/for-developers-find-events).

To get a temp for the item, you use the `CheckOut` method of the facade. Then, you modify the content with `newContent` in the `Do` method of the temp facade. You call `CheckIn` to transfer the changes to the master version of the item. Then, you call `Publish` to transfer the changes to the live version. Finally, you call `SaveChanges` to save all changes.
