public ActionResult Create(ProductAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
                return AccessDeniedView();

            //decode description
            model.Description = HttpUtility.HtmlDecode(model.Description);
            foreach (var localized in model.Locales)
                localized.Description = HttpUtility.HtmlDecode(localized.Description);

            if (ModelState.IsValid)
            {
                var productAttribute = model.ToEntity();
                _productAttributeService.InsertProductAttribute(productAttribute);
                UpdateLocales(productAttribute, model);

                //activity log
                _customerActivityService.InsertActivity("AddNewProductAttribute", _localizationService.GetResource("ActivityLog.AddNewProductAttribute"), productAttribute.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.ProductAttributes.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = productAttribute.Id }) : RedirectToAction("List");
            }

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

            var model = new ProductAttributeModel();
            //locales
            AddLocales(_languageService, model.Locales);
            return View(model);
        }
Пример #3
0
 public bool ChangeImageStatue(long AttributeId, ProductAttributeModel status)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append("UPDATE Shop_Attributes ");
     builder.Append("SET UsageMode=@Status ");
     builder.Append("WHERE AttributeId=@AttributeId ");
     SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@AttributeId", SqlDbType.BigInt), new SqlParameter("@Status", SqlDbType.Int) };
     cmdParms[0].Value = AttributeId;
     cmdParms[1].Value = (int) status;
     return (DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms) > 0);
 }
        protected virtual void UpdateLocales(ProductAttribute productAttribute, ProductAttributeModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(productAttribute,
                                                               x => x.Name,
                                                               localized.Name,
                                                               localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(productAttribute,
                                                           x => x.Description,
                                                           localized.Description,
                                                           localized.LanguageId);
            }
        }
Пример #5
0
        public ActionResult Create(ProductAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var productAttribute = model.ToEntity();
                _productAttributeService.InsertProductAttribute(productAttribute);
                UpdateLocales(productAttribute, model);

                //activity log
                _customerActivityService.InsertActivity("AddNewProductAttribute", _localizationService.GetResource("ActivityLog.AddNewProductAttribute"), productAttribute.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.ProductAttributes.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = productAttribute.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Edit(ProductAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

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

            if (productAttribute == null)
            {
                //No product attribute found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                productAttribute         = model.ToEntity(productAttribute);
                productAttribute.Locales = UpdateLocales(productAttribute, model);
                _productAttributeService.UpdateProductAttribute(productAttribute);

                //activity log
                _customerActivityService.InsertActivity("EditProductAttribute", productAttribute.Id, _localizationService.GetResource("ActivityLog.EditProductAttribute"), productAttribute.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.ProductAttributes.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

                    return(RedirectToAction("Edit", new { id = productAttribute.Id }));
                }
                return(RedirectToAction("List"));
            }
            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #7
0
        public async Task <IResult> Insert(ProductAttributeViewModel productAttribute)
        {
            var result = new Result
            {
                Operation = Operation.Create,
                Status    = Status.Success
            };

            try
            {
                var attributeNameCheck = await _productAttributeRepository.CheckExistingAttribute(productAttribute.AttributeName);

                if (!attributeNameCheck)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "isPresent";
                    return(result);
                }
                productAttribute.CreatedDate = DateTime.Now;
                productAttribute.CreatedBy   = _specificClaim.GetSpecificClaim("Id");
                ProductAttributeModel attributeModel = new ProductAttributeModel();
                attributeModel.MapFromViewModel(productAttribute);

                var addAttr = await _productAttributeRepository.InsertAttribute(attributeModel);

                return(addAttr);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;

                return(result);
            }
        }
        public virtual IActionResult Create(ProductAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var productAttribute = model.ToEntity <ProductAttribute>();
                _productAttributeService.InsertProductAttribute(productAttribute);
                UpdateLocales(productAttribute, model);

                //activity log
                _customerActivityService.InsertActivity("AddNewProductAttribute",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewProductAttribute"), productAttribute.Name), productAttribute);

                _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.ProductAttributes.Added"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("Edit", new { id = productAttribute.Id }));
            }

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

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
        private void LoadProductAttributes(int Id)
        {
            DataTable productAttr = new ProductAttribute("[dbo].[LIST_ProductAttributes]").GetProductAttributes(Id);

            dgvProductAttributes.Rows.Clear();
            dgvProductAttributes.Refresh();
            productAttributes = new List <ProductAttributeModel>();
            foreach (DataRow pa in productAttr.Rows)
            {
                dgvProductAttributes.Rows.Add("Remove", pa["Id"], pa["ItemCode"], pa["Quantity"], pa["Category1"], pa["Category2"], pa["Category3"],
                                              pa["ItemDescription1"], pa["ItemDescription2"], pa["ItemSpecs1"], pa["ItemSpecs2"], pa["UOM"], pa["CostCode"]);

                var model = new ProductAttributeModel()
                {
                    Category1        = pa["Category1"].ToString(),
                    Category2        = pa["Category2"].ToString(),
                    Category3        = pa["Category3"].ToString(),
                    CategoryId1      = (int)pa["CategoryId1"],
                    CategoryId2      = (int)pa["CategoryId2"],
                    CategoryId3      = (int)pa["CategoryId3"],
                    CostCode         = pa["CostCode"].ToString(),
                    Id               = (int)pa["Id"],
                    ItemCode         = pa["ItemCode"].ToString(),
                    ItemDescription1 = pa["ItemDescription1"].ToString(),
                    ItemDescription2 = pa["ItemDescription2"].ToString(),
                    ItemMasterId     = (int)pa["ItemMasterId"],
                    ItemSpecs1       = pa["ItemSpecs1"].ToString(),
                    ItemSpecs2       = pa["ItemSpecs2"].ToString(),
                    ProductId        = int.Parse(txtProductCode.Text),
                    Quantity         = (decimal)pa["Quantity"],
                    UOM              = pa["UOM"].ToString()
                };

                productAttributes.Add(model);
            }
        }
        protected virtual List <LocalizedProperty> UpdateLocales(ProductAttribute productAttribute, ProductAttributeModel 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,
                    });
                }

                if (!(String.IsNullOrEmpty(local.Description)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "Description",
                        LocaleValue = local.Description,
                    });
                }
            }
            return(localized);
        }
