public LicenseDetailsViewItem(Model.License license, Model.Customer purchasingCustomer, Model.Customer owningCustomer, Model.SKU sku) : base(license) { OwningCustomerName = (owningCustomer != null) ? owningCustomer.Name : "Not owned"; PurchasingCustomerName = purchasingCustomer.Name; SKUName = sku.SkuCode; }
/// <summary> /// Construct the viewmodel /// </summary> /// <param name="license">License entity</param> /// <param name="skus">List of SKUs to select</param> /// <param name="customers">List of customers to select</param> public LicenseEditViewModel(Model.License license, List <Model.SKU> skus, List <Model.Customer> customers) { this.License = new LicenseViewModel(license); this.SKUList = skus.ToSelectList(x => x.SkuId, x => x.SkuCode); this.CustomerList = customers.ToSelectList(x => x.ObjectId, x => x.Name); }
public ActionResult Create(LicenseCreateViewModel viewModel) { try { if (ModelState.IsValid) { using (var context = dataContextFactory.CreateByUser()) { Model.License license = viewModel.ToEntity(null); context.Licenses.Add(license); context.SaveChanges(); Flash.Success("The license was succesfully created."); } if (!string.IsNullOrEmpty(viewModel.RedirectUrl)) { return(Redirect(viewModel.RedirectUrl)); } else { return(RedirectToAction("Index")); } } else { return(View(viewModel)); } } catch { throw; } }
public ActionResult Edit(LicenseEditViewModel viewModel) { try { if (ModelState.IsValid) { using (var context = dataContextFactory.CreateByUser()) { Model.License license = (from x in context.Licenses where x.ObjectId == viewModel.License.ObjectId select x).FirstOrDefault(); viewModel.ToEntity(license); context.SaveChanges(); } if (!string.IsNullOrEmpty(viewModel.RedirectUrl)) { return(Redirect(viewModel.RedirectUrl)); } else { return(RedirectToAction("Index")); } } else { return(View(viewModel)); } } catch { throw; } }
public LicenseIndexViewItem(Model.License license, Model.Customer owningCustomer, Model.SKU sku, IEnumerable <Model.DomainLicense> domains) : base(license) { OwningCustomerName = (owningCustomer != null) ? owningCustomer.Name : "Not owned"; SKUName = sku.SkuCode; DomainSummary = domains.ToSummary(x => x.DomainName, 1, ", "); }
/// <summary> /// Construct viewmodel /// </summary> /// <param name="License">License that this viewmodel represents</param> public LicenseViewModel(Model.License license) : this() { this.ObjectId = license.ObjectId; this.SkuId = license.SkuId; this.PurchasingCustomerId = license.PurchasingCustomerId; this.OwnerName = license.OwnerName; this.OwningCustomerId = license.OwningCustomerId; this.LicenseIssued = license.LicenseIssued; this.LicenseExpires = license.LicenseExpires; }
/// <summary> /// Convert back to License instance /// </summary> /// <param name="original">Original License. If Null a new instance is created.</param> /// <returns>License containing viewmodel data </returns> public Model.License ToEntity(Model.License original) { Model.License current = original ?? new Model.License(); current.ObjectId = this.ObjectId; current.SkuId = this.SkuId; current.PurchasingCustomerId = this.PurchasingCustomerId; current.OwnerName = this.OwnerName; current.OwningCustomerId = this.OwningCustomerId; current.LicenseIssued = this.LicenseIssued; current.LicenseExpires = this.LicenseExpires; return(current); }
public object Post(CreateLicense request) { var license = new Model.License().PopulateWith(request); documentSession.Store(license); documentSession.SaveChanges(); return (new HttpResult(new LicenseDto { Customer = documentSession.Load <Customer>(license.CustomerId), Product = new ProductDto().PopulateWith(documentSession.Load <Product>(license.ProductId)) }.PopulateWith(license)) { StatusCode = HttpStatusCode.Created, Headers = { { HttpHeaders.Location, Request.AbsoluteUri.CombineWith(license.Id) } } }); }
public object Post(CreateLicense request) { var license = new Model.License().PopulateWith(request); documentSession.Store(license); documentSession.SaveChanges(); return new HttpResult(new LicenseDto { Customer = documentSession.Load<Customer>(license.CustomerId), Product = new ProductDto().PopulateWith(documentSession.Load<Product>(license.ProductId)) }.PopulateWith(license)) { StatusCode = HttpStatusCode.Created, Headers = { {HttpHeaders.Location, Request.AbsoluteUri.CombineWith(license.Id)} } }; }
public IQueryable <Model.License> InsertLicense(Model.License license) { int newId = 0; using (TransactionScope scope = new TransactionScope()) { //using (ScutexEntities db1 = new ScutexEntities()) //{ License l = new License(); //Mapper.CreateMap<Model.License, License>(); //l = Mapper.Map<Model.License, License>(license); l.Name = license.Name; l.BuyNowUrl = license.BuyNowUrl; l.ProductUrl = license.ProductUrl; l.EulaUrl = license.EulaUrl; l.SupportEmail = license.SupportEmail; l.SalesEmail = license.SalesEmail; l.KeyGeneratorTypeId = (int)license.KeyGeneratorType; l.CreatedOn = license.CreatedOn; if (license.UpdatedOn.HasValue) { l.UpdatedOn = license.UpdatedOn; } if (license.Service != null) { l.ServiceId = license.Service.ServiceId; } l.UniqueId = license.UniqueId; l.ProductId = license.Product.ProductId; l.PrivateKey = license.KeyPair.PrivateKey; l.PublicKey = license.KeyPair.PublicKey; if (license.TrailNotificationSettings != null) { l.TrialTryButtonDelay = license.TrailNotificationSettings.TryButtonDelay; } db.AddToLicenses(l); db.SaveChanges(); newId = l.LicenseId; //} foreach (var ls in license.LicenseSets) { ls.LicenseId = newId; _licenseSetsRepository.InsertLicenseSet(ls); } license.TrialSettings.LicenseId = newId; _trialSettingsRepository.InsertTrialSettings(license.TrialSettings); scope.Complete(); } return(GetLicenseById(newId)); }
public IQueryable <Model.License> UpdateLicense(Model.License license) { int newId; using (TransactionScope scope = new TransactionScope()) { //using (ScutexEntities db1 = new ScutexEntities()) //{ var lic = (from l in db.Licenses where l.LicenseId == license.LicenseId select l).First(); lic.Name = license.Name; lic.BuyNowUrl = license.BuyNowUrl; lic.ProductUrl = license.ProductUrl; lic.EulaUrl = license.EulaUrl; lic.SupportEmail = license.SupportEmail; lic.SalesEmail = license.SalesEmail; lic.KeyGeneratorTypeId = (int)license.KeyGeneratorType; lic.CreatedOn = license.CreatedOn; if (license.UpdatedOn.HasValue) { lic.UpdatedOn = license.UpdatedOn; } lic.UniqueId = license.UniqueId; lic.ProductId = license.Product.ProductId; lic.PrivateKey = license.KeyPair.PrivateKey; lic.PublicKey = license.KeyPair.PublicKey; if (license.Service != null) { lic.ServiceId = license.Service.ServiceId; } if (license.TrailNotificationSettings != null) { lic.TrialTryButtonDelay = license.TrailNotificationSettings.TryButtonDelay; } db.SaveChanges(); newId = lic.LicenseId; //} _productsRepository.UpdateProduct(license.Product); foreach (var ls in license.LicenseSets) { ls.LicenseId = newId; if (ls.LicenseSetId == 0) { _licenseSetsRepository.InsertLicenseSet(ls); } else { _licenseSetsRepository.UpdateLicenseSet(ls); } } _trialSettingsRepository.DeleteTrialSettingsByLicenseId(newId); license.TrialSettings.LicenseId = newId; _trialSettingsRepository.InsertTrialSettings(license.TrialSettings); scope.Complete(); } return(GetLicenseById(newId)); }
/// <summary> /// Convert back to License instance /// </summary> /// <param name="original">Original License. If Null a new instance is created.</param> /// <returns>License containing viewmodel data </returns> public Model.License ToEntity(Model.License original) { return(License.ToEntity(original)); }
/// <summary> /// Construct the viewmodel /// </summary> /// <param name="license">License entity to show</param> public LicenseDetailsViewModel(Model.License license) : this() { License = new LicenseDetailsViewItem(license, license.PurchasingCustomer, license.OwningCustomer, license.Sku); }
public void ExecuteCheckout(Customer purchasingCustomer, Customer owningCustomer) { var currentUser = context.GetUser(HttpContext.Current.User.Identity); //Add PurchasingCustomer if none existing if (purchasingCustomer.ObjectId == new Guid()) { context.Customers.Add(purchasingCustomer); context.SaveChanges(); if (!currentUser.IsVendorAdmin) { context.UserCustomerRights.Add(new UserCustomerRight { RightObject = purchasingCustomer, RightId = EditEntityMembers.Id, UserId = currentUser.UserId }); context.SaveChanges(); } } //Add OwningCustomer if none existing if (owningCustomer != purchasingCustomer) { if (owningCustomer.ObjectId == new Guid()) { context.Customers.Add(owningCustomer); context.SaveChanges(); if (!currentUser.IsVendorAdmin) { context.UserCustomerRights.Add(new UserCustomerRight { RightObject = owningCustomer, RightId = EditEntityInfo.Id, UserId = currentUser.UserId }); context.SaveChanges(); } } } //Create licenses for every transactionitem foreach (var item in Transaction.TransactionItems) { if (item.License == null) { var newLicense = new Model.License(item.Sku, owningCustomer, purchasingCustomer); context.Licenses.Add(newLicense); item.License = newLicense; } } context.SaveChanges(); var existingCustomerApps = (from x in context.Licenses join y in context.LicenseCustomerApps on x.ObjectId equals y.LicenseId where x.OwningCustomerId == owningCustomer.ObjectId select y.CustomerApp).ToList(); //Add to any existing apps if (existingCustomerApps.Any()) { foreach (var customerApp in existingCustomerApps) { customerApp.AddLicenses((from x in Transaction.TransactionItems select x.License.ObjectId)); } context.SaveChanges(); } else { //Create default application containing all licenses var newCustomerApp = new CustomerApp() { ApplicationName = owningCustomer.Name + "_Application" }; context.CustomerApps.Add(newCustomerApp); newCustomerApp.AddLicenses((from x in Transaction.TransactionItems select x.License.ObjectId)); newCustomerApp.CustomerAppKeys.Add(new CustomerAppKey()); } Transaction.Status = TransactionStatus.Complete; context.SaveChanges(); }