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));
 }