public ActionResult Create(ServicePrincipalModel servicePrincipal)
        {
            if (ModelState.IsValid)
            {
                servicePrincipal.SaveToStorage();
                return RedirectToAction("Index");
            }

            return View("Error");
        }
 public ActionResult Edit(string tenantId, ServicePrincipalModel editedServicePrincipal)
 {
     if (ModelState.IsValid)
     {
         var servicePrincipal = new ServicePrincipalModel();
         UpdateModel(servicePrincipal);
         try
         {
             var replaceOperation = TableOperation.Replace(servicePrincipal);
             servicePrincipal.SaveToStorage();
             return RedirectToAction("Index");
         }
         catch (StorageException ex)
         {
             if (ex.RequestInformation.HttpStatusCode == 412)
             {
                 // Concurrency error
                 var currentServicePrincipal = ServicePrincipalModel.GetFromStorage(tenantId);
                 if (currentServicePrincipal.Key != editedServicePrincipal.Key)
                 {
                     ModelState.AddModelError("Key", "Current value: " + currentServicePrincipal.Key);
                 }
                 if (currentServicePrincipal.AppId != editedServicePrincipal.AppId)
                 {
                     ModelState.AddModelError("AppId", "Current value: " + currentServicePrincipal.AppId);
                 }
                 if (currentServicePrincipal.TenantId != editedServicePrincipal.TenantId)
                 {
                     ModelState.AddModelError("TenantId", "Current value: " + currentServicePrincipal.TenantId);
                 }
                 ModelState.AddModelError(string.Empty, "The record you attempted to edit "
                     + "was modified by another user after you got the original value. The "
                     + "edit operation was canceled and the current values in the database "
                     + "have been displayed. If you still want to edit this record, click "
                     + "the Save button again. Otherwise click the Back to List hyperlink.");
                 ModelState.SetModelValue("ETag", new ValueProviderResult(currentServicePrincipal.ETag, currentServicePrincipal.ETag, null));
             }
             else
             {
                 throw;
             }
         }
     }
     return View(editedServicePrincipal);
 }
 public ActionResult DeleteConfirmed(string tenantId, ServicePrincipalModel editedServicePrincipalList)
 {
     // Delete all rows for this servicePrincipal list, that is, 
     // Subscriber rows as well as ServicePrincipal rows.
     // Therefore, no need to specify row key.
     var listRows = ServicePrincipalModel.GetAllFromStorage(tenantId);
     var batchOperation = new TableBatchOperation();
     int itemsInBatch = 0;
     foreach (DynamicTableEntity listRow in listRows)
     {
         batchOperation.Delete(listRow);
         itemsInBatch++;
         if (itemsInBatch == 100)
         {
             StorageFactory.Instance.IpcAzureAppTenantStateTable.ExecuteBatch(batchOperation);
             itemsInBatch = 0;
             batchOperation = new TableBatchOperation();
         }
     }
     if (itemsInBatch > 0)
     {
         StorageFactory.Instance.IpcAzureAppTenantStateTable.ExecuteBatch(batchOperation);
     }
     return RedirectToAction("Index");
 }