/// <summary>
 /// Initializes a new instance of the <see cref="SysEventArgs{TEntity}"/> class using the specified parameter.
 /// </summary>
 /// <param name="e">An instance of the <see cref="SysEventArgs"/> class to initialize with.</param>
 /// <exception cref="System.InvalidCastException">
 /// Either <see cref="SysEventArgs.Data"/> or <see cref="SysEventArgs.User"/> cannot be converted to the generic entity type or to <see cref="IdentityUser"/> respectively.
 /// </exception>
 public SysEventArgs(SysEventArgs e) : base(e.EventType)
 {
     Data        = (TEntity)e.Data;
     User        = (IdentityUser)e.User;
     Error       = e.Error;
     ObjectState = e.ObjectState;
 }
        /// <summary>
        /// Asynchronously adds an event entry to the log.
        /// </summary>
        /// <param name="args">The arguments of the event to log.</param>
        /// <returns></returns>
        public override async Task LogAsync(SysEventArgs args)
        {
            var type = args.EventType;
            var user = args.User;
            var usr  = await AsUser(user, type);

            args.User = usr;

            if (type == SysEventType.LoginSuccess)
            {
                try
                {
                    // update last seen
                    var u = await _userRepository.GetAsync(q => q.Where(e => e.Id == usr.Id).SingleOrDefault());

                    u.LastSeen = DateTime.UtcNow;
                    u.HostName = args.Data?.ToString();
                    await _userRepository.SaveChangesAsync();
                }
                catch (Exception)
                {
                }
            }

            await base.LogAsync(args);
        }