/// <summary>
        /// delete an entity if it exists
        /// </summary>
        /// <param name="entity"></param>
        public void Delete(ActionRequestLogEntity entity)
        {
            var deleteEntity = this.SelectOne(entity.PartitionKey, entity.RowKey);

            if (deleteEntity != null)
            {
                GetTableReference().Execute(TableOperation.Delete(deleteEntity));
            }
        }
 /// <summary>
 /// insert an entity regardless
 /// </summary>
 /// <param name="entity"></param>
 public void Insert(ActionRequestLogEntity entity)
 {
     try
     {
         GetTableReference().Execute(TableOperation.Insert(entity));
     }
     catch (Exception ex)
     {
         LogErrorMessage(entity, ex);
     }
 }
        /// <summary>
        /// update an entity if it exists, otherwise insert a new record
        /// </summary>
        /// <param name="entity"></param>
        public void Upsert(ActionRequestLogEntity entity)
        {
            var updateEntity = this.SelectOne(entity.PartitionKey, entity.RowKey);

            if (updateEntity == null)
            {
                this.Insert(entity);
            }
            else
            {
                this.Update(entity);
            }
        }
        /// <summary>
        /// update an entity if it exists
        /// </summary>
        /// <param name="entity"></param>
        public void Update(ActionRequestLogEntity entity)
        {
            var updateEntity = this.SelectOne(entity.PartitionKey, entity.RowKey);

            if (updateEntity == null)
            {
                return;
            }

            // not allow to change the original creator id
            updateEntity.AccessDate       = entity.AccessDate;
            updateEntity.ActionParameters = entity.ActionParameters;
            updateEntity.IpAddress        = entity.IpAddress;
            GetTableReference().Execute(TableOperation.Replace(updateEntity));
        }
        public void LogErrorMessage(ActionRequestLogEntity entity, Exception ex)
        {
            var msg = string.Format("message: {0}, source: {1}, stack trace: {2}, TargetSite: {3}", ex.Message, ex.Source, ex.StackTrace, ex.TargetSite);

            if (ex.Data != null && ex.Data.Keys != null)
            {
                foreach (var key in ex.Data.Keys)
                {
                    msg = string.Format("{0}, {1}|{2},", msg, key, ex.Data[key]);
                }
            }
            using (var context = OsbideContext.DefaultWebConnection)
            {
                context.LocalErrorLogs.Add(new LocalErrorLog
                {
                    SenderId = Convert.ToInt32(entity.RowKey.Split('_')[0]),
                    LogDate  = DateTime.Now,
                    Content  = msg
                });
                context.SaveChanges();
            }
        }