Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }