Пример #1
0
        /// <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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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;
        }
Пример #4
0
 /// <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;
 }
Пример #5
0
        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;
        }