public async Task <IResult> UpdateProductAttributeValue(ProductAttributeValueViewModel productAttributeValue)
        {
            var result = new Result
            {
                Operation = Operation.Update,
                Status    = Status.Success
            };

            try
            {
                var pdtAttrValueModel = new ProductAttributeValues();
                pdtAttrValueModel.MapFromViewModel(productAttributeValue);
                var attributeValueCheck = _productRepository.CheckAttributeValue(pdtAttrValueModel);
                if (!attributeValueCheck)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "Product value exists already.";
                    return(result);
                }
                var updateAttrValue = await _productRepository.UpdateProductAttributeValue(pdtAttrValueModel);

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

                return(result);
            }
        }
Example #2
0
 // ADD and UPDATE product attribute value.
 public void SaveProductAttributeValue(ProductAttributeValueViewModel vm)
 {
     if (vm.Id == 0)     // Add
     {
         var row = ctx.ProductAttributeValues.FirstOrDefault(x => x.ProductAttributeId.Equals(vm.ProductAttributeId) && x.ProductId.Equals(vm.ProductId));
         if (row == null)
         {
             var productAttributeValue = new ProductAttributeValue
             {
                 Value = vm.Value,
                 ProductAttributeId = vm.ProductAttributeId,
                 ProductId          = vm.ProductId
             };
             ctx.ProductAttributeValues.Add(productAttributeValue);
         }
         else
         {
             ctx.ProductAttributeValues.Remove(row);
             ctx.SaveChanges();
             var productAttributeValue = new ProductAttributeValue
             {
                 Value = vm.Value,
                 ProductAttributeId = vm.ProductAttributeId,
                 ProductId          = vm.ProductId
             };
             ctx.ProductAttributeValues.Add(productAttributeValue);
         }
     }
     ctx.SaveChanges();
 }
        public async Task <IResult> InsertProductAttributeValue(ProductAttributeValueViewModel productAttributeValue)
        {
            var result = new Result
            {
                Operation = Operation.Create,
                Status    = Status.Success
            };

            try
            {
                ProductAttributeValues attributeValue = new ProductAttributeValues();
                attributeValue.MapFromViewModel(productAttributeValue);
                var attributeValueCheck = _productRepository.CheckAttributeValue(attributeValue);
                if (!attributeValueCheck)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "isValue";
                    return(result);
                }
                var addAttrValue = await _productRepository.AddProductAttributeValue(attributeValue);

                return(addAttrValue);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;
                return(result);
            }
        }
 public void UpdateProductAttributeValue(ProductAttributeValueViewModel viewModel)
 {
     SqlDb_Ultis.ExeNonStored("Product_Attribute_ValueUpDate",
                              "@Id", viewModel.Id,
                              "@ProductId", viewModel.AttributeId,
                              "@AttributeId", viewModel.ProductId,
                              "@Value", viewModel.Value);
 }
        public async Task <IResult> ListProductAttributeValue(int id, DataHelperModel dataHelper)
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                var attributeValues = _productRepository.GetProductAttributeValuesList(id);
                if (attributeValues.Count() == 0)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "Attributes do not exist for the product.";
                    return(result);
                }
                var list = attributeValues;
                list = DataSortExtention.SortBy(list, dataHelper.SortColumn, dataHelper.SortOrder);
                var resultCount = list.Count();
                var pagedList   = DataCount.Page(list, dataHelper.PageNumber, dataHelper.PageSize);
                var resultList  = await pagedList.ToListAsync();

                var pdtAttrValue = new List <ProductAttributeValueViewModel>();
                pdtAttrValue = resultList.Select(p =>
                {
                    var pdtAttrValueView = new ProductAttributeValueViewModel();
                    pdtAttrValueView.MapFromModel(p);
                    return(pdtAttrValueView);
                }).ToList();
                ResultModel resultModel = new ResultModel();
                resultModel.ProductAttributeValueResult = pdtAttrValue;
                resultModel.TotalCount = resultCount;
                if (resultList.Count == 0)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "No records present.";
                    return(result);
                }

                result.Status     = Status.Success;
                result.StatusCode = HttpStatusCode.OK;
                result.Body       = resultModel;
                return(result);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;

                return(result);
            }
        }
