/// <summary>
        /// Deletes the specified egm windows event entity.
        /// </summary>
        /// <param name="egmWindowsEvent">The egm windows event entity.</param>
        public void Delete(EgmWindowsEvent egmWindowsEvent)
        {
            using (var context = new HmsDbContext())
            {
                if (!context.EgmWindowsEvents.Any(winEvt => winEvt.Id == egmWindowsEvent.Id))
                {
                    return;
                }

                // matching PK found, thus we proceed with Delete
                DaoUtilities.DeleteEntity(context, context.EgmWindowsEvents, egmWindowsEvent);
            }
        }
        /// <summary>
        /// Updates the state of the existing entity.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityEntry">The entity entry.</param>
        /// <param name="egmWindowsEvent">The egm windows event entity.</param>
        private static void UpdateExistingEntityState(HmsDbContext context, DbEntityEntry entityEntry,
                                                      EgmWindowsEvent egmWindowsEvent)
        {
            var winEvtEntity = (EgmWindowsEvent)entityEntry.Entity;

            if (!winEvtEntity.SentAt.Equals(egmWindowsEvent.SentAt))
            {
                winEvtEntity.SentAt = egmWindowsEvent.SentAt;
            }

            if (!winEvtEntity.ReportGuid.Equals(egmWindowsEvent.ReportGuid))
            {
                winEvtEntity.ReportGuid = egmWindowsEvent.ReportGuid;
            }

            DaoUtilities.UpdateVersion(context, entityEntry);
        }
        /// <summary>
        /// Saves the specified egm windows event entity.
        /// </summary>
        /// <param name="egmWindowsEvent">The egm windows event entity.</param>
        public void Save(EgmWindowsEvent egmWindowsEvent)
        {
            using (var context = new HmsDbContext())
            {
                //context.Database.Log = Console.Write;

                if (!context.EgmWindowsEvents.Any(winEvt => winEvt.Id == egmWindowsEvent.Id))
                {
                    // no matching PK for this EgmWindowsEvent in database,
                    // thus we create new entity and add it to db
                    DaoUtilities.SaveCreatedEntity(context, context.EgmWindowsEvents, egmWindowsEvent,
                                                   SetNewEntityState);
                }
                else
                {
                    // matching PK found, thus we update state of existing EgmWindowsEvent entity
                    DaoUtilities.SaveUpdatedEntity(context, context.EgmWindowsEvents, egmWindowsEvent,
                                                   UpdateExistingEntityState);
                }
            }
        }
 /// <summary>
 /// Sets the new state of the entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 private static void SetNewEntityState(EgmWindowsEvent entity)
 {
     entity.Version = 0;
     entity.Hash    = GenerateHash(entity);
 }
 /// <summary>
 /// Generates the hash for the specified EgmWindowsEvent entity.
 /// </summary>
 /// <param name="egmWindowsEvent">The egm windows event entity.</param>
 /// <returns>System.String.</returns>
 public static string GenerateHash(EgmWindowsEvent egmWindowsEvent)
 {
     return(GenerateHash(egmWindowsEvent.Code, egmWindowsEvent.Description, egmWindowsEvent.EgmSerialNumber,
                         egmWindowsEvent.OccurredAt, egmWindowsEvent.CasinoCode, egmWindowsEvent.EventLogName));
 }