private int SaveActions(decimal incidentId, List <INCFORM_ACTION> itemList) { PSsqmEntities entities = new PSsqmEntities(); int status = 0; using (var ctx = new PSsqmEntities()) { ctx.ExecuteStoreCommand("DELETE FROM INCFORM_ACTION WHERE INCIDENT_ID = {0}", incidentId); } int seq = 0; foreach (INCFORM_ACTION item in itemList) { var newItem = new INCFORM_ACTION(); if (!string.IsNullOrEmpty(item.ITEM_DESCRIPTION)) { seq = seq + 1; newItem.INCIDENT_ID = incidentId; newItem.ITEM_SEQ = seq; newItem.ITEM_DESCRIPTION = item.ITEM_DESCRIPTION; newItem.ASSIGNED_PERSON_ID = item.ASSIGNED_PERSON_ID; newItem.START_DATE = item.START_DATE; newItem.COMPLETION_DATE = item.COMPLETION_DATE; newItem.IsCompleted = item.IsCompleted; newItem.LAST_UPD_BY = SessionManager.UserContext.Person.FIRST_NAME + " " + SessionManager.UserContext.Person.LAST_NAME; newItem.LAST_UPD_DT = DateTime.Now; entities.AddToINCFORM_ACTION(newItem); status = entities.SaveChanges(); DateTime dueDate = newItem.START_DATE.HasValue ? (DateTime)newItem.START_DATE : DateTime.Now.AddDays(2); EHSIncidentMgr.CreateOrUpdateTask(incidentId, (decimal)item.ASSIGNED_PERSON_ID, 40, dueDate, item.ITEM_DESCRIPTION); } } return(status); }