Example #6
0
        public IViewComponentResult Invoke(int productId)
        {
            // To get the product (from the product id the card passed in).
            var theProduct = _productRepo.Products.FirstOrDefault(p => p.Id.Equals(productId));
            // To get the products subcategory.
            var productsSubcategoryId = theProduct.Subcategory.Id;
            // To have all info from the ProductAttributeValue DB.
            var productAttributeValues = _productAttrValRepo.ProductAttributeValues;
            // List to store the specific cards product attribute value data.
            var theCardsProductAttributeValues = new List <ProductAttributeValue>();

            foreach (var productAttrValueRow in productAttributeValues)
            {
                if (productId == productAttrValueRow.ProductId)
                {
                    theCardsProductAttributeValues.Add(productAttrValueRow);
                }
            }
            // To have all info from the SubcategoryAttributeGroup DB.
            var subcategoryAttributeGroups         = _subcategoryAttributeGroupRepo.SubcategoryAttributeGroups;
            var theCardsSubcategoryAttributeGroups = new List <SubcategoryAttributeGroup>();

            // To get each subcatId so can get the subcategories different AttrGroups it has.
            foreach (var subcatAttrGroup in subcategoryAttributeGroups)
            {
                // if the subcatId matches the products subcategory id, push the subcategory attribute group row to the list...
                if (subcatAttrGroup.SubcategoryId == productsSubcategoryId)
                {
                    theCardsSubcategoryAttributeGroups.Add(subcatAttrGroup);
                }
            }
            // To send in filtered info for the specific product on the card.
            // If the product has information in the ProductAttributeValue DB table...
            if (theCardsProductAttributeValues.Any())
            {
                var prodAttrValVM = new ProductAttributeValueViewModel
                {
                    ProductId = productId,
                    CardProductAttributeValues     = theCardsProductAttributeValues,
                    CardSubcategoryAttributeGroups = theCardsSubcategoryAttributeGroups
                };
                return(View(prodAttrValVM));
            }
            // If not just show all the product attributes connected to the products subcategory (the 'value' from the ProductAttributeValue DB table will be empty)..
            else
            {
                var prodAttrValVM = new ProductAttributeValueViewModel
                {
                    ProductId = productId,
                    CardSubcategoryAttributeGroups = theCardsSubcategoryAttributeGroups
                };
                return(View(prodAttrValVM));
            }
        }
        public ProductAttributeValueViewModel GetProductAttributeValueById(Guid Id)
        {
            DataTable dtb = SqlDb_Ultis.ExeStoredToDataTable("Product_Attribute_ValueSelectByID", "@Id", Id);
            ProductAttributeValueViewModel role = new ProductAttributeValueViewModel();

            foreach (DataRow item in dtb.Rows)
            {
                role = Ultis.GetItem <ProductAttributeValueViewModel>(item);
            }
            return(role);
        }
        public async Task <IResult> GetProductAttributeValuesForCustomer(int id)
        {
            var result = new Result()
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                if (id != 0)
                {
                    var attributeValues = _productRepository.GetProductAttributeValuesList(id);
                    if (attributeValues.Count() == 0)
                    {
                        result.Status     = Status.Fail;
                        result.StatusCode = HttpStatusCode.BadRequest;
                        result.Message    = "Attributes do not exist for the product.";
                        return(result);
                    }
                    var resultList = await attributeValues.ToListAsync();

                    var pdtAttrValue = new List <ProductAttributeValueViewModel>();
                    pdtAttrValue = resultList.Select(p =>
                    {
                        var pdtAttrValueView = new ProductAttributeValueViewModel();
                        pdtAttrValueView.MapFromModel(p);
                        return(pdtAttrValueView);
                    }).ToList();
                    ResultModel resultModel = new ResultModel();
                    resultModel.ProductAttributeValueResult = pdtAttrValue;
                    resultModel.TotalCount = resultList.Count;

                    result.Status     = Status.Success;
                    result.StatusCode = HttpStatusCode.OK;
                    result.Body       = resultModel;
                    return(result);
                }
                result.Message    = "Product ID is not valid.";
                result.Status     = Status.Fail;
                result.StatusCode = HttpStatusCode.BadRequest;
                return(result);
            }
            catch (Exception e)
            {
                result.Body       = e;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;
                result.Status     = Status.Error;
                return(result);
            }
        }
        public async Task <IResult> UpdateProductAttributeValue([FromBody] ProductAttributeValueViewModel attributeValue)
        {
            var result = new Result
            {
                Operation = Operation.Update,
                Status    = Status.Success
            };

            if (!ModelState.IsValid)
            {
                result.Status     = Status.Fail;
                result.StatusCode = HttpStatusCode.BadRequest;
                return(result);
            }
            var attrValue = await _productService.UpdateProductAttributeValue(attributeValue);

            return(attrValue);
        }
Example #10
0
        public string _ValueEditPopup(ProductAttributeValueViewModel model)
        {
            PredefinedProductAttributeValue _pro = new PredefinedProductAttributeValue();

            _pro.Id                 = model.Id;
            _pro.Cost               = model.Cost;
            _pro.Name               = model.Name;
            _pro.OrderNo            = model.OrderNo;
            _pro.ProductAttributeId = model.ProductAttributeId;

            if (_predefinedProductAttributeValueService.Update(_pro))
            {
                return("1");
            }
            else
            {
                return("-1");
            }
        }
Example #11
0
        public ActionResult GetValueByAttributeId(int Id)
        {
            if (Id == 0)
            {
                throw new ArgumentException("ValueByAttribute Id degeri >>" + Id);
            }
            var data = _predefinedProductAttributeValueService.GetById(Id);

            if (data == null)
            {
                throw new ArgumentException("ValueByAttribute degeri Null");
            }
            ProductAttributeValueViewModel model = new ProductAttributeValueViewModel();

            model.Cost               = data.Cost;
            model.Name               = data.Name;
            model.OrderNo            = data.OrderNo;
            model.ProductAttributeId = data.ProductAttributeId;
            model.Id = data.Id;
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Example #12
0
        public IResult GetProductAttributeValue(int id)
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                if (id != 0)
                {
                    var attributeValue = _productRepository.GetProductAttributeValue(id);
                    if (attributeValue == null)
                    {
                        result.Status     = Status.Fail;
                        result.StatusCode = HttpStatusCode.BadRequest;
                        result.Message    = "This attribute for product does not exist.";
                        return(result);
                    }
                    ProductAttributeValueViewModel valueViewModel = new ProductAttributeValueViewModel();
                    valueViewModel.MapFromModel(attributeValue);

                    result.Status     = Status.Success;
                    result.Body       = valueViewModel;
                    result.StatusCode = HttpStatusCode.OK;
                    return(result);
                }
                result.Status     = Status.Fail;
                result.StatusCode = HttpStatusCode.BadRequest;
                return(result);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;
                return(result);
            }
        }
 public IActionResult SaveProductAttributeValue(ProductAttributeValueViewModel vm)
 {
     _productRepo.SaveProductAttributeValue(vm);
     return(RedirectToAction(nameof(Index)));
 }
Example #14
0
 public ActionResult SaveAttr(ProductAttributeValueViewModel viewModel)
 {
     _iProductAttributeValueService.InsertProductAttributeValue(viewModel);
     return(Json(new { success = 1, msg = "OK" }));
 }