Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam working on nopcommerce2.8 version. I have a problem with telerik plugin implementation to create new grid.
Iam implementing a concept where for a product i want to give different price for different customer. So to assign new price for different customers, in admin panel i am creating a grid in edit productvariant page using telerik. I have created a new tab to display these details. Iam able to display customer name and price in grid, but i am not able to call update function, when i click on update button after editing a row. I have created new model to save the customer and price details. Please help me to solve this update problem.

The model, view and controller of my nopcommerce in given below.

Thanks.


Objective-C
//Model
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using FluentValidation.Attributes;
using Nop.Admin.Models.Customers;
using Nop.Admin.Validators.Catalog;
using Nop.Web.Framework;
using Nop.Web.Framework.Localization;
using Nop.Web.Framework.Mvc;
using Telerik.Web.Mvc;

namespace Nop.Admin.Models.Catalog
{
    public partial class CustomerProductPriceModel : BaseNopModel
    {
        public int Customer_Id { get; set; }
        [NopResourceDisplayName("Customer Name")]
        public string Customer_name { get; set; }

        [NopResourceDisplayName("Price")]
        public decimal Price { get; set; }

        [NopResourceDisplayName("Unit")]
        public string Units { get; set; }

    }
}

// view

  @(Html.Telerik().Grid<customerproductpricemodel>()
        .Name("Grid")
        .DataKeys(x =>
                    {
                        x.Add(y => y.Customer_Id);
                    })
                     .DataBinding(dataBinding =>
                    {
                            dataBinding.Ajax()
                            .Select("CustomerProductPriceList", "ProductVariant", new { productVariantId = Model.Id })
                            .Update("CustomerPriceUpdate", "ProductVariant", new { productVariantId = Model.Id });
                    })
        .Columns(columns =>
        {
            columns.Bound(y => y.Customer_name).Width(200).ReadOnly();
            columns.Bound(y => y.Price).Width(100);

            columns.Command(commands =>
            {
                commands.Edit().Text(T("Admin.Common.Edit").Text);
            }).Width(180);

        })
        .Editable(x =>
                {
                    x.Mode(GridEditMode.InLine);
                })
        .EnableCustomBinding(true)

      )


    // controller

    [GridAction(EnableCustomBinding = true)]
        public ActionResult CustomerPriceUpdate(GridCommand command, CustomerProductPriceModel model, int productVariantId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
                return AccessDeniedView();


             return CustomerProductPriceList(command, productVariantId);
        }


       [HttpPost, GridAction(EnableCustomBinding = true)]
        public ActionResult CustomerProductPriceList(GridCommand command, int productVariantId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
                return AccessDeniedView();

            var productVariant = _productService.GetProductVariantById(productVariantId);
            if (productVariant == null)
                throw new ArgumentException("No product variant found with the specified id");

            var CustomerPrices = PrepareCustomerProductPriceModel(productVariant.Product.Id);
            var CustomerPricesa = CustomerPrices
               .Select(x =>
               {
                   return new CustomerProductPriceModel()
                   {
                       Customer_Id = x.Customer_Id,
                       Price = x.Price,
                       Units = x.Units,
                       Customer_name = x.Customer_name
                   };
               })
               .ToList();
            var model = new GridModel<customerproductpricemodel>
            {
                Data = CustomerPricesa,
                Total = CustomerPrices.Count
            };
            return new JsonResult
            {
                Data = model
            };
        }</customerproductpricemodel></customerproductpricemodel>
Posted
Updated 4-Apr-13 2:22am
v2
Comments
Sandeep Mewara 4-Apr-13 12:44pm    
Looked at telerik forum?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900