Пример #11
0
        public IActionResult Create()
        {
            var model = new ProductAttributeModel();

            return(View(model));
        }
Пример #12
0
        public async Task <IHttpActionResult> Detail(int id)
        {
            var result  = new ApiResult <ProductDetailModel>();
            var product = await ProductService.GetAll()
                          .Where(x => x.Id == id)
                          .FirstOrDefaultAsync();

            if (product == null || product.Deleted)
            {
                return(NotFound());
            }

            var model = new ProductDetailModel
            {
                Id            = product.Id,
                OwnerId       = product.CreateUserId,
                Name          = product.Name,
                CategoryId    = product.CategoryId,
                Description   = product.Description,
                DetailUrl     = product.DetailUrl,
                ImageUrl      = product.ImageUrl,
                isAgreeActive = product.isAgreeActive,
                Price         = product.Price,
                SKU           = product.SKU,
                Status        = product.Status,
                VipPrice      = product.VipPrice,
                UrgencyPrice  = product.UrgencyPrice
            };

            #region attribute
            //performance optimization
            //We cache a value indicating whether a product has attributes
            IList <ProductAttributeMapping> productAttributeMapping = null;

            //no value in the cache yet
            //let's load attributes and cache the result (true/false)
            productAttributeMapping = ProductAttributeMappingService.GetProductAttributeMappingsByProductId(product.Id);

            if (productAttributeMapping == null)
            {
                productAttributeMapping = new List <ProductAttributeMapping>();
            }
            foreach (var attribute in productAttributeMapping)
            {
                var attributeModel = new ProductAttributeModel
                {
                    Id                 = attribute.Id,
                    ProductId          = product.Id,
                    ProductAttributeId = attribute.ProductAttributeId,
                    Name               = attribute.ProductAttribute.Name,
                    Description        = attribute.ProductAttribute.Description
                };

                //values
                var attributeValues = ProductAttributeValueService.GetAll().Where(x => x.ProductAttributeMappingId == attribute.Id && !x.Deleted);
                foreach (var attributeValue in attributeValues)
                {
                    var valueModel = new ProductAttributeValueModel
                    {
                        Id              = attributeValue.Id,
                        Name            = attributeValue.Name,
                        PriceAdjustment = attributeValue.PriceAdjustment,
                        ImageUrl        = attributeValue.ImageUrl
                    };
                    attributeModel.Values.Add(valueModel);
                }
                model.ProductAttributes.Add(attributeModel);
            }

            #endregion

            #region specification
            var specs = from psa in ProductSpecificationAttributeService.GetAll()
                        join sao in SpecificationAttributeOptionService.GetAll()
                        on psa.SpecificationAttributeOptionId equals sao.Id
                        join sa in SpecificationAttributeService.GetAll()
                        on sao.SpecificationAttributeId equals sa.Id
                        select new
            {
                sa,
                psa,
                sao
            };

            model.ProductSpecifications = specs.Where(x => x.psa.ProductId == id).ToList().Select(x => new ProductSpecificationModel()
            {
                SpecificationAttributeId   = x.sa.Id,
                SpecificationAttributeName = x.sa.Name,
                Value = x.sao.Name
            }).ToList();

            #endregion


            #region Storage Quatity

            var storageQuatities = from psq in ProductStorageQuantityService.GetAll()
                                   join ss in StorageService.GetAll()
                                   on psq.StorageId equals ss.Id
                                   select new
            {
                psq,
                ss,
            };

            model.ProductStorages = storageQuatities.Where(x => x.psq.ProductId == id).ToList().Select(x => new ProductStorageModel()
            {
                Name      = x.ss.Name,
                ProductId = x.psq.ProductId,
                StorageId = x.ss.Id,
                Quantity  = x.psq.Quantity,
                Id        = x.psq.Id
            }).ToList();

            #endregion
            result.Data = model;

            return(Ok(result));
        }
