public ActionResult TransferOwnership(LedgerTransferOwnershipModel model)
 {
     using (db00ccd2da5aff4a5983c0a17b010f53a6Entities context = new db00ccd2da5aff4a5983c0a17b010f53a6Entities())
     {
         var theLedger = context.Ledgers.FirstOrDefault(l => l.LedgerId == model.LedgerId);
         if (theLedger == default(Ledger))
         {
             return View("ErrorMessage", new Models.ErrorMessageModel { Title = "No Such Ledger!", Message = "The ledger you are attempting to access does not exist in the database.", ReturnAction = "Index", ReturnRouteValues = new { } });
         }
         else if (theLedger.UserProfile.UserName != User.Identity.Name)
         {
             return View("ErrorMessage", new Models.ErrorMessageModel { Title = "No Permission!", Message = "You are not the owner of the ledger you are attempting to access.", ReturnAction = "Index", ReturnRouteValues = new { } });
         }
         var theOldOwner = theLedger.UserProfile;
         var theNewOwner = context.UserProfiles.FirstOrDefault(u => u.UserName == model.NewOwner);
         if (theNewOwner == default(UserProfile))
         {
             return View("ErrorMessage", new Models.ErrorMessageModel { Title = "User Does Not Exist!", Message = "The specified new owner does not exist!", ReturnAction = "Detail", ReturnRouteValues = new { id=model.LedgerId } });
         }
         if (theOldOwner.UserId != theNewOwner.UserId)
         {
             if (!theLedger.Editors.Any(u => u.UserId == theOldOwner.UserId) && model.MakeOldOwnerAnEditor)
             {
                 theLedger.Editors.Add(theOldOwner);
             }
             theLedger.UserProfile = theNewOwner;
             context.SaveChanges();
         }
         return RedirectToAction("Index");
     }
 }
 public ActionResult TransferOwnership(int id)
 {
     using (db00ccd2da5aff4a5983c0a17b010f53a6Entities context = new db00ccd2da5aff4a5983c0a17b010f53a6Entities())
     {
         var theLedger = context.Ledgers.FirstOrDefault(l => l.LedgerId == id);
         if (theLedger == default(Ledger))
         {
             return View("ErrorMessage", new Models.ErrorMessageModel { Title = "No Such Ledger!", Message = "The ledger you are attempting to access does not exist in the database.", ReturnAction = "Index", ReturnRouteValues = new { } });
         }
         else if (theLedger.UserProfile.UserName != User.Identity.Name)
         {
             return View("ErrorMessage", new Models.ErrorMessageModel { Title = "No Permission!", Message = "You are not the owner of the ledger you are attempting to access.", ReturnAction = "Index", ReturnRouteValues = new { } });
         }
         LedgerTransferOwnershipModel theModel = new LedgerTransferOwnershipModel();
         theModel.LedgerId = id;
         theModel.MakeOldOwnerAnEditor = true;
         return View(theModel);
     }
 }