AzureTicker.Worker.Model.Repositories.NotificationRepository.AddOrUpdate C# (CSharp) Метод

AddOrUpdate() публичный Метод

public AddOrUpdate ( Notification notification ) : string
notification AzureTicker.Worker.Model.TableStorage.Notification
Результат string
        public string AddOrUpdate(Notification notification)
        {
            string key = string.Empty;
            var existingNotification = GetByRowKey(notification.RowKey);
            if (existingNotification == null)
            {
                key = Guid.NewGuid().ToString();
                notification.RowKey = key;
                notification.Password = TickerEncryption.Utility.Encrypt(notification.Password, CloudConfigurationManager.GetSetting(Constants.Thumbprint1), CloudConfigurationManager.GetSetting(Constants.Thumbprint2));
                notification.BalanceString = "New";
                notification.LastVerification = DateTime.UtcNow;
                context.AddObject(tableName, notification);
            }
            else
            {
                existingNotification.UserName = notification.UserName;
                existingNotification.Password = TickerEncryption.Utility.Encrypt(notification.Password, CloudConfigurationManager.GetSetting(Constants.Thumbprint1), CloudConfigurationManager.GetSetting(Constants.Thumbprint2));
                existingNotification.NotificationUri = notification.NotificationUri;
                notification.LastVerification = DateTime.UtcNow;
                key = existingNotification.RowKey;
                context.UpdateObject(existingNotification);
            }
            return key;
        }

Usage Example

 public string Post(Notification notification)
 {
     string retVal = string.Empty;
     notification.PartitionKey = "partitionName";
     using (INotificationRepository rep = new NotificationRepository())
     {
         rep.AddOrUpdate(notification);
         rep.SaveChanges();
         retVal = notification.RowKey;
     }
     return retVal;
 }