Пример #13
0
        protected virtual List <LocalizedProperty> UpdateLocales(ProductAttribute productAttribute, ProductAttributeModel 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,
                    });
                }

                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,
                    });
                }
            }
            return(localized);
        }
Пример #14
0
 public static ProductAttribute ToEntity(this ProductAttributeModel model)
 {
     return(Mapper.Map <ProductAttributeModel, ProductAttribute>(model));
 }
        public ActionResult Edit(ProductAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
                return AccessDeniedView();

            var productAttribute = _productAttributeService.GetProductAttributeById(model.Id);
            if (productAttribute == null)
                //No product attribute found with the specified id
                return RedirectToAction("List");

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

                UpdateLocales(productAttribute, model);

                //activity log
                _customerActivityService.InsertActivity("EditProductAttribute", _localizationService.GetResource("ActivityLog.EditProductAttribute"), productAttribute.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.ProductAttributes.Updated"));
                return continueEditing ? RedirectToAction("Edit", productAttribute.Id) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #16
0
 public static ProductAttribute ToEntity(this ProductAttributeModel model, ProductAttribute entity)
 {
     MapperFactory.Map(model, entity);
     return(entity);
 }
Пример #17
0
        /// <summary>
        /// Prepare product attribute model
        /// </summary>
        /// <param name="model">Product attribute model</param>
        /// <param name="productAttribute">Product attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Product attribute model</returns>
        public virtual async Task <ProductAttributeModel> PrepareProductAttributeModelAsync(ProductAttributeModel model,
                                                                                            ProductAttribute productAttribute, bool excludeProperties = false)
        {
            Action <ProductAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (productAttribute != null)
            {
                //fill in model values from the entity
                model ??= productAttribute.ToModel <ProductAttributeModel>();

                //prepare nested search models
                PreparePredefinedProductAttributeValueSearchModel(model.PredefinedProductAttributeValueSearchModel, productAttribute);
                PrepareProductAttributeProductSearchModel(model.ProductAttributeProductSearchModel, productAttribute);

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

                    locale.Description = await _localizationService.GetLocalizedAsync(productAttribute, entity => entity.Description, languageId, false, false);
                };
            }

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

            return(model);
        }
 public async Task CreateNewProductAttribute(Guid productId, ProductAttributeModel model) => await Commands.AddAttributeToProduct(productId, model.Attribute.Id, model.Value);
Пример #19
0
 public static ProductAttribute ToEntity(this ProductAttributeModel model)
 {
     return(model.MapTo <ProductAttributeModel, ProductAttribute>());
 }
Пример #20
0
        public ActionResult Create(ProductAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                var productAttribute = model.ToEntity();
                _productAttributeService.InsertProductAttribute(productAttribute);
                UpdateLocales(productAttribute, model);

                //activity log
                _customerActivityService.InsertActivity("AddNewProductAttribute", _localizationService.GetResource("ActivityLog.AddNewProductAttribute"), productAttribute.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.ProductAttributes.Added"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return RedirectToAction("Edit", new { id = productAttribute.Id });
                }
                return RedirectToAction("List");

            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
        protected virtual List<LocalizedProperty> UpdateLocales(ProductAttribute productAttribute, ProductAttributeModel 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,
                    });

                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,
                    });

            }
            return localized;
        }
Пример #22
0
 void Clear()
 {
     Model = new ProductAttributeModel();
     StateHasChanged();
 }
Пример #23
0
 public static ProductAttribute ToEntity(this ProductAttributeModel model, ProductAttribute destination)
 {
     return(model.MapTo(destination));
 }
Пример #24
0
        /// <returns>A task that represents the asynchronous operation</returns>
        protected virtual async Task UpdateLocalesAsync(ProductAttribute productAttribute, ProductAttributeModel model)
        {
            foreach (var localized in model.Locales)
            {
                await _localizedEntityService.SaveLocalizedValueAsync(productAttribute,
                                                                      x => x.Name,
                                                                      localized.Name,
                                                                      localized.LanguageId);

                await _localizedEntityService.SaveLocalizedValueAsync(productAttribute,
                                                                      x => x.Description,
                                                                      localized.Description,
                                                                      localized.LanguageId);
            }
        }