public void ApplyToEntity(IDataContextByUser dataContext, Model.Feature feature) { var vendor = dataContext.Vendors.Single(v => v.ObjectId == Feature.VendorId); // Load the vendor to ensure its authorized feature.Vendor = vendor; feature.FeatureName = Feature.FeatureName; feature.FeatureCode = Feature.FeatureCode; }
private void CheckAuthorizedToCreate(IDataContextByUser context) { var user = context.GetUser(HttpContext.User.Identity); if (!user.IsVendorAdmin && !user.IsSystemAdmin) { throw new UnauthorizedAccessException("Only system or vendor admins may create customers."); } }
public static FeatureCreateEditViewModel ForCreate(IDataContextByUser context) { FeatureCreateEditViewModel viewModel = new FeatureCreateEditViewModel() { Feature = new FeatureViewModel(new Model.Feature()), VendorList = context.Vendors.ToList().ToSelectList(v => v.ObjectId, v => v.Name) }; return(viewModel); }
public static FeatureCreateEditViewModel ForCreate(IDataContextByUser context) { FeatureCreateEditViewModel viewModel = new FeatureCreateEditViewModel() { Feature = new FeatureViewModel(new Model.Feature()), VendorList = context.Vendors.ToList().ToSelectList(v => v.ObjectId, v => v.Name) }; return viewModel; }
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 static FeatureCreateEditViewModel ForEdit(IDataContextByUser context, Guid key) { var feature = context.Features.SingleOrDefault(f => f.FeatureId == key); if (feature == null) { return(null); } else { var viewModel = ForCreate(context); viewModel.Feature = new FeatureViewModel(feature); return(viewModel); } }
public static FeatureCreateEditViewModel ForEdit(IDataContextByUser context, Guid key) { var feature = context.Features.SingleOrDefault(f => f.FeatureId == key); if (feature == null) { return null; } else { var viewModel = ForCreate(context); viewModel.Feature = new FeatureViewModel(feature); return viewModel; } }
public static CustomerAppCreateEditModel ForEdit(IDataContextByUser context, Guid key) { var model = ForCreate(context); var customerApp = context.CustomerApps.Where(a => a.CustomerAppId == key) .Include(a => a.LicenseCustomerApps) .SingleOrDefault(); if (customerApp == null) return null; model.ApplicationId = customerApp.CustomerAppId; model.ApplicationName = customerApp.ApplicationName; model.SelectedLicenseGUIDs = customerApp.LicenseCustomerApps.Select(lca => lca.LicenseId).ToList(); return model; }
public static CustomerAppCreateEditModel ForEdit(IDataContextByUser context, Guid key) { var model = ForCreate(context); var customerApp = context.CustomerApps.Where(a => a.CustomerAppId == key) .Include(a => a.LicenseCustomerApps) .SingleOrDefault(); if (customerApp == null) { return(null); } model.ApplicationId = customerApp.CustomerAppId; model.ApplicationName = customerApp.ApplicationName; model.SelectedLicenseGUIDs = customerApp.LicenseCustomerApps.Select(lca => lca.LicenseId).ToList(); return(model); }
private static ActionResult LoadDomainLicenseForRemoval(IDataContextByUser context, Guid key, out DomainLicense domainLicense) { domainLicense = context.DomainLicenses .Include(dl => dl.License) .Include(dl => dl.License.Sku) .SingleOrDefault(x => x.DomainLicenseId == key); if (domainLicense == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } if (!domainLicense.CanBeManuallyDeleted) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(null); }
public static CustomerAppCreateEditModel ForCreate(IDataContextByUser context) { CustomerAppCreateEditModel viewModel; var availableLicenses = (from x in context.Licenses select x) .Include(x => x.Sku) .Include(x => x.OwningCustomer) .ToList(); viewModel = new CustomerAppCreateEditModel() { LicenseList = availableLicenses.Select(l => new SelectListItem() { Text = String.Format("{0} owned by {1}", l.Sku.SkuCode, l.OwningCustomer.Name), Value = l.ObjectId.ToString() }).ToList(), SelectedLicenseGUIDs = new List<Guid>() }; return viewModel; }
public static CustomerAppCreateEditModel ForCreate(IDataContextByUser context) { CustomerAppCreateEditModel viewModel; var availableLicenses = (from x in context.Licenses select x) .Include(x => x.Sku) .Include(x => x.OwningCustomer) .ToList(); viewModel = new CustomerAppCreateEditModel() { LicenseList = availableLicenses.Select(l => new SelectListItem() { Text = String.Format("{0} owned by {1}", l.Sku.SkuCode, l.OwningCustomer.Name), Value = l.ObjectId.ToString() }).ToList(), SelectedLicenseGUIDs = new List <Guid>() }; return(viewModel); }
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; }
private static ActionResult LoadDomainLicenseForRemoval(IDataContextByUser context, Guid key, out DomainLicense domainLicense) { domainLicense = context.DomainLicenses .Include(dl => dl.License) .Include(dl => dl.License.Sku) .SingleOrDefault(x => x.DomainLicenseId == key); if (domainLicense == null) { return new HttpStatusCodeResult(HttpStatusCode.NotFound); } if (!domainLicense.CanBeManuallyDeleted) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError); } return null; }
private void CheckAuthorizedToCreate(IDataContextByUser context) { var user = context.GetUser(HttpContext.User.Identity); if (!user.IsVendorAdmin && !user.IsSystemAdmin) throw new UnauthorizedAccessException("Only system or vendor admins may create customers."); }