public IHttpActionResult DoExport(CsvExportInfo exportInfo) { var notification = new ExportNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Catalog export task", Description = "starting export...." }; _notifier.Upsert(notification); var catalog = _catalogService.GetById(exportInfo.CatalogId); if (catalog == null) { throw new NullReferenceException("catalog"); } var curencySetting = _settingsManager.GetSettingByName("VirtoCommerce.Core.General.Currencies"); var defaultCurrency = EnumUtility.SafeParse <CurrencyCodes>(curencySetting.DefaultValue, CurrencyCodes.USD); var exportJob = new CsvCatalogExportJob(); BackgroundJob.Enqueue(() => exportJob.DoExport(exportInfo.CatalogId, exportInfo.CategoryIds, exportInfo.ProductIds, exportInfo.PriceListId, exportInfo.FulfilmentCenterId, exportInfo.Currency ?? defaultCurrency, catalog.DefaultLanguage.LanguageCode, notification)); return(Ok(notification)); }
public IHttpActionResult Publish(ImportManifest importManifest) { var settingsManager = ServiceLocator.Current.GetInstance <ISettingsManager>(); var packagesPath = settingsManager.GetValue("VirtoCommerce.ModulesPublishing.AppStoreImport.PackagesPath", String.Empty); importManifest.DefaultCategoryCode = settingsManager.GetValue("VirtoCommerce.ModulesPublishing.AppStoreImport.DefaultCategoryCode", String.Empty); importManifest.PackagesPath = HttpContext.Current.Server.MapPath(packagesPath); var notification = new ModulePublishingPushNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Import applications task", Description = "Task added and will start soon...." }; if (string.IsNullOrEmpty(importManifest.DefaultCategoryCode)) { notification.Errors.Add("Set 'Category code' setting, before import."); } if (string.IsNullOrEmpty(packagesPath)) { notification.Errors.Add("Set 'Packages folder' setting, before import."); } if (!Directory.Exists(importManifest.PackagesPath)) { notification.Errors.Add(string.Format("Path doesn't exists: {0}", importManifest.PackagesPath)); } if (notification.Errors.Count == 0) { BackgroundJob.Enqueue(() => ModulesImportBackground(importManifest, notification)); } _pushNotifier.Upsert(notification); return(Ok(notification)); }
private webModel.ModulePushNotification ScheduleJob(webModel.ModuleBackgroundJobOptions options) { var notification = new webModel.ModulePushNotification(CurrentPrincipal.GetCurrentUserName()); switch (options.Action) { case webModel.ModuleAction.Install: notification.Title = "Install Module"; break; case webModel.ModuleAction.Update: notification.Title = "Update Module"; break; case webModel.ModuleAction.Uninstall: notification.Title = "Uninstall Module"; break; } _pushNotifier.Upsert(notification); BackgroundJob.Enqueue(() => ModuleBackgroundJob(options, notification)); return(notification); }
internal static Node GetToDtoLambda(Type dtoType, CurrentPrincipal currentUser, string[] includes = null, string[] selects = null, char sepChar = defaultSepChar) { var includeSelects = new IncludeSelectOptions(dtoType, currentUser, includes, selects, sepChar); VisitNodes(includeSelects.RequiredMappings); return(includeSelects.RequiredMappings); }
public override void OnBeforeUpdate(DbEntityEntry entry, IAuditable item) { base.OnBeforeUpdate(entry, item); var currentTime = DateTime.UtcNow; item.ModifiedDate = currentTime; item.CreatedBy = CurrentPrincipal.GetCurrentUserName(); }
public MedSimDtoRepository(IPrincipal user, MedSimDbContext validationContext = null) { _contextProvider = new EFContextProvider <MedSimDbContext>(/*user , allowedRoles: new[] { RoleConstants.AccessAllData } */); _currentUser = new CurrentPrincipal(user, validationContext); _validationHelper = new ValidateMedSim(_currentUser); _contextProvider.BeforeSaveEntitiesDelegate += BeforeSaveEntities; _contextProvider.AfterSaveEntitiesDelegate += _validationHelper.AfterSave; _user = user; }
// // GET: /Admin/Home/ public ActionResult Index() { if (CurrentPrincipal.IsInRole(Roles.SuperAdmin)) { return(RedirectToAction("Index", "Users", new { area = "Admin" })); } //return RedirectToAction("Index", "Requests", new { area = "Admin" }); return(null); }
public override void OnBeforeInsert(DbEntityEntry entry, IAuditable item) { base.OnBeforeInsert(entry, item); var currentTime = DateTime.UtcNow; var currentUser = CurrentPrincipal.GetCurrentUserName(); item.CreatedDate = item.CreatedDate == default(DateTime) ? currentTime : item.CreatedDate; item.ModifiedDate = item.ModifiedDate ?? currentTime; item.CreatedBy = item.CreatedBy ?? currentUser; item.ModifiedBy = item.ModifiedBy ?? currentUser; }
public IncludeSelectOptions(Type dtoType, CurrentPrincipal currentUser, IList <string> includes = null, IList <string> selects = null, char sepChar = '.') { ValidateNoRepeats(includes, "includes"); ValidateNoRepeats(selects, "selects"); _sepChar = sepChar; _currentUser = currentUser; List <string[]> includeList = (includes == null) ? new List <string[]>() : new List <string[]>(includes.Select(i => i.Split(sepChar))); List <string[]> selectList = (selects == null) ? new List <string[]>() : new List <string[]>(selects.Select(i => i.Split(sepChar))); RequiredMappings = GetRequiredMappings(dtoType, includeList, selectList); //RequiredMappings.PrintPretty(" "); }
/// <summary> /// Initiates the scenario by handling a concrete instance of the <see cref="ICommand"/> /// </summary> /// <param name="command">Concrete instance of the command to be handled</param> /// <returns></returns> public CommandResult IsHandled(ICommand command) { if (command_handler == null) { throw new Exception("You must specify a command handler before calling CommandIsHandled"); } using (var currentPrincipal = CurrentPrincipal.SetPrincipalTo(principal)) { result_of_scenario = command_coordinator.Handle(command); return(result_of_scenario); } }
public IHttpActionResult DoImport(CsvImportInfo importInfo) { var notification = new ImportNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Import catalog from CSV", Description = "starting import...." }; _notifier.Upsert(notification); BackgroundJob.Enqueue(() => BackgroundImport(importInfo, notification)); return(Ok(notification)); }
/// <summary> /// States the entry2 operation log. /// </summary> /// <param name="objectType">Type of the object.</param> /// <param name="createdDate">The createdDate.</param> /// <param name="objectId">The key value.</param> /// <param name="state">The state.</param> /// <returns> /// OperationLog object /// </returns> private OperationLogEntity StateEntry2OperationLog(string objectType, DateTime createdDate, string objectId, EntityState state) { var retVal = new OperationLogEntity { Id = Guid.NewGuid().ToString("N"), CreatedDate = createdDate, ObjectId = objectId, ObjectType = objectType, CreatedBy = CurrentPrincipal.GetCurrentUserName(), OperationType = state.ToString() }; return(retVal); }
public IHttpActionResult ProcessImport(PlatformImportExportRequest importRequest) { var notification = new PlatformImportPushNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Platform import task", Description = "starting import...." }; _pushNotifier.Upsert(notification); BackgroundJob.Enqueue(() => PlatformImportBackground(importRequest, notification)); return(Ok(notification)); }
public IHttpActionResult StartImport(ShopifyImportParams importParams) { var notification = new ShopifyImportNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Import catalog from Shopify", Description = "starting import...." }; _notifier.Upsert(notification); BackgroundJob.Enqueue(() => _shopifyImportService.Import(importParams, notification)); return(Ok(notification)); }
public IHttpActionResult ProcessExport(PlatformExportImportRequest exportRequest) { var notification = new ExportImportProgressNotificationEvent(CurrentPrincipal.GetCurrentUserName()) { Title = "Platform export task", Description = "starting export...." }; _eventNotifier.Upsert(notification); var now = DateTime.UtcNow; BackgroundJob.Enqueue(() => PlatformExportBackground(exportRequest, PlatformVersion.CurrentVersion.ToString(), CurrentPrincipal.GetCurrentUserName(), notification)); return(Ok(notification)); }
public IHttpActionResult DoExport(CsvExportInfo exportInfo) { var notification = new ExportNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Catalog export task", Description = "starting export...." }; _notifier.Upsert(notification); BackgroundJob.Enqueue(() => BackgroundExport(exportInfo, notification)); return(Ok(notification)); }
// perform post intialization protected override void OnInitialized() { base.OnInitialized(); StatusProperty.DisplayFormat = $"{Header.FieldId} - {Header.FieldText}"; TerritoryIdProperty.SetCascadingProperty(Enumerations.SalesTerritory.Attributes.Group, GlobalRegionProperty); SalesPersonIdProperty.SetCascadingProperty(Enumerations.SalesPerson.Attributes.TerritoryId, TerritoryIdProperty); SalesPersonIdProperty.NullsMatchAnyCascading = true; SalesPersonIdProperty.DisplayListSeparator = "; "; if (CurrentPrincipal.IsStoreContact() || CurrentPrincipal.IsIndividualCustomer()) { CustomerStoreOperatorProperty.AccessLevel = AccessLevel.None; CustomerNameOperatorProperty.AccessLevel = AccessLevel.None; } }
public IHttpActionResult DoImport(CsvImportConfiguration importConfiguration) { var notification = new ImportNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Import catalog from CSV", Description = "starting import...." }; _notifier.Upsert(notification); var importJob = new CsvCatalogImportJob(); BackgroundJob.Enqueue(() => importJob.DoImport(importConfiguration, notification)); return(Ok(notification)); }
public IHttpActionResult DoImport(CsvImportInfo importInfo) { base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Import, importInfo); var notification = new ImportNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Import catalog from CSV", Description = "starting import...." }; _notifier.Upsert(notification); BackgroundJob.Enqueue(() => BackgroundImport(importInfo, notification)); return(Ok(notification)); }
public PlatformExportManifest GetNewExportManifest() { var retVal = new PlatformExportManifest { Author = CurrentPrincipal.GetCurrentUserName(), PlatformVersion = PlatformVersion.CurrentVersion.ToString(), Modules = InnerGetModulesWithInterface(typeof(ISupportExportImportModule)).Select(x => new ExportModuleInfo { Id = x.Id, Dependencies = x.Dependencies != null ? x.Dependencies.ToArray() : null, Version = x.Version, Description = ((ISupportExportImportModule)x.ModuleInfo.ModuleInstance).ExportDescription }).ToArray() }; return(retVal); }
public IHttpActionResult DoExport(CsvExportInfo exportInfo) { base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Export, exportInfo); var notification = new ExportNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Catalog export task", Description = "starting export...." }; _notifier.Upsert(notification); BackgroundJob.Enqueue(() => BackgroundExport(exportInfo, notification)); return(Ok(notification)); }
public ActionResult Index() { var backendUser = CurrentUser; if (backendUser != null) { if (CurrentPrincipal.IsInRole(Roles.SuperAdmin)) { return(RedirectToAction("Index", "Registers", new { area = "SuperAdmin" })); } if (CurrentPrincipal.IsInRole(Roles.Admin)) { return(RedirectToAction("Index", "Users", new { area = "Admin" })); } } return(RedirectToAction("Index", "Home", new { area = "Public" })); }
public IHttpActionResult DoExport(StoreExportConfiguration exportConfiguration) { var notification = new ExportNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Store export task", Description = "starting export...." }; _notifier.Upsert(notification); var store = _storeService.GetById(exportConfiguration.StoreId); if (store == null) { throw new NullReferenceException("store"); } var backupStoreJob = new BackupStoreJob(); BackgroundJob.Enqueue(() => backupStoreJob.DoExport(exportConfiguration, notification)); return(Ok(notification)); }
public LambdaExpression GetWhereExpression(CurrentPrincipal user) { return(WherePredicate == null ?null :WherePredicate(user)); }
/// <summary> /// Checks whether the Current user has the requested role. /// </summary> /// <param name="role">Role to check for</param> /// <returns>True is the user has the role, False otherwise</returns> public virtual bool IsInRole(string role) { return(CurrentPrincipal.Get().IsInRole(role)); }
public virtual async Task <Output <ICollection <SalesOrder_ReadListOutput> > > ReadListAsync(SalesOrder_ReadListInput_Criteria _criteria) { ICollection <SalesOrder_ReadListOutput> res = null; try { currentErrors.AbortIfHasErrors(); // CUSTOM_CODE_START: add custom security checks for ReadList operation below if (!CurrentPrincipal.IsEmployee() && !CurrentPrincipal.IsIndividualCustomer() && !CurrentPrincipal.IsStoreContact()) { currentErrors.CriticalError(ErrorType.Security, Messages.OperationNotAllowed); } // CUSTOM_CODE_END var src = from obj in ctx.SalesOrder select obj; // Source filter if (_criteria != null) { // CUSTOM_CODE_START: add code for GlobalRegion criteria of ReadList operation below src = AddClause(src, "GlobalRegion", o => o.TerritoryObject.Group, Operators.IsEqualTo, _criteria.GlobalRegion); // CUSTOM_CODE_END } // CUSTOM_CODE_START: add custom filter criteria to the source query for ReadList operation below if (CurrentPrincipal.IsStoreContact()) { int?storeId = CurrentPrincipal.GetStoreId(); src = src.Where(o => o.CustomerObject.StoreObject.BusinessEntityId == storeId); } if (CurrentPrincipal.IsIndividualCustomer()) { int?personId = CurrentPrincipal.GetPersonId(); src = src.Where(o => o.CustomerObject.PersonObject.BusinessEntityId == personId); } // CUSTOM_CODE_END var qry = from obj in src select new SalesOrder_ReadListOutput() { SalesOrderId = obj.SalesOrderId, SalesOrderNumber = obj.SalesOrderNumber, Status = obj.Status, OrderDate = obj.OrderDate, ShipDate = obj.ShipDate, DueDate = obj.DueDate, TotalDue = obj.TotalDue, OnlineOrderFlag = obj.OnlineOrderFlag, // CUSTOM_CODE_START: set the CustomerStore output parameter of ReadList operation below CustomerStore = obj.CustomerObject.StoreObject.Name, // CUSTOM_CODE_END // CUSTOM_CODE_START: set the CustomerName output parameter of ReadList operation below CustomerName = obj.CustomerObject.PersonObject.LastName + ", " + obj.CustomerObject.PersonObject.FirstName, // CUSTOM_CODE_END SalesPersonId = obj.SalesPersonId, TerritoryId = obj.TerritoryId, }; // Result filter if (_criteria != null) { qry = AddClause(qry, "SalesOrderNumber", o => o.SalesOrderNumber, _criteria.SalesOrderNumberOperator, _criteria.SalesOrderNumber); qry = AddClause(qry, "Status", o => o.Status, _criteria.StatusOperator, _criteria.Status); qry = AddClause(qry, "OrderDate", o => o.OrderDate, _criteria.OrderDateOperator, _criteria.OrderDate, _criteria.OrderDate2); qry = AddClause(qry, "DueDate", o => o.DueDate, _criteria.DueDateOperator, _criteria.DueDate, _criteria.DueDate2); qry = AddClause(qry, "TotalDue", o => o.TotalDue, _criteria.TotalDueOperator, _criteria.TotalDue, _criteria.TotalDue2); qry = AddClause(qry, "CustomerStore", o => o.CustomerStore, _criteria.CustomerStoreOperator, _criteria.CustomerStore); qry = AddClause(qry, "CustomerName", o => o.CustomerName, _criteria.CustomerNameOperator, _criteria.CustomerName); qry = AddClause(qry, "TerritoryId", o => o.TerritoryId, _criteria.TerritoryIdOperator, _criteria.TerritoryId); qry = AddClause(qry, "SalesPersonId", o => o.SalesPersonId, _criteria.SalesPersonIdOperator, _criteria.SalesPersonId); } // CUSTOM_CODE_START: add custom filter criteria to the result query for ReadList operation below // qry = qry.Where(o => o.FieldName == VALUE); // CUSTOM_CODE_END currentErrors.AbortIfHasErrors(); res = await qry.ToListAsync(); } catch (Exception ex) { currentErrors.MergeWith(errorParser.FromException(ex)); } return(await Task.FromResult(new Output <ICollection <SalesOrder_ReadListOutput> >(currentErrors, res))); }
public static LambdaExpression GetWhereExpression(Type serverModelType, CurrentPrincipal user) { return(_serverDtoDictionary[serverModelType].GetWhereExpression(user)); }
/// <summary> /// /// </summary> /// <param name="funzione1">Ruolo da testare 1°</param> /// <param name="funzione2">Ruolo da testare 2°</param> /// <param name="operatore">and / or se entrambe sono vere o una delle due</param> /// <param name="procedura">la procedura della pagina da controllare</param> /// <returns></returns> /// public static bool CheckAccessRight(string accessRight) { return((CurrentPrincipal != null) && (CurrentPrincipal.IsInRole(accessRight))); }
/// <summary> /// predominantly for unit testing /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TMap"></typeparam> /// <param name="currentUser"></param> /// <param name="includes"></param> /// <param name="selects"></param> /// <param name="sepChar"></param> /// <returns></returns> public static Expression <Func <T, TMap> > GetToDtoLambda <T, TMap>(CurrentPrincipal currentUser, string[] includes = null, string[] selects = null, char sepChar = defaultSepChar) { var returnVar = GetToDtoLambda(typeof(TMap), currentUser, includes, selects, sepChar); return((Expression <Func <T, TMap> >)returnVar.SelectExpression); }
public static IQueryable <TMap> ProjectToDto <T, TMap>(this IQueryable <T> queryable, CurrentPrincipal currentUser, string[] includes = null, string[] selects = null, char sepChar = defaultSepChar) { var returnVar = GetToDtoLambda(typeof(TMap), currentUser, includes, selects, sepChar); if (returnVar.WhereExpression != null) { queryable = queryable.Where((Expression <Func <T, bool> >)returnVar.WhereExpression); } return(queryable.Select((Expression <Func <T, TMap> >)returnVar.SelectExpression)); }