public void Should_not_have_error_when_pageSizeOptions_is_null_or_empty() { var model = new ManufacturerModel(); model.PageSizeOptions = null; _validator.ShouldNotHaveValidationErrorFor(x => x.PageSizeOptions, model); model.PageSizeOptions = ""; _validator.ShouldNotHaveValidationErrorFor(x => x.PageSizeOptions, model); }
public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var model = new ManufacturerModel(); //locales AddLocales(_languageService, model.Locales); //templates PrepareTemplatesModel(model); //default values model.PageSize = 4; model.Published = true; model.AllowCustomersToSelectPageSize = true; model.PageSizeOptions = _catalogSettings.DefaultManufacturerPageSizeOptions; return View(model); }
private void PrepareManufacturerModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (manufacturer != null) { model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(manufacturer); } else { model.SelectedStoreIds = new int[0]; } } if (manufacturer != null) { model.CreatedOn = _dateTimeHelper.ConvertToUserTime(manufacturer.CreatedOnUtc, DateTimeKind.Utc); model.UpdatedOn = _dateTimeHelper.ConvertToUserTime(manufacturer.UpdatedOnUtc, DateTimeKind.Utc); } }
public ActionResult ProductAddPopupList(GridCommand command, ManufacturerModel.AddManufacturerProductModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var gridModel = new GridModel(); IList<int> filterableSpecificationAttributeOptionIds = null; var products = _productService.SearchProducts(model.SearchCategoryId, model.SearchManufacturerId, null, null, null, 0, model.SearchProductName, false, false, _workContext.WorkingLanguage.Id, new List<int>(), ProductSortingEnum.Position, command.Page - 1, command.PageSize, false, out filterableSpecificationAttributeOptionIds, true); gridModel.Data = products.Select(x => x.ToModel()); gridModel.Total = products.TotalCount; return new JsonResult { Data = gridModel }; }
protected virtual void PrepareStoresMappingModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); if (!excludeProperties && manufacturer != null) model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(manufacturer).ToList(); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { model.AvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString(), Selected = model.SelectedStoreIds.Contains(store.Id) }); } }
public void Should_not_have_error_when_pageSizeOptions_has_not_duplicate_items() { var model = new ManufacturerModel(); model.PageSizeOptions = "1, 2, 3, 5, 9"; _validator.ShouldNotHaveValidationErrorFor(x => x.PageSizeOptions, model); }
public ActionResult ProductUpdate(ManufacturerModel.ManufacturerProductModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); var productManufacturer = _manufacturerService.GetProductManufacturerById(model.Id); if (productManufacturer == null) throw new ArgumentException("No product manufacturer mapping found with the specified id"); productManufacturer.IsFeaturedProduct = model.IsFeaturedProduct; productManufacturer.DisplayOrder = model.DisplayOrder1; _manufacturerService.UpdateProductManufacturer(productManufacturer); return new NullJsonResult(); }
private void PrepareStoresMappingModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (manufacturer != null) { model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(manufacturer); } else { model.SelectedStoreIds = new int[0]; } } }
public static Manufacturer ToEntity(this ManufacturerModel model, Manufacturer destination) { return(Mapper.Map(model, destination)); }
public static Manufacturer ToEntity(this ManufacturerModel model) { return(Mapper.Map <ManufacturerModel, Manufacturer>(model)); }
public SelectManufacturerPageViewModel(INavigationService navigationService, IManufacturerService manufacturerService, IDialogService dialogService ) : base(navigationService, dialogService) { Title = "选择供应商"; _navigationService = navigationService; _dialogService = dialogService; _manufacturerService = manufacturerService; //Load this.Load = ManufacturersLoader.Load(async() => { //重载时排它 ItemTreshold = 1; try { //清除列表 Manufacturers.Clear(); var items = await GetManufacturersPage(0, PageSize); if (items != null) { foreach (var item in items) { if (Manufacturers.Count(s => s.Id == item.Id) == 0) { Manufacturers.Add(item); } } } } catch (Exception ex) { Crashes.TrackError(ex); } this.Manufacturers = new ObservableRangeCollection <ManufacturerModel>(Manufacturers); return(Manufacturers.ToList()); }); //以增量方式加载数据 this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() => { using (var dig = UserDialogs.Instance.Loading("加载中...")) { try { int pageIdex = Manufacturers.Count / (PageSize == 0 ? 1 : PageSize); var items = await GetManufacturersPage(pageIdex, PageSize); var previousLastItem = Terminals.Last(); if (items != null) { foreach (var item in items) { if (Manufacturers.Count(s => s.Id == item.Id) == 0) { Manufacturers.Add(item); } } if (items.Count() == 0 || items.Count() == Terminals.Count) { ItemTreshold = -1; return(Manufacturers.ToList()); } } } catch (Exception ex) { Crashes.TrackError(ex); ItemTreshold = -1; } this.Manufacturers = new ObservableRangeCollection <ManufacturerModel>(Manufacturers); return(Manufacturers.ToList()); } }, this.WhenAny(x => x.Terminals, x => x.GetValue().Count > 0)); this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(async item => { await _navigationService.GoBackAsync(("Manufacturer", item)); this.Selecter = null; }).DisposeWith(DeactivateWith); this.BindBusyCommand(Load); }
/// <summary> /// Prepare manufacturer model /// </summary> /// <param name="manufacturer">Manufacturer identifier</param> /// <param name="command">Catalog paging filtering command</param> /// <returns>Manufacturer model</returns> public virtual ManufacturerModel PrepareManufacturerModel(Manufacturer manufacturer, CatalogPagingFilteringModel command) { if (manufacturer == null) { throw new ArgumentNullException(nameof(manufacturer)); } var model = new ManufacturerModel { Id = manufacturer.Id, Name = _localizationService.GetLocalized(manufacturer, x => x.Name), Description = _localizationService.GetLocalized(manufacturer, x => x.Description), MetaKeywords = _localizationService.GetLocalized(manufacturer, x => x.MetaKeywords), MetaDescription = _localizationService.GetLocalized(manufacturer, x => x.MetaDescription), MetaTitle = _localizationService.GetLocalized(manufacturer, x => x.MetaTitle), SeName = _urlRecordService.GetSeName(manufacturer), }; //sorting PrepareSortingOptions(model.PagingFilteringContext, command); //view mode PrepareViewModes(model.PagingFilteringContext, command); //page size PreparePageSizeOptions(model.PagingFilteringContext, command, manufacturer.AllowCustomersToSelectPageSize, manufacturer.PageSizeOptions, manufacturer.PageSize); //price ranges var selectedPriceRange = model.PagingFilteringContext.PriceRangeFilter.GetSelectedPriceRange(_webHelper, manufacturer.PriceRanges); decimal?minPriceConverted = null; decimal?maxPriceConverted = null; if (selectedPriceRange != null) { if (selectedPriceRange.From.HasValue) { minPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.From.Value, _workContext.WorkingCurrency); } if (selectedPriceRange.To.HasValue) { maxPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.To.Value, _workContext.WorkingCurrency); } } ////products //var products = _productService.SearchProducts(out IList<int> _, true, // manufacturerId: manufacturer.Id, // storeId: _storeContext.CurrentStore.Id, // visibleIndividuallyOnly: true, // featuredProducts: _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false, // priceMin: minPriceConverted, // priceMax: maxPriceConverted, // orderBy: (ProductSortingEnum)command.OrderBy, // pageIndex: command.PageNumber - 1, // pageSize: command.PageSize); //model.Products = _productModelFactory.PrepareProductOverviewModels(products).ToList(); //model.PagingFilteringContext.LoadPagedList(products); return(model); }
protected virtual List <LocalizedProperty> UpdateLocales(Manufacturer manufacturer, ManufacturerModel model) { List <LocalizedProperty> localized = new List <LocalizedProperty>(); foreach (var local in model.Locales) { if (!(String.IsNullOrEmpty(local.Description))) { localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Description", LocaleValue = local.Description, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } if (!(String.IsNullOrEmpty(local.MetaDescription))) { localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaDescription", LocaleValue = local.MetaDescription, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } if (!(String.IsNullOrEmpty(local.MetaKeywords))) { localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaKeywords", LocaleValue = local.MetaKeywords, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } if (!(String.IsNullOrEmpty(local.MetaTitle))) { localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaTitle", LocaleValue = local.MetaTitle, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } if (!(String.IsNullOrEmpty(local.Name))) { localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } //search engine name var seName = manufacturer.ValidateSeName(local.SeName, local.Name, false); _urlRecordService.SaveSlug(manufacturer, seName, local.LanguageId); if (!(String.IsNullOrEmpty(seName))) { localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "SeName", LocaleValue = seName, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } } return(localized); }
public virtual async Task <IActionResult> Create(ManufacturerModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var manufacturer = model.ToEntity <Manufacturer>(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; await _manufacturerService.InsertManufacturerAsync(manufacturer); //search engine name model.SeName = await _urlRecordService.ValidateSeNameAsync(manufacturer, model.SeName, manufacturer.Name, true); await _urlRecordService.SaveSlugAsync(manufacturer, model.SeName, 0); //locales await UpdateLocalesAsync(manufacturer, model); //discounts var allDiscounts = await _discountService.GetAllDiscountsAsync(DiscountType.AssignedToManufacturers, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //manufacturer.AppliedDiscounts.Add(discount); await _manufacturerService.InsertDiscountManufacturerMappingAsync(new DiscountManufacturerMapping { EntityId = manufacturer.Id, DiscountId = discount.Id }); } } await _manufacturerService.UpdateManufacturerAsync(manufacturer); //update picture seo file name await UpdatePictureSeoNamesAsync(manufacturer); //ACL (customer roles) await SaveManufacturerAclAsync(manufacturer, model); //stores await SaveStoreMappingsAsync(manufacturer, model); //activity log await _customerActivityService.InsertActivityAsync("AddNewManufacturer", string.Format(await _localizationService.GetResourceAsync("ActivityLog.AddNewManufacturer"), manufacturer.Name), manufacturer); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Catalog.Manufacturers.Added")); if (!continueEditing) { return(RedirectToAction("List")); } return(RedirectToAction("Edit", new { id = manufacturer.Id })); } //prepare model model = await _manufacturerModelFactory.PrepareManufacturerModelAsync(model, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
protected virtual void PrepareDiscountModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableDiscounts = _discountService .GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true) .Select(d => d.ToModel()) .ToList(); if (!excludeProperties && manufacturer != null) { model.SelectedDiscountIds = manufacturer.AppliedDiscounts.Select(d => d.Id).ToArray(); } }
private void PrepareAclModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); if (!excludeProperties) { if (manufacturer != null) { model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(manufacturer); } else { model.SelectedCustomerRoleIds = new int[0]; } } }
protected ManufacturerFacade(ManufacturerModel model) : base(model) { }
public ActionResult Create(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); if (ModelState.IsValid) { var manufacturer = model.ToEntity(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.InsertManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL (customer roles) SaveManufacturerAcl(manufacturer, model); //Stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("AddNewManufacturer", _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added")); return continueEditing ? RedirectToAction("Edit", new { id = manufacturer.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //ACL PrepareAclModel(model, null, true); //Stores PrepareStoresMappingModel(model, null, true); return View(model); }
public virtual IActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } //try to get a manufacturer with the specified id var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) { return(RedirectToAction("List")); } if (ModelState.IsValid) { var prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = _urlRecordService.ValidateSeName(manufacturer, model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //new discount if (_manufacturerService.GetDiscountAppliedToManufacturer(manufacturer.Id, discount.Id) is null) { _manufacturerService.InsertDiscountManufacturerMapping(new DiscountManufacturerMapping { EntityId = manufacturer.Id, DiscountId = discount.Id }); } } else { //remove discount if (_manufacturerService.GetDiscountAppliedToManufacturer(manufacturer.Id, discount.Id) is DiscountManufacturerMapping discountManufacturerMapping) { _manufacturerService.DeleteDiscountManufacturerMapping(discountManufacturerMapping); } } } _manufacturerService.UpdateManufacturer(manufacturer); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != manufacturer.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL SaveManufacturerAcl(manufacturer, model); //stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("EditManufacturer", string.Format(_localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name), manufacturer); _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); if (!continueEditing) { return(RedirectToAction("List")); } return(RedirectToAction("Edit", new { id = manufacturer.Id })); } //prepare model model = _manufacturerModelFactory.PrepareManufacturerModel(model, manufacturer, true); //if we got this far, something failed, redisplay form return(View(model)); }
public ActionResult ProductAddPopup(string btnId, string formId, ManufacturerModel.AddManufacturerProductModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); if (model.SelectedProductIds != null) { foreach (int id in model.SelectedProductIds) { var product = _productService.GetProductById(id); if (product != null) { var existingProductmanufacturers = _manufacturerService.GetProductManufacturersByManufacturerId(model.ManufacturerId, 0, int.MaxValue, true); if (existingProductmanufacturers.FindProductManufacturer(id, model.ManufacturerId) == null) { _manufacturerService.InsertProductManufacturer( new ProductManufacturer() { ManufacturerId = model.ManufacturerId, ProductId = id, IsFeaturedProduct = false, DisplayOrder = 1 }); } } } } ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return View(model); }
public virtual async Task <Manufacturer> UpdateManufacturerModel(Manufacturer manufacturer, ManufacturerModel model) { string prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; manufacturer.Locales = await model.Locales.ToLocalizedProperty(manufacturer, x => x.Name, _seoSettings, _urlRecordService, _languageService); //discounts var allDiscounts = await _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //new discount if (manufacturer.AppliedDiscounts.Count(d => d == discount.Id) == 0) { manufacturer.AppliedDiscounts.Add(discount.Id); } } else { //remove discount if (manufacturer.AppliedDiscounts.Count(d => d == discount.Id) > 0) { manufacturer.AppliedDiscounts.Remove(discount.Id); } } } model.SeName = await manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true, _seoSettings, _urlRecordService, _languageService); manufacturer.SeName = model.SeName; await _manufacturerService.UpdateManufacturer(manufacturer); //search engine name await _urlRecordService.SaveSlug(manufacturer, model.SeName, ""); //delete an old picture (if deleted or updated) if (!String.IsNullOrEmpty(prevPictureId) && prevPictureId != manufacturer.PictureId) { var prevPicture = await _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) { await _pictureService.DeletePicture(prevPicture); } } //update picture seo file name await _pictureService.UpdatePictureSeoNames(manufacturer.PictureId, manufacturer.Name); //activity log await _customerActivityService.InsertActivity("EditManufacturer", manufacturer.Id, _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); return(manufacturer); }
protected virtual async Task SaveStoreMappingsAsync(Manufacturer manufacturer, ManufacturerModel model) { manufacturer.LimitedToStores = model.SelectedStoreIds.Any(); await _manufacturerService.UpdateManufacturerAsync(manufacturer); var existingStoreMappings = await _storeMappingService.GetStoreMappingsAsync(manufacturer); var allStores = await _storeService.GetAllStoresAsync(); foreach (var store in allStores) { if (model.SelectedStoreIds.Contains(store.Id)) { //new store if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0) { await _storeMappingService.InsertStoreMappingAsync(manufacturer, store.Id); } } else { //remove store var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) { await _storeMappingService.DeleteStoreMappingAsync(storeMappingToDelete); } } } }
public ActionResult Create(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var manufacturer = model.ToEntity(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.InsertManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { manufacturer.AppliedDiscounts.Add(discount); } } _manufacturerService.UpdateManufacturer(manufacturer); //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL (customer roles) SaveManufacturerAcl(manufacturer, model); //Stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("AddNewManufacturer", _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added")); if (continueEditing) { //selected tab SaveSelectedTabName(); return(RedirectToAction("Edit", new { id = manufacturer.Id })); } return(RedirectToAction("List")); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //discounts PrepareDiscountModel(model, null, true); //ACL PrepareAclModel(model, null, true); //Stores PrepareStoresMappingModel(model, null, true); return(View(model)); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) //No manufacturer found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //locales UpdateLocales(manufacturer, model); //update picture seo file name UpdatePictureSeoNames(manufacturer); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); return continueEditing ? RedirectToAction("Edit", manufacturer.Id) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); return View(model); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) { //No manufacturer found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { int prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //new discount if (manufacturer.AppliedDiscounts.Count(d => d.Id == discount.Id) == 0) { manufacturer.AppliedDiscounts.Add(discount); } } else { //remove discount if (manufacturer.AppliedDiscounts.Count(d => d.Id == discount.Id) > 0) { manufacturer.AppliedDiscounts.Remove(discount); } } } _manufacturerService.UpdateManufacturer(manufacturer); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != manufacturer.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL SaveManufacturerAcl(manufacturer, model); //Stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); if (continueEditing) { //selected tab SaveSelectedTabName(); return(RedirectToAction("Edit", new { id = manufacturer.Id })); } return(RedirectToAction("List")); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //discounts PrepareDiscountModel(model, manufacturer, true); //ACL PrepareAclModel(model, manufacturer, true); //Stores PrepareStoresMappingModel(model, manufacturer, true); return(View(model)); }
protected void UpdateLocales(Manufacturer manufacturer, ManufacturerModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.Description, localized.Description, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.SeName, localized.SeName, localized.LanguageId); } }
public static Manufacturer ToEntity(this ManufacturerModel model, Manufacturer destination) { return(model.MapTo(destination)); }
public ActionResult ProductAddPopupList(GridCommand command, ManufacturerModel.AddManufacturerProductModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var gridModel = new GridModel(); var ctx = new ProductSearchContext(); if (model.SearchCategoryId > 0) ctx.CategoryIds.Add(model.SearchCategoryId); ctx.ManufacturerId = model.SearchManufacturerId; ctx.Keywords = model.SearchProductName; ctx.LanguageId = _workContext.WorkingLanguage.Id; ctx.OrderBy = ProductSortingEnum.Position; ctx.PageIndex = command.Page - 1; ctx.PageSize = command.PageSize; ctx.ShowHidden = true; ctx.ProductType = model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null; var products = _productService.SearchProducts(ctx); gridModel.Data = products.Select(x => { var productModel = x.ToModel(); productModel.ProductTypeName = x.GetProductTypeLabel(_localizationService); return productModel; }); gridModel.Total = products.TotalCount; return new JsonResult { Data = gridModel }; }
public static Manufacturer ToEntity(this ManufacturerModel model) { return(model.MapTo <ManufacturerModel, Manufacturer>()); }
public ActionResult ProductAddPopupList(GridCommand command, ManufacturerModel.AddManufacturerProductModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var gridModel = new GridModel(); var products = _productService.SearchProducts( categoryIds: new List<int>() { model.SearchCategoryId }, manufacturerId: model.SearchManufacturerId, keywords: model.SearchProductName, pageIndex: command.Page - 1, pageSize: command.PageSize, showHidden: true ); gridModel.Data = products.Select(x => x.ToModel()); gridModel.Total = products.TotalCount; return new JsonResult { Data = gridModel }; }
public ActionResult ProductAddPopup(string btnId, string formId, ManufacturerModel.AddManufacturerProductModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); if (model.SelectedProductIds != null) { foreach (int id in model.SelectedProductIds) { var product = _productService.GetProductById(id); if (product != null) { var existingProductmanufacturers = product.ProductManufacturers; if (product.ProductManufacturers.Where(x => x.ManufacturerId == model.ManufacturerId).Count() == 0) { _manufacturerService.InsertProductManufacturer( new ProductManufacturer { ManufacturerId = model.ManufacturerId, ProductId = id, IsFeaturedProduct = false, DisplayOrder = 1, _id = ObjectId.GenerateNewId().ToString(), Id = product.ProductManufacturers.Count > 0 ? product.ProductManufacturers.Max(x => x.Id) + 1 : 1, }); } } } } ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return View(model); }
protected void PrepareTemplatesModel(ManufacturerModel model) { if (model == null) throw new ArgumentNullException("model"); var templates = _manufacturerTemplateService.GetAllManufacturerTemplates(); foreach (var template in templates) { model.AvailableManufacturerTemplates.Add(new SelectListItem() { Text = template.Name, Value = template.Id.ToString() }); } }
protected virtual void PrepareAclModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); if (!excludeProperties) { if (manufacturer != null) { model.SelectedCustomerRoleIds = manufacturer.CustomerRoles.ToArray(); } } }
protected void SaveManufacturerAcl(Manufacturer manufacturer, ManufacturerModel model) { var existingAclRecords = _aclService.GetAclRecords(manufacturer); var allCustomerRoles = _customerService.GetAllCustomerRoles(true); foreach (var customerRole in allCustomerRoles) { if (model.SelectedCustomerRoleIds != null && model.SelectedCustomerRoleIds.Contains(customerRole.Id)) { //new role if (existingAclRecords.Count(acl => acl.CustomerRoleId == customerRole.Id) == 0) _aclService.InsertAclRecord(manufacturer, customerRole.Id); } else { //removed role var aclRecordToDelete = existingAclRecords.FirstOrDefault(acl => acl.CustomerRoleId == customerRole.Id); if (aclRecordToDelete != null) _aclService.DeleteAclRecord(aclRecordToDelete); } } }
protected virtual void PrepareStoresMappingModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (manufacturer != null) { model.SelectedStoreIds = manufacturer.Stores.ToArray(); } } }
protected void SaveStoreMappings(Manufacturer manufacturer, ManufacturerModel model) { var existingStoreMappings = _storeMappingService.GetStoreMappings(manufacturer); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { if (model.SelectedStoreIds != null && model.SelectedStoreIds.Contains(store.Id)) { //new role if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0) _storeMappingService.InsertStoreMapping(manufacturer, store.Id); } else { //removed role var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) _storeMappingService.DeleteStoreMapping(storeMappingToDelete); } } }
protected virtual List<LocalizedProperty> UpdateLocales(Manufacturer manufacturer, ManufacturerModel model) { List<LocalizedProperty> localized = new List<LocalizedProperty>(); foreach (var local in model.Locales) { if (!(String.IsNullOrEmpty(local.Description))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Description", LocaleValue = local.Description, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.MetaDescription))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaDescription", LocaleValue = local.MetaDescription, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.MetaKeywords))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaKeywords", LocaleValue = local.MetaKeywords, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.MetaTitle))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaTitle", LocaleValue = local.MetaTitle, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.Name))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); //search engine name var seName = manufacturer.ValidateSeName(local.SeName, local.Name, false); _urlRecordService.SaveSlug(manufacturer, seName, local.LanguageId); if (!(String.IsNullOrEmpty(seName))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "SeName", LocaleValue = seName, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } return localized; }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) //No manufacturer found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { int prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != manufacturer.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) _pictureService.DeletePicture(prevPicture); } //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL SaveManufacturerAcl(manufacturer, model); //Stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); if (continueEditing) { //selected tab SaveSelectedTabIndex(); return RedirectToAction("Edit", manufacturer.Id); } else { return RedirectToAction("List"); } } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //ACL PrepareAclModel(model, manufacturer, true); //Stores PrepareStoresMappingModel(model, manufacturer, true); return View(model); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) //No manufacturer found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { int prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //new discount if (manufacturer.AppliedDiscounts.Count(d => d.Id == discount.Id) == 0) manufacturer.AppliedDiscounts.Add(discount); } else { //remove discount if (manufacturer.AppliedDiscounts.Count(d => d.Id == discount.Id) > 0) manufacturer.AppliedDiscounts.Remove(discount); } } _manufacturerService.UpdateManufacturer(manufacturer); //update "HasDiscountsApplied" property _manufacturerService.UpdateHasDiscountsApplied(manufacturer); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != manufacturer.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) _pictureService.DeletePicture(prevPicture); } //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL SaveManufacturerAcl(manufacturer, model); //Stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); if (continueEditing) { //selected tab SaveSelectedTabIndex(); return RedirectToAction("Edit", new {id = manufacturer.Id}); } return RedirectToAction("List"); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //discounts PrepareDiscountModel(model, manufacturer, true); //ACL PrepareAclModel(model, manufacturer, true); //Stores PrepareStoresMappingModel(model, manufacturer, true); return View(model); }
public ActionResult ProductAddPopupList(DataSourceRequest command, ManufacturerModel.AddManufacturerProductModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); var gridModel = new DataSourceResult(); var products = _productService.SearchProducts( categoryIds: new List<int>() { model.SearchCategoryId }, manufacturerId: model.SearchManufacturerId, storeId: model.SearchStoreId, vendorId: model.SearchVendorId, productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null, keywords: model.SearchProductName, pageIndex: command.Page - 1, pageSize: command.PageSize, showHidden: true ); gridModel.Data = products.Select(x => x.ToModel()); gridModel.Total = products.TotalCount; return Json(gridModel); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) return RedirectToAction("List"); if (ModelState.IsValid) { manufacturer = model.ToEntity(manufacturer); MediaHelper.UpdatePictureTransientStateFor(manufacturer, m => m.PictureId); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //update picture seo file name UpdatePictureSeoNames(manufacturer); //Stores _storeMappingService.SaveStoreMappings<Manufacturer>(manufacturer, model.SelectedStoreIds); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); NotifySuccess(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); return continueEditing ? RedirectToAction("Edit", manufacturer.Id) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); PrepareManufacturerModel(model, manufacturer, true); return View(model); }
protected void UpdateLocales(Manufacturer manufacturer, ManufacturerModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.Description, localized.Description, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); //search engine name var seName = manufacturer.ValidateSeName(localized.SeName, localized.Name, false); _urlRecordService.SaveSlug(manufacturer, seName, localized.LanguageId); } }
protected virtual void PrepareDiscountModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); if (!excludeProperties && manufacturer != null) model.SelectedDiscountIds = manufacturer.AppliedDiscounts.Select(d => d.Id).ToList(); foreach (var discount in _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true)) { model.AvailableDiscounts.Add(new SelectListItem { Text = discount.Name, Value = discount.Id.ToString(), Selected = model.SelectedDiscountIds.Contains(discount.Id) }); } }
protected virtual void PrepareAclModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); if (!excludeProperties && manufacturer != null) model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(manufacturer).ToList(); var allRoles = _customerService.GetAllCustomerRoles(true); foreach (var role in allRoles) { model.AvailableCustomerRoles.Add(new SelectListItem { Text = role.Name, Value = role.Id.ToString(), Selected = model.SelectedCustomerRoleIds.Contains(role.Id) }); } }
protected virtual async Task SaveManufacturerAclAsync(Manufacturer manufacturer, ManufacturerModel model) { manufacturer.SubjectToAcl = model.SelectedCustomerRoleIds.Any(); await _manufacturerService.UpdateManufacturerAsync(manufacturer); var existingAclRecords = await _aclService.GetAclRecordsAsync(manufacturer); var allCustomerRoles = await _customerService.GetAllCustomerRolesAsync(true); foreach (var customerRole in allCustomerRoles) { if (model.SelectedCustomerRoleIds.Contains(customerRole.Id)) { //new role if (existingAclRecords.Count(acl => acl.CustomerRoleId == customerRole.Id) == 0) { await _aclService.InsertAclRecordAsync(manufacturer, customerRole.Id); } } else { //remove role var aclRecordToDelete = existingAclRecords.FirstOrDefault(acl => acl.CustomerRoleId == customerRole.Id); if (aclRecordToDelete != null) { await _aclService.DeleteAclRecordAsync(aclRecordToDelete); } } } }