private bool LocalTryUpdateModel(CertificateUploadModel model) { if (!TryUpdateModel(model)) { return(false); } var domain = m_domainRepository.GetByDomainName(model.Owner); if (domain != null) { return(true); } // Check the address host try { domain = m_domainRepository.GetByDomainName(new MailAddress(model.Owner).Host); if (domain != null) { return(true); } } catch { } model.Owner = ""; ModelState.AddModelError("Owner", "Domain does not exist"); return(false); }
public ActionResult Add(FormCollection formValues) { var model = new CertificateUploadModel(); if (LocalTryUpdateModel(model)) { byte[] bytes = GetFileFromRequest("certificateFile"); if (bytes.Length < 1) { ModelState.AddModelError("certificateFile", "No file provided"); return(View(model)); } var domain = m_domainRepository.GetByDomainName(model.Owner); if (domain == null) { // Check the address host try { domain = m_domainRepository.GetByDomainName(new MailAddress(model.Owner).Host); if (domain == null) { return(View("NotFound")); } } catch { return(View("NotFound")); } } try { var cert = new Certificate(model.Owner, bytes, model.Password); Repository.Add(cert); } catch (CryptographicException ex) { ModelState.AddModelError("certificateFile", "Invalid certificate file - " + ex.GetBaseException().Message); return(View(model)); } return(RedirectToAction("Index", new { domainID = domain.ID })); } return(View(model)); }