public void Delete(LaundryJobChecklistDataEntity p_checklist)
 {
     using(var session = NHibernateHelper.OpenSession())
     {
         using(var transaction = session.BeginTransaction())
         {
             try
             {
                 session.Delete(p_checklist);
                 transaction.Commit();
             }
             catch(Exception ex)
             {
                 transaction.Rollback();
                 throw ex;
             }
         }
     }
 }
 public void OnCheckListChange(object sender, ChecklistEventArgs e)
 {
     m_headerEntity.JobChecklistEntities = new List<LaundryJobChecklistDataEntity>();
     foreach(string checklist in e.Checklist){
         string[] arrchecklist = checklist.Split('|');
         LaundryJobChecklistDataEntity newChecklist = new LaundryJobChecklistDataEntity();
         newChecklist.Header = m_headerEntity;
         newChecklist.Checklist = m_presenter.GetChecklistByName(arrchecklist[0]);
         newChecklist.Qty = int.Parse(arrchecklist[1]);
         m_headerEntity.JobChecklistEntities.Add(newChecklist);
     }
 }
        private bool SaveUpdateOrDeleteJobCheckList()
        {
            try{
                if(new_ChecklistEntities != null){
                    orig_ChecklistEntities = m_jobChecklistDao.GetAllItemsByHeaderId(m_headerEntity.LaundryHeaderID) as List<LaundryJobChecklistDataEntity>;

                    var listToLookUp = new_ChecklistEntities.ToLookup(entity => entity.Checklist.ChecklistID);
                    var listToDelete = orig_ChecklistEntities.Where(entity => (!listToLookUp.Contains(entity.Checklist.ChecklistID)));

                    foreach(LaundryJobChecklistDataEntity entity in listToDelete.ToList()){
                        m_jobChecklistDao.Delete(entity);
                    }

                    orig_ChecklistEntities = m_jobChecklistDao.GetAllItemsByHeaderId(m_headerEntity.LaundryHeaderID) as List<LaundryJobChecklistDataEntity>;
                    List<LaundryJobChecklistDataEntity> new_Checklist = new List<LaundryJobChecklistDataEntity>();

                    foreach(LaundryJobChecklistDataEntity entity in orig_ChecklistEntities)
                    {
                        LaundryJobChecklistDataEntity checklist = new LaundryJobChecklistDataEntity();
                        checklist = new_ChecklistEntities.Where(x => x.Checklist.ChecklistID == entity.Checklist.ChecklistID).FirstOrDefault();
                        if(checklist != null)
                        {
                            entity.Qty = checklist.Qty;
                            new_Checklist.Add(entity);
                        }
                    }

                    var listToLookUpForAdd = orig_ChecklistEntities.ToLookup(entity => entity.Checklist.ChecklistID);
                    var listToAdd = new_ChecklistEntities.Where(entity => (!listToLookUpForAdd.Contains(entity.Checklist.ChecklistID)));
                    foreach(LaundryJobChecklistDataEntity entity in listToAdd.ToList()){
                        new_Checklist.Add(entity);
                    }

                    m_OriginalHeaderEntity.JobChecklistEntities = new_Checklist;
                }
            }
            catch(Exception ex){
                MessageService.ShowError("Unexpected exception occured while processing your request.\nPlease see log file for technical details.","Error", ex);
                return false;
            }
            return true;
        }