private ActionResult CreateRP(RelyingParty rp, RPCertInputModel cert)
        {
            // ID is not required for create
            ModelState["ID"].Errors.Clear();

            rp.Id = null;
            rp.EncryptingCertificate = cert.Cert;

            if (ModelState.IsValid)
            {
                try
                {
                    this.RelyingPartyRepository.Add(rp);
                    TempData["Message"] = Resources.RPController.CreateSuccessful;
                    return(RedirectToAction("Index"));
                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
                catch
                {
                    ModelState.AddModelError("", Resources.RPController.ErrorCreatingRelyingParty);
                }
            }

            return(View("RP", rp));
        }
        public ActionResult RP(string id,
                               string action,
                               [Bind(Exclude = "EncryptingCertificate")] RelyingParty rp,
                               RPCertInputModel cert)
        {
            if (action == "create")
            {
                return(CreateRP(rp, cert));
            }
            if (action == "save")
            {
                return(SaveRP(id, rp, cert));
            }
            if (action == "delete")
            {
                return(DeleteRP(id));
            }

            var origRP = this.RelyingPartyRepository.Get(id);

            rp.EncryptingCertificate = origRP.EncryptingCertificate;

            ModelState.AddModelError("", Resources.RPController.InvalidAction);
            return(View("RP", rp));
        }
        private ActionResult SaveRP(string id, RelyingParty rp, RPCertInputModel cert)
        {
            if (cert.RemoveCert == true)
            {
                rp.EncryptingCertificate = null;
            }
            else if (cert.Cert != null)
            {
                rp.EncryptingCertificate = cert.Cert;
            }
            else
            {
                var origRP = this.RelyingPartyRepository.Get(id);
                rp.EncryptingCertificate = origRP.EncryptingCertificate;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    this.RelyingPartyRepository.Update(rp);
                    TempData["Message"] = Resources.RPController.UpdateSuccessful;
                    return(RedirectToAction("RP", new { id }));
                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
                catch
                {
                    ModelState.AddModelError("", Resources.RPController.ErrorUpdatingRelyingParty);
                }
            }

            return(View("RP", rp));
        }