/// <summary> /// Create a single domainLicense /// </summary> /// <param name="owningLicense">Owning license ID</param> /// <returns>Create DomainLicense view</returns> public ActionResult Create(Guid owningLicense) { using (var context = dataContextFactory.CreateByUser()) { var license = (from x in context.Licenses where x.ObjectId == owningLicense select x) .Include(x => x.Sku) .SingleOrDefault(); if (license == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var domainLicense = new Model.DomainLicense() { LicenseId = license.ObjectId, License = license, DomainLicenseIssued = license.Sku.CalculateDomainIssueDate(), DomainLicenseExpires = license.Sku.CalculateAutoDomainExpiration() }; if (license.Sku.CanCalculateManualDomainExpiration) { domainLicense.DomainLicenseExpires = license.Sku.CalculateManualDomainExpiration(); } var viewModel = new DomainLicenseViewModel(domainLicense); viewModel.RedirectUrl = new UrlHelper(ControllerContext.RequestContext).Action("Details", "License", new { key = viewModel.LicenseId }); return(View(viewModel)); } }
public ActionResult Edit(DomainLicenseViewModel viewModel) { try { if (ModelState.IsValid) { using (var context = dataContextFactory.CreateByUser()) { var domainLicense = (from x in context.DomainLicenses where x.DomainLicenseId == viewModel.DomainLicenseId select x) .SingleOrDefault(); if (domainLicense == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } domainLicense.DomainName = viewModel.DomainName; domainLicense.DomainLicenseIssued = viewModel.DomainLicenseIssued; domainLicense.DomainLicenseExpires = viewModel.DomainLicenseExpires; domainLicense.AutomaticallyCreated = viewModel.AutomaticallyCreated; context.SaveChanges(); Flash.Success("The domain license was updated."); } if (!string.IsNullOrEmpty(viewModel.RedirectUrl)) { return(Redirect(viewModel.RedirectUrl)); } else { return(RedirectToAction("Details", "License", new { key = viewModel.LicenseId })); } } else { return(View(viewModel)); } } catch { throw; } }
/// <summary> /// Edit a single domainLicense /// </summary> /// <param name="key">GUID of domainLicense to edit</param> /// <returns>Edit domainLicense view</returns> public ActionResult Edit(Guid key) { using (var context = dataContextFactory.CreateByUser()) { var domainLicense = (from x in context.DomainLicenses where x.DomainLicenseId == key select x) .Include(x => x.License.Sku) .SingleOrDefault(); if (domainLicense == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var viewModel = new DomainLicenseViewModel(domainLicense); viewModel.UseLocalReferrerAsRedirectUrl(Request); return(View(viewModel)); } }
public ActionResult Create(DomainLicenseViewModel viewModel) { if (ModelState.IsValid) { using (var context = dataContextFactory.CreateByUser()) { var license = context.Licenses.Where(l => l.ObjectId == viewModel.LicenseId) .Include(l => l.Sku) .Include(l => l.Sku.PrivateKey) .SingleOrDefault(); if (license == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var domainLicense = new Model.DomainLicense(); domainLicense.License = license; domainLicense.KeyBytes = license.Sku.PrivateKey.KeyBytes; domainLicense.DomainName = viewModel.DomainName; domainLicense.DomainLicenseIssued = viewModel.DomainLicenseIssued; domainLicense.DomainLicenseExpires = viewModel.DomainLicenseExpires; domainLicense.AutomaticallyCreated = viewModel.AutomaticallyCreated; context.DomainLicenses.Add(domainLicense); if (context.SaveChanges(CreateValidationFailed)) { Flash.Success("The domain license was created."); return(Redirect(viewModel.RedirectUrl)); } } } return(View(viewModel)); }