public ActionResult Edit(RelyingPartyModel relyingParty)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    TrySetCertificateFromUpload(relyingParty);
                    Repository.Update(relyingParty.ToDomainModel());

                    return(RedirectToAction("Index"));
                }

                return(View(relyingParty));
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ModelState.AddModelError("", ex.InnerException.Message);
                }
                else
                {
                    ModelState.AddModelError("", ex.Message);
                }

                return(View(relyingParty));
            }
        }
        private void TrySetCertificateFromUpload(RelyingPartyModel relyingParty)
        {
            if (relyingParty.CertificateUpload != null && relyingParty.CertificateUpload.ContentLength > 0)
            {
                byte[] bytes = new byte[relyingParty.CertificateUpload.InputStream.Length];
                relyingParty.CertificateUpload.InputStream.Read(bytes, 0, bytes.Length);

                relyingParty.EncryptingCertificate = Convert.ToBase64String(bytes);
            }
        }