I have a custom list (not document library) that i have attached 2 event receivers to. These are itemupdating and itemupdated. My itemupdating event receiver sets a value in a field and my itemupdated sets some permissions on the item. I've noticed that the after the itemupdated method is called the itemupdating method is called again. I presume this is because the i've called properties.ListItem.Update(); I do not want the itemupdating event code to run twice. How can i handle this scenerio?
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
if (properties.ListTitle != C.EquipmentList) return;
//Expiry date calculated field is not available in this event so
//im recreating the formula to pass to the checkexpirydate method
DateTime ExpiryDate = CalculateExpiryDate(
properties.AfterProperties[C.InternalLastCalDate].ToString(),
properties.AfterProperties[C.InternalNumberOfDaysTillNextCalibration].ToString()
);
properties.AfterProperties[C.Status] = CheckExpiryDate(ExpiryDate);
}
public override void ItemUpdated(SPItemEventProperties properties)
{
try
{
base.ItemUpdated(properties);
if (properties.ListTitle != C.EquipmentList) return;
properties.Web.AllowUnsafeUpdates = true;
properties.Web.Site.AllowUnsafeUpdates = true;
RemoveItemPermission(properties);
SetCustodianPermissions(properties);
SPGroup AdminSGroup = properties.Web.SiteGroups[C.AdminsGroup];
GrantPermission(properties.ListItem, properties.Web, SPRoleType.Administrator, AdminSGroup);
EventFiringEnabled = false;
properties.ListItem.SystemUpdate();
}
finally
{
EventFiringEnabled = true;
properties.Web.AllowUnsafeUpdates = false;
properties.Web.Site.AllowUnsafeUpdates = false;
}
}