/// <summary> /// Convert back to CustomerApp instance /// </summary> /// <param name="original">Original CustomerApp. If Null a new instance is created.</param> /// <returns>CustomerApp containing viewmodel data </returns> public Model.CustomerApp ToEntity(Model.CustomerApp original) { Model.CustomerApp current = original ?? new Model.CustomerApp(); current.CustomerAppId = this.CustomerAppId; current.ApplicationName = this.ApplicationName; return(current); }
public bool TryToSaveCustomerApp(IDataContextByUser context, Action <string, string> modelErrorAccumulator) { Model.CustomerApp customerApp; if (!ApplicationId.HasValue) { customerApp = new Model.CustomerApp(); customerApp.CustomerAppKeys.Add(new CustomerAppKey() { }); context.CustomerApps.Add(customerApp); } else { customerApp = context.CustomerApps.Where(a => a.CustomerAppId == ApplicationId.Value).SingleOrDefault(); } customerApp.ApplicationName = ApplicationName; var allowedLicenses = context.Licenses.Where(l => SelectedLicenseGUIDs.Contains(l.ObjectId)).ToArray(); if (SelectedLicenseGUIDs.Count() != allowedLicenses.Count()) { modelErrorAccumulator("", "Attempted to license application with unrecognized or unpermitted license."); } else { customerApp.LicenseCustomerApps.Clear(); customerApp.LicenseCustomerApps.AddRange( allowedLicenses.Select(lid => new LicenseCustomerApp() { CustomerApp = customerApp, License = lid })); try { context.SaveChanges(); return(true); } catch (BusinessRuleValidationException ex) { foreach (var error in ex.ValidationResults.Where(x => x != BusinessRuleValidationResult.Success)) { modelErrorAccumulator("CustomerApp." + error.PropertyName, error.ErrorMessage); } } } return(false); }
public CustomerAppIndexViewItem(Model.CustomerApp customerApp, IEnumerable <Model.License> customerAppLicenses) : base(customerApp) { LicenseSummary = customerAppLicenses.ToSummary(x => x.Sku.SkuCode, 3, ", "); if (customerApp.CustomerAppKeys.Any()) { ActiveCustomerAppKey = customerApp.CustomerAppKeys.Last().AppKey; } WebConfigExample = string.Format(example, ActiveCustomerAppKey); IssueCount = customerApp.CustomerAppIssues.Count; }
/// <summary> /// Construct viewmodel /// </summary> /// <param name="CustomerApp">CustomerApp that this viewmodel represents</param> public CustomerAppViewModel(Model.CustomerApp customerApp) : this() { this.CustomerAppId = customerApp.CustomerAppId; this.ApplicationName = customerApp.ApplicationName; }
public bool TryToSaveCustomerApp(IDataContextByUser context, Action<string, string> modelErrorAccumulator) { Model.CustomerApp customerApp; if (!ApplicationId.HasValue) { customerApp = new Model.CustomerApp(); customerApp.CustomerAppKeys.Add(new CustomerAppKey() {}); context.CustomerApps.Add(customerApp); } else { customerApp = context.CustomerApps.Where(a => a.CustomerAppId == ApplicationId.Value).SingleOrDefault(); } customerApp.ApplicationName = ApplicationName; var allowedLicenses = context.Licenses.Where(l => SelectedLicenseGUIDs.Contains(l.ObjectId)).ToArray(); if (SelectedLicenseGUIDs.Count() != allowedLicenses.Count()) { modelErrorAccumulator("", "Attempted to license application with unrecognized or unpermitted license."); } else { customerApp.LicenseCustomerApps.Clear(); customerApp.LicenseCustomerApps.AddRange( allowedLicenses.Select(lid => new LicenseCustomerApp() { CustomerApp = customerApp, License = lid })); try { context.SaveChanges(); return true; } catch (BusinessRuleValidationException ex) { foreach (var error in ex.ValidationResults.Where(x => x != BusinessRuleValidationResult.Success)) { modelErrorAccumulator("CustomerApp." + error.PropertyName, error.ErrorMessage); } } } return false; }