Ejemplo n.º 1
0
        public virtual IActionResult PredefinedProductAttributeValueEditPopup(PredefinedProductAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            var ppav = _productAttributeService.GetPredefinedProductAttributeValueById(model.Id);

            if (ppav == null)
            {
                throw new ArgumentException("No product attribute value found with the specified id");
            }

            if (ModelState.IsValid)
            {
                ppav.Name             = model.Name;
                ppav.PriceAdjustment  = model.PriceAdjustment;
                ppav.WeightAdjustment = model.WeightAdjustment;
                ppav.Cost             = model.Cost;
                ppav.IsPreSelected    = model.IsPreSelected;
                ppav.DisplayOrder     = model.DisplayOrder;
                _productAttributeService.UpdatePredefinedProductAttributeValue(ppav);

                UpdateLocales(ppav, model);

                ViewBag.RefreshPage = true;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public virtual IActionResult PredefinedProductAttributeValueEditPopup(PredefinedProductAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            //try to get a predefined product attribute value with the specified id
            var productAttributeValue = _productAttributeService.GetPredefinedProductAttributeValueById(model.Id)
                                        ?? throw new ArgumentException("No predefined product attribute value found with the specified id");

            //try to get a product attribute with the specified id
            var productAttribute = _productAttributeService.GetProductAttributeById(productAttributeValue.ProductAttributeId)
                                   ?? throw new ArgumentException("No product attribute found with the specified id");

            if (ModelState.IsValid)
            {
                productAttributeValue = model.ToEntity(productAttributeValue);
                _productAttributeService.UpdatePredefinedProductAttributeValue(productAttributeValue);

                UpdateLocales(productAttributeValue, model);

                ViewBag.RefreshPage = true;

                return(View(model));
            }

            //prepare model
            model = _productAttributeModelFactory.PreparePredefinedProductAttributeValueModel(model, productAttribute, productAttributeValue, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
0
        //edit
        public ActionResult PredefinedProductAttributeValueEditPopup(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            var ppav = _productAttributeService.GetPredefinedProductAttributeValueById(id);

            if (ppav == null)
            {
                throw new ArgumentException("No product attribute value found with the specified id");
            }

            var model = new PredefinedProductAttributeValueModel
            {
                ProductAttributeId = ppav.ProductAttributeId,
                Name             = ppav.Name,
                PriceAdjustment  = ppav.PriceAdjustment,
                WeightAdjustment = ppav.WeightAdjustment,
                Cost             = ppav.Cost,
                IsPreSelected    = ppav.IsPreSelected,
                DisplayOrder     = ppav.DisplayOrder
            };

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name = ppav.GetLocalized(x => x.Name, languageId, false, false);
            });
            return(View(model));
        }
 protected virtual void UpdateLocales(PredefinedProductAttributeValue ppav, PredefinedProductAttributeValueModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(ppav,
                                                        x => x.Name,
                                                        localized.Name,
                                                        localized.LanguageId);
     }
 }
Ejemplo n.º 5
0
 protected virtual void UpdateLocales(PredefinedProductAttributeValue ppav, PredefinedProductAttributeValueModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(ppav,
                                                    x => x.Name,
                                                    localized.Name,
                                                    localized.LanguageId);
     }
 }
Ejemplo n.º 6
0
        //create
        public IActionResult PredefinedProductAttributeValueCreatePopup(string productAttributeId)
        {
            var productAttribute = _productAttributeService.GetProductAttributeById(productAttributeId);

            if (productAttribute == null)
            {
                throw new ArgumentException("No product attribute found with the specified id");
            }

            var model = new PredefinedProductAttributeValueModel();

            model.ProductAttributeId = productAttributeId;

            //locales
            AddLocales(_languageService, model.Locales);

            return(View(model));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Prepare paged predefined product attribute value list model
        /// </summary>
        /// <param name="searchModel">Predefined product attribute value search model</param>
        /// <param name="productAttribute">Product attribute</param>
        /// <returns>Predefined product attribute value list model</returns>
        public virtual PredefinedProductAttributeValueListModel PreparePredefinedProductAttributeValueListModel(
            PredefinedProductAttributeValueSearchModel searchModel, ProductAttribute productAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (productAttribute == null)
            {
                throw new ArgumentNullException(nameof(productAttribute));
            }

            //get predefined product attribute values
            var values = _productAttributeService.GetPredefinedProductAttributeValues(productAttribute.Id);

            //prepare list model
            var model = new PredefinedProductAttributeValueListModel
            {
                Data = values.PaginationByRequestModel(searchModel).Select(value =>
                {
                    //fill in model values from the entity
                    var predefinedProductAttributeValueModel = new PredefinedProductAttributeValueModel
                    {
                        Id = value.Id,
                        ProductAttributeId = value.ProductAttributeId,
                        Name          = value.Name,
                        IsPreSelected = value.IsPreSelected,
                        DisplayOrder  = value.DisplayOrder
                    };

                    //fill in additional values (not existing in the entity)
                    predefinedProductAttributeValueModel.WeightAdjustmentStr = value.WeightAdjustment.ToString("G29");
                    predefinedProductAttributeValueModel.PriceAdjustmentStr  = value.PriceAdjustment
                                                                               .ToString("G29") + (value.PriceAdjustmentUsePercentage ? " %" : string.Empty);

                    return(predefinedProductAttributeValueModel);
                }),
                Total = values.Count
            };

            return(model);
        }
Ejemplo n.º 8
0
        public IActionResult PredefinedProductAttributeValueEditPopup(PredefinedProductAttributeValueModel model)
        {
            var productAttribute = _productAttributeService.GetProductAttributeById(model.ProductAttributeId);
            var ppav             = productAttribute.PredefinedProductAttributeValues.Where(x => x.Id == model.Id).FirstOrDefault();

            if (ppav == null)
            {
                throw new ArgumentException("No product attribute value found with the specified id");
            }

            if (ModelState.IsValid)
            {
                ppav = model.ToEntity(ppav);
                _productAttributeService.UpdateProductAttribute(productAttribute);

                ViewBag.RefreshPage = true;
                return(View(model));
            }
            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <IActionResult> PredefinedProductAttributeValueCreatePopup(PredefinedProductAttributeValueModel model)
        {
            var productAttribute = await _productAttributeService.GetProductAttributeById(model.ProductAttributeId);

            if (productAttribute == null)
            {
                throw new ArgumentException("No product attribute found with the specified id");
            }

            if (ModelState.IsValid)
            {
                var ppav = model.ToEntity();
                productAttribute.PredefinedProductAttributeValues.Add(ppav);
                await _productAttributeService.UpdateProductAttribute(productAttribute);

                ViewBag.RefreshPage = true;
                return(View(model));
            }
            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 10
0
        public virtual IActionResult PredefinedProductAttributeValueCreatePopup(PredefinedProductAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            //try to get a product attribute with the specified id
            var productAttribute = _productAttributeService.GetProductAttributeById(model.ProductAttributeId)
                                   ?? throw new ArgumentException("No product attribute found with the specified id");

            if (ModelState.IsValid)
            {
                var ppav = new PredefinedProductAttributeValue
                {
                    ProductAttributeId = model.ProductAttributeId,
                    Name            = model.Name,
                    PriceAdjustment = model.PriceAdjustment,
                    PriceAdjustmentUsePercentage = model.PriceAdjustmentUsePercentage,
                    WeightAdjustment             = model.WeightAdjustment,
                    Cost          = model.Cost,
                    IsPreSelected = model.IsPreSelected,
                    DisplayOrder  = model.DisplayOrder
                };

                _productAttributeService.InsertPredefinedProductAttributeValue(ppav);
                UpdateLocales(ppav, model);

                ViewBag.RefreshPage = true;

                return(View(model));
            }

            //prepare model
            model = _productAttributeModelFactory.PreparePredefinedProductAttributeValueModel(model, productAttribute, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 11
0
        //create
        public ActionResult PredefinedProductAttributeValueCreatePopup(int productAttributeId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            var productAttribute = _productAttributeService.GetProductAttributeById(productAttributeId);

            if (productAttribute == null)
            {
                throw new ArgumentException("No product attribute found with the specified id");
            }

            var model = new PredefinedProductAttributeValueModel();

            model.ProductAttributeId = productAttributeId;

            //locales
            AddLocales(_languageService, model.Locales);

            return(View(model));
        }
        public IActionResult PredefinedProductAttributeValueCreatePopup(PredefinedProductAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            var productAttribute = _productAttributeService.GetProductAttributeById(model.ProductAttributeId);

            if (productAttribute == null)
            {
                throw new ArgumentException("No product attribute found with the specified id");
            }

            if (ModelState.IsValid)
            {
                var ppav = new PredefinedProductAttributeValue
                {
                    ProductAttributeId = model.ProductAttributeId,
                    Name             = model.Name,
                    PriceAdjustment  = model.PriceAdjustment,
                    WeightAdjustment = model.WeightAdjustment,
                    Cost             = model.Cost,
                    IsPreSelected    = model.IsPreSelected,
                    DisplayOrder     = model.DisplayOrder,
                };
                ppav.Locales = UpdateLocales(ppav, model);
                productAttribute.PredefinedProductAttributeValues.Add(ppav);
                _productAttributeService.UpdateProductAttribute(productAttribute);

                ViewBag.RefreshPage = true;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        //edit
        public ActionResult PredefinedProductAttributeValueEditPopup(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
                return AccessDeniedView();

            var ppav = _productAttributeService.GetPredefinedProductAttributeValueById(id);
            if (ppav == null)
                throw new ArgumentException("No product attribute value found with the specified id");

            var model = new PredefinedProductAttributeValueModel
            {
                ProductAttributeId = ppav.ProductAttributeId,
                Name = ppav.Name,
                PriceAdjustment = ppav.PriceAdjustment,
                WeightAdjustment = ppav.WeightAdjustment,
                Cost = ppav.Cost,
                IsPreSelected = ppav.IsPreSelected,
                DisplayOrder = ppav.DisplayOrder
            };
            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name = ppav.GetLocalized(x => x.Name, languageId, false, false);
            });
            return View(model);
        }
        public ActionResult PredefinedProductAttributeValueCreatePopup(string btnId, string formId, PredefinedProductAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
                return AccessDeniedView();

            var productAttribute = _productAttributeService.GetProductAttributeById(model.ProductAttributeId);
            if (productAttribute == null)
                throw new ArgumentException("No product attribute found with the specified id");

            if (ModelState.IsValid)
            {
                var ppav = new PredefinedProductAttributeValue
                {
                    ProductAttributeId = model.ProductAttributeId,
                    Name = model.Name,
                    PriceAdjustment = model.PriceAdjustment,
                    WeightAdjustment = model.WeightAdjustment,
                    Cost = model.Cost,
                    IsPreSelected = model.IsPreSelected,
                    DisplayOrder = model.DisplayOrder,
                    _id = ObjectId.GenerateNewId().ToString(),
                    Id = productAttribute.PredefinedProductAttributeValues.Count > 0 ? productAttribute.PredefinedProductAttributeValues.Max(x=>x.Id)+1:1,
                };
                ppav.Locales = UpdateLocales(ppav, model);
                productAttribute.PredefinedProductAttributeValues.Add(ppav);
                _productAttributeService.UpdateProductAttribute(productAttribute);

                ViewBag.RefreshPage = true;
                ViewBag.btnId = btnId;
                ViewBag.formId = formId;
                return View(model);
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
        protected virtual List<LocalizedProperty> UpdateLocales(PredefinedProductAttributeValue ppav, PredefinedProductAttributeValueModel model)
        {
            List<LocalizedProperty> localized = new List<LocalizedProperty>();
            foreach (var local in model.Locales)
            {

                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,
                    });
            }
            return localized;
        }
 //value
 public static PredefinedProductAttributeValue ToEntity(this PredefinedProductAttributeValueModel model)
 {
     return(model.MapTo <PredefinedProductAttributeValueModel, PredefinedProductAttributeValue>());
 }
 public static PredefinedProductAttributeValue ToEntity(this PredefinedProductAttributeValueModel model, PredefinedProductAttributeValue destination)
 {
     return(model.MapTo(destination));
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Prepare predefined product attribute value model
        /// </summary>
        /// <param name="model">Predefined product attribute value model</param>
        /// <param name="productAttribute">Product attribute</param>
        /// <param name="productAttributeValue">Predefined product attribute value</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Predefined product attribute value model</returns>
        public virtual PredefinedProductAttributeValueModel PreparePredefinedProductAttributeValueModel(PredefinedProductAttributeValueModel model,
                                                                                                        ProductAttribute productAttribute, PredefinedProductAttributeValue productAttributeValue, bool excludeProperties = false)
        {
            if (productAttribute == null)
            {
                throw new ArgumentNullException(nameof(productAttribute));
            }

            Action <PredefinedProductAttributeValueLocalizedModel, int> localizedModelConfiguration = null;

            if (productAttributeValue != null)
            {
                //fill in model values from the entity
                model = model ?? new PredefinedProductAttributeValueModel
                {
                    ProductAttributeId = productAttributeValue.ProductAttributeId,
                    Name            = productAttributeValue.Name,
                    PriceAdjustment = productAttributeValue.PriceAdjustment,
                    PriceAdjustmentUsePercentage = productAttributeValue.PriceAdjustmentUsePercentage,
                    WeightAdjustment             = productAttributeValue.WeightAdjustment,
                    Cost          = productAttributeValue.Cost,
                    IsPreSelected = productAttributeValue.IsPreSelected,
                    DisplayOrder  = productAttributeValue.DisplayOrder
                };

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = productAttributeValue.GetLocalized(entity => entity.Name, languageId, false, false);
                };
            }

            model.ProductAttributeId = productAttribute.Id;

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
Ejemplo n.º 19
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> PredefinedProductAttributeValueCreatePopup(PredefinedProductAttributeValueModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            //try to get a product attribute with the specified id
            var productAttribute = await _productAttributeService.GetProductAttributeByIdAsync(model.ProductAttributeId)
                                   ?? throw new ArgumentException("No product attribute found with the specified id");

            if (ModelState.IsValid)
            {
                //fill entity from model
                var ppav = model.ToEntity <PredefinedProductAttributeValue>();

                await _productAttributeService.InsertPredefinedProductAttributeValueAsync(ppav);
                await UpdateLocalesAsync(ppav, model);

                ViewBag.RefreshPage = true;

                return(View(model));
            }

            //prepare model
            model = await _productAttributeModelFactory.PreparePredefinedProductAttributeValueModelAsync(model, productAttribute, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
        protected virtual List <LocalizedProperty> UpdateLocales(PredefinedProductAttributeValue ppav, PredefinedProductAttributeValueModel model)
        {
            List <LocalizedProperty> localized = new List <LocalizedProperty>();

            foreach (var local in model.Locales)
            {
                if (!(String.IsNullOrEmpty(local.Name)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "Name",
                        LocaleValue = local.Name,
                    });
                }
            }
            return(localized);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Prepare predefined product attribute value model
        /// </summary>
        /// <param name="model">Predefined product attribute value model</param>
        /// <param name="productAttribute">Product attribute</param>
        /// <param name="productAttributeValue">Predefined product attribute value</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Predefined product attribute value model</returns>
        public virtual async Task <PredefinedProductAttributeValueModel> PreparePredefinedProductAttributeValueModelAsync(PredefinedProductAttributeValueModel model,
                                                                                                                          ProductAttribute productAttribute, PredefinedProductAttributeValue productAttributeValue, bool excludeProperties = false)
        {
            if (productAttribute == null)
            {
                throw new ArgumentNullException(nameof(productAttribute));
            }

            Action <PredefinedProductAttributeValueLocalizedModel, int> localizedModelConfiguration = null;

            if (productAttributeValue != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model = productAttributeValue.ToModel <PredefinedProductAttributeValueModel>();
                }

                //define localized model configuration action
                localizedModelConfiguration = async(locale, languageId) =>
                {
                    locale.Name = await _localizationService.GetLocalizedAsync(productAttributeValue, entity => entity.Name, languageId, false, false);
                };
            }

            model.ProductAttributeId = productAttribute.Id;

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration);
            }

            return(model);
        }
Ejemplo n.º 22
0
 /// <returns>A task that represents the asynchronous operation</returns>
 protected virtual async Task UpdateLocalesAsync(PredefinedProductAttributeValue ppav, PredefinedProductAttributeValueModel model)
 {
     foreach (var localized in model.Locales)
     {
         await _localizedEntityService.SaveLocalizedValueAsync(ppav,
                                                               x => x.Name,
                                                               localized.Name,
                                                               localized.LanguageId);
     }
 }
        //create
        public ActionResult PredefinedProductAttributeValueCreatePopup(int productAttributeId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
                return AccessDeniedView();

            var productAttribute = _productAttributeService.GetProductAttributeById(productAttributeId);
            if (productAttribute == null)
                throw new ArgumentException("No product attribute found with the specified id");

            var model = new PredefinedProductAttributeValueModel();
            model.ProductAttributeId = productAttributeId;

            //locales
            AddLocales(_languageService, model.Locales);

            return View(model);
        }
        public ActionResult PredefinedProductAttributeValueEditPopup(string btnId, string formId, PredefinedProductAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
                return AccessDeniedView();

            var ppav = _productAttributeService.GetPredefinedProductAttributeValueById(model.Id);
            if (ppav == null)
                throw new ArgumentException("No product attribute value found with the specified id");

            if (ModelState.IsValid)
            {
                ppav.Name = model.Name;
                ppav.PriceAdjustment = model.PriceAdjustment;
                ppav.WeightAdjustment = model.WeightAdjustment;
                ppav.Cost = model.Cost;
                ppav.IsPreSelected = model.IsPreSelected;
                ppav.DisplayOrder = model.DisplayOrder;
                _productAttributeService.UpdatePredefinedProductAttributeValue(ppav);

                UpdateLocales(ppav, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId = btnId;
                ViewBag.formId = formId;
                return View(model);
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
Ejemplo n.º 25
0
        protected virtual List <LocalizedProperty> UpdateLocales(PredefinedProductAttributeValue ppav, PredefinedProductAttributeValueModel model)
        {
            List <LocalizedProperty> localized = new List <LocalizedProperty>();

            foreach (var local in model.Locales)
            {
                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,
                    });
                }
            }
            return(localized);
        }