/// <summary> /// Prepare customer role product search model /// </summary> /// <param name="searchModel">Customer role product search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the customer role product search model /// </returns> public virtual async Task <CustomerRoleProductSearchModel> PrepareCustomerRoleProductSearchModelAsync(CustomerRoleProductSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //a vendor should have access only to his products searchModel.IsLoggedInAsVendor = await _workContext.GetCurrentVendorAsync() != null; //prepare available categories await _baseAdminModelFactory.PrepareCategoriesAsync(searchModel.AvailableCategories); //prepare available manufacturers await _baseAdminModelFactory.PrepareManufacturersAsync(searchModel.AvailableManufacturers); //prepare available stores await _baseAdminModelFactory.PrepareStoresAsync(searchModel.AvailableStores); //prepare available vendors await _baseAdminModelFactory.PrepareVendorsAsync(searchModel.AvailableVendors); //prepare available product types await _baseAdminModelFactory.PrepareProductTypesAsync(searchModel.AvailableProductTypes); //prepare page parameters searchModel.SetPopupGridPageSize(); return(searchModel); }
protected virtual async Task <IPagedList <BestsellersReportLine> > GetBestsellersReportAsync(BestsellerSearchModel searchModel) { //get parameters to filter bestsellers var orderStatus = searchModel.OrderStatusId > 0 ? (OrderStatus?)searchModel.OrderStatusId : null; var paymentStatus = searchModel.PaymentStatusId > 0 ? (PaymentStatus?)searchModel.PaymentStatusId : null; if (await _workContext.GetCurrentVendorAsync() != null) { searchModel.VendorId = (await _workContext.GetCurrentVendorAsync()).Id; } var startDateValue = !searchModel.StartDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = !searchModel.EndDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); //get bestsellers var bestsellers = await _orderReportService.BestSellersReportAsync(showHidden : true, createdFromUtc : startDateValue, createdToUtc : endDateValue, os : orderStatus, ps : paymentStatus, billingCountryId : searchModel.BillingCountryId, orderBy : OrderByEnum.OrderByTotalAmount, vendorId : searchModel.VendorId, categoryId : searchModel.CategoryId, manufacturerId : searchModel.ManufacturerId, storeId : searchModel.StoreId, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); return(bestsellers); }
/// <summary> /// Prepare the vendor info model /// </summary> /// <param name="model">Vendor info model</param> /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param> /// <param name="overriddenVendorAttributesXml">Overridden vendor attributes in XML format; pass null to use VendorAttributes of vendor</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the vendor info model /// </returns> public virtual async Task <VendorInfoModel> PrepareVendorInfoModelAsync(VendorInfoModel model, bool excludeProperties, string overriddenVendorAttributesXml = "") { if (model == null) { throw new ArgumentNullException(nameof(model)); } var vendor = await _workContext.GetCurrentVendorAsync(); if (!excludeProperties) { model.Description = vendor.Description; model.Email = vendor.Email; model.Name = vendor.Name; } var picture = await _pictureService.GetPictureByIdAsync(vendor.PictureId); var pictureSize = _mediaSettings.AvatarPictureSize; (model.PictureUrl, _) = picture != null ? await _pictureService.GetPictureUrlAsync(picture, pictureSize) : (string.Empty, null); //vendor attributes if (string.IsNullOrEmpty(overriddenVendorAttributesXml)) { overriddenVendorAttributesXml = await _genericAttributeService.GetAttributeAsync <string>(vendor, NopVendorDefaults.VendorAttributes); } model.VendorAttributes = await PrepareVendorAttributesAsync(overriddenVendorAttributesXml); return(model); }
public virtual async Task <IActionResult> ImportFromXlsx(IFormFile importexcelfile) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } //a vendor cannot import manufacturers if (await _workContext.GetCurrentVendorAsync() != null) { return(AccessDeniedView()); } try { if (importexcelfile != null && importexcelfile.Length > 0) { await _importManager.ImportManufacturersFromXlsxAsync(importexcelfile.OpenReadStream()); } else { _notificationService.ErrorNotification(await _localizationService.GetResourceAsync("Admin.Common.UploadFile")); return(RedirectToAction("List")); } _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Catalog.Manufacturers.Imported")); return(RedirectToAction("List")); } catch (Exception exc) { await _notificationService.ErrorNotificationAsync(exc); return(RedirectToAction("List")); } }
public virtual async Task <IActionResult> AssociateProductToCustomerRolePopup([Bind(Prefix = nameof(AddProductToCustomerRoleModel))] AddProductToCustomerRoleModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCustomers) || !await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAcl)) { return(AccessDeniedView()); } //try to get a product with the specified id var associatedProduct = await _productService.GetProductByIdAsync(model.AssociatedToProductId); if (associatedProduct == null) { return(Content("Cannot load a product")); } //a vendor should have access only to his products if (await _workContext.GetCurrentVendorAsync() != null && associatedProduct.VendorId != (await _workContext.GetCurrentVendorAsync()).Id) { return(Content("This is not your product")); } ViewBag.RefreshPage = true; ViewBag.productId = associatedProduct.Id; ViewBag.productName = associatedProduct.Name; return(View(new CustomerRoleProductSearchModel())); }
public virtual async Task <IActionResult> Edit(int id) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProductReviews)) { return(AccessDeniedView()); } //try to get a product review with the specified id var productReview = await _productService.GetProductReviewByIdAsync(id); if (productReview == null) { return(RedirectToAction("List")); } //a vendor should have access only to his products if (await _workContext.GetCurrentVendorAsync() != null && (await _productService.GetProductByIdAsync(productReview.ProductId)).VendorId != (await _workContext.GetCurrentVendorAsync()).Id) { return(RedirectToAction("List")); } //prepare model var model = await _productReviewModelFactory.PrepareProductReviewModelAsync(null, productReview); return(View(model)); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> Info() { if (!await _customerService.IsRegisteredAsync(await _workContext.GetCurrentCustomerAsync())) { return(Challenge()); } if (await _workContext.GetCurrentVendorAsync() == null || !_vendorSettings.AllowVendorsToEditInfo) { return(RedirectToRoute("CustomerInfo")); } var model = new VendorInfoModel(); model = await _vendorModelFactory.PrepareVendorInfoModelAsync(model, false); return(View(model)); }
public virtual async Task <IActionResult> SearchAutoComplete(string term) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.AccessAdminPanel)) { return(Content(string.Empty)); } const int searchTermMinimumLength = 3; if (string.IsNullOrWhiteSpace(term) || term.Length < searchTermMinimumLength) { return(Content(string.Empty)); } //a vendor should have access only to his products var vendorId = 0; if (await _workContext.GetCurrentVendorAsync() != null) { vendorId = (await _workContext.GetCurrentVendorAsync()).Id; } //products const int productNumber = 15; var products = await _productService.SearchProductsAsync(0, vendorId : vendorId, keywords : term, pageSize : productNumber, showHidden : true); var result = (from p in products select new { label = p.Name, productid = p.Id }).ToList(); return(Json(result)); }
public ProductReviewValidator(ILocalizationService localizationService, INopDataProvider dataProvider, IWorkContext workContext) { var isLoggedInAsVendor = workContext.GetCurrentVendorAsync().Result != null; //vendor can edit "Reply text" only if (!isLoggedInAsVendor) { RuleFor(x => x.Title).NotEmpty().WithMessageAwait(localizationService.GetResourceAsync("Admin.Catalog.ProductReviews.Fields.Title.Required")); RuleFor(x => x.ReviewText).NotEmpty().WithMessageAwait(localizationService.GetResourceAsync("Admin.Catalog.ProductReviews.Fields.ReviewText.Required")); } SetDatabaseValidationRules <ProductReview>(dataProvider); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> DeleteSelected(ICollection <int> selectedIds) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCategories)) { return(AccessDeniedView()); } if (selectedIds != null) { await _categoryService.DeleteCategoriesAsync(await (await _categoryService.GetCategoriesByIdsAsync(selectedIds.ToArray())).WhereAwait(async p => await _workContext.GetCurrentVendorAsync() == null).ToListAsync()); } return(Json(new { Result = true })); }
/// <summary> /// Prepare product review search model /// </summary> /// <param name="searchModel">Product review search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the product review search model /// </returns> public virtual async Task <ProductReviewSearchModel> PrepareProductReviewSearchModelAsync(ProductReviewSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } searchModel.IsLoggedInAsVendor = await _workContext.GetCurrentVendorAsync() != null; //prepare available stores await _baseAdminModelFactory.PrepareStoresAsync(searchModel.AvailableStores); //prepare "approved" property (0 - all; 1 - approved only; 2 - disapproved only) searchModel.AvailableApprovedOptions.Add(new SelectListItem { Text = await _localizationService.GetResourceAsync("Admin.Catalog.ProductReviews.List.SearchApproved.All"), Value = "0" }); searchModel.AvailableApprovedOptions.Add(new SelectListItem { Text = await _localizationService.GetResourceAsync("Admin.Catalog.ProductReviews.List.SearchApproved.ApprovedOnly"), Value = "1" }); searchModel.AvailableApprovedOptions.Add(new SelectListItem { Text = await _localizationService.GetResourceAsync("Admin.Catalog.ProductReviews.List.SearchApproved.DisapprovedOnly"), Value = "2" }); searchModel.HideStoresList = _catalogSettings.IgnoreStoreLimitations || searchModel.AvailableStores.SelectionIsNotPossible(); //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <summary> /// Prepare dashboard model /// </summary> /// <param name="model">Dashboard model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the dashboard model /// </returns> public virtual async Task <DashboardModel> PrepareDashboardModelAsync(DashboardModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } model.IsLoggedInAsVendor = await _workContext.GetCurrentVendorAsync() != null; //prepare nested search models await _commonModelFactory.PreparePopularSearchTermSearchModelAsync(model.PopularSearchTerms); await _orderModelFactory.PrepareBestsellerBriefSearchModelAsync(model.BestsellersByAmount); await _orderModelFactory.PrepareBestsellerBriefSearchModelAsync(model.BestsellersByQuantity); return(model); }
/// <summary> /// Called early in the filter pipeline to confirm request is authorized /// </summary> /// <param name="context">Authorization filter context</param> /// <returns>A task that represents the asynchronous operation</returns> private async Task ValidateVendorAsync(AuthorizationFilterContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!await DataSettingsManager.IsDatabaseInstalledAsync()) { return; } //check whether this filter has been overridden for the Action var actionFilter = context.ActionDescriptor.FilterDescriptors .Where(filterDescriptor => filterDescriptor.Scope == FilterScope.Action) .Select(filterDescriptor => filterDescriptor.Filter) .OfType <ValidateVendorAttribute>() .FirstOrDefault(); //ignore filter (the action is available even if the current customer isn't a vendor) if (actionFilter?.IgnoreFilter ?? _ignoreFilter) { return; } //whether current customer is vendor var customer = await _workContext.GetCurrentCustomerAsync(); if (!await _customerService.IsVendorAsync(customer)) { return; } //ensure that this user has active vendor record associated var vendor = await _workContext.GetCurrentVendorAsync(); if (vendor == null) { context.Result = new ChallengeResult(); } }
/// <summary> /// Invoke view component /// </summary> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the view component result /// </returns> public async Task <IViewComponentResult> InvokeAsync() { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCustomers) || !await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageOrders) || !await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageReturnRequests) || !await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts)) { return(Content(string.Empty)); } //a vendor doesn't have access to this report if (await _workContext.GetCurrentVendorAsync() != null) { return(Content(string.Empty)); } //prepare model var model = await _commonModelFactory.PrepareCommonStatisticsModelAsync(); return(View(model)); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> ProductDetails(int productId, int updatecartitemid = 0) { var product = await _productService.GetProductByIdAsync(productId); if (product == null || product.Deleted) { return(InvokeHttp404()); } var notAvailable = //published? (!product.Published && !_catalogSettings.AllowViewUnpublishedProductPage) || //ACL (access control list) !await _aclService.AuthorizeAsync(product) || //Store mapping !await _storeMappingService.AuthorizeAsync(product) || //availability dates !_productService.ProductIsAvailable(product); //Check whether the current user has a "Manage products" permission (usually a store owner) //We should allows him (her) to use "Preview" functionality var hasAdminAccess = await _permissionService.AuthorizeAsync(StandardPermissionProvider.AccessAdminPanel) && await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts); if (notAvailable && !hasAdminAccess) { return(InvokeHttp404()); } //visible individually? if (!product.VisibleIndividually) { //is this one an associated products? var parentGroupedProduct = await _productService.GetProductByIdAsync(product.ParentGroupedProductId); if (parentGroupedProduct == null) { return(RedirectToRoute("Homepage")); } return(RedirectToRoutePermanent("Product", new { SeName = await _urlRecordService.GetSeNameAsync(parentGroupedProduct) })); } //update existing shopping cart or wishlist item? ShoppingCartItem updatecartitem = null; if (_shoppingCartSettings.AllowCartItemEditing && updatecartitemid > 0) { var cart = await _shoppingCartService.GetShoppingCartAsync(await _workContext.GetCurrentCustomerAsync(), storeId : (await _storeContext.GetCurrentStoreAsync()).Id); updatecartitem = cart.FirstOrDefault(x => x.Id == updatecartitemid); //not found? if (updatecartitem == null) { return(RedirectToRoute("Product", new { SeName = await _urlRecordService.GetSeNameAsync(product) })); } //is it this product? if (product.Id != updatecartitem.ProductId) { return(RedirectToRoute("Product", new { SeName = await _urlRecordService.GetSeNameAsync(product) })); } } //save as recently viewed await _recentlyViewedProductsService.AddProductToRecentlyViewedListAsync(product.Id); //display "edit" (manage) link if (await _permissionService.AuthorizeAsync(StandardPermissionProvider.AccessAdminPanel) && await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts)) { //a vendor should have access only to his products if (await _workContext.GetCurrentVendorAsync() == null || (await _workContext.GetCurrentVendorAsync()).Id == product.VendorId) { DisplayEditLink(Url.Action("Edit", "Product", new { id = product.Id, area = AreaNames.Admin })); } } //activity log await _customerActivityService.InsertActivityAsync("PublicStore.ViewProduct", string.Format(await _localizationService.GetResourceAsync("ActivityLog.PublicStore.ViewProduct"), product.Name), product); //model var model = await _productModelFactory.PrepareProductDetailsModelAsync(product, updatecartitem, false); //template var productTemplateViewPath = await _productModelFactory.PrepareProductTemplateViewPathAsync(product); return(View(productTemplateViewPath, model)); }