Monday 26 December 2016

Custom directives in angular JS



<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/angular.js"></script>
</head>
<body ng-app="app" ng-controller="ctrl">
    <div class="my-directive"></div>
 
</body>
</html>
<script type="text/javascript">

    angular.module("app", [])
    .controller("ctrl", function () { })
    .directive("myDirective", function () {
        var Directive = {};
        Directive.restrict = "C";
        Directive.template = "<P style='color:white'>Jay Jagannath...</P>";
        Directive.link = function ($scope, element, attr)
        {
            element.append("<input type='button' value='Press Me'   /><Br>");
            element.bind('mouseenter', function () {
                element.css('background-color', 'red');
            });
            element.on('mouseleave', function () {
                element.css('background-color', 'Black');
            });
            element.on('click', function () {
                element.append("<input type='text' /><Br>");
            });
         
        };
        return Directive;
    });
</script>

-----------------------------------------------------
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/angular.js"></script>
</head>
<body ng-app="myApp">
   
    <div ng-controller="MyController as vm">
        <my-select callback="vm.setValue($value)"></my-select>
        <p>Selected Value: {{vm.value}}</p>
    </div>
</body>
</html>
<script type="text/javascript">
 
    angular.module('myApp', [])
   .controller('MyController', MyController)
   .controller('MySelectController', MySelectController)
   .directive('mySelect', mySelectDirective);

    function MyController() {
        var vm = this;
        vm.setValue = function (value) {
            vm.value = value;
        };
    }

    function MySelectController() {
        var vm = this;
        vm.items = [
          { label: 'One', value: 1 },
          { label: 'Two', value: 2 },
          { label: 'Three', value: 3 }
        ];
    }

    function mySelectDirective() {
        return {
            bindToController: {
                callback: '&'
            },
            controller: 'MySelectController',
            controllerAs: 'vm',
            link: postLink,
            scope: true,
            template: '<select ng-model="vm.selected" ng-change="fillddl()"  ng-options="item.value as item.label for item in vm.items"></select>'
        };

        function postLink(scope, iElement, iAttrs, vm) {
         
            scope.$watch(function () {
                return vm.selected;
            }, function (newValue) {
                if (angular.isDefined(newValue) && typeof vm.callback === 'function') {
                    vm.callback({ $value: newValue });
                }
            });
            scope.fillddl = function () {
                alert(vm.selected);
            };
        }
    }
</script>

Wednesday 21 December 2016

example of list box and nested gride in angularjs


MVC Code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication19.Models;

namespace WebApplication19.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }
        [AcceptVerbs(HttpVerbs.Get)]
        [OutputCache(Duration = 0)]
        public JsonResult Gets()
        {
            using (Database1Entities obj = new Database1Entities())
            {
                List<EMP2> lst = (from x in obj.EMPs
                                 select new EMP2() {
                                  EID=x.EID,
                                  NAME=x.NAME,
                                  LDEPT = obj.DEPTs.Where(n => obj.EMPMAPPINGs.Where(p => p.EID == x.EID).Select(t=>t.DID).Contains(n.DID)).ToList()
                                 }).ToList();
                return Json(lst, JsonRequestBehavior.AllowGet);
            }
        }
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult Get(int EID)
        {
            using (Database1Entities obj = new Database1Entities())
            {
                EMP1 emp = (from x in obj.EMPs
                           where x.EID==EID
                            select new EMP1
                            {
                                EID = x.EID,
                                NAME = x.NAME,
                                MAP = obj.EMPMAPPINGs.Where(m => m.EID == x.EID).Select(p => p.DID.Value).ToList()
                            }).SingleOrDefault(m => m.EID == EID);
                return Json(emp, JsonRequestBehavior.AllowGet);
            }
        }
        public string Save(EMP1 emp)
        {
            using (Database1Entities obj = new Database1Entities())
            {
                EMP emp1 = new EMP();
                emp1.EID = emp.EID;
                emp1.NAME = emp.NAME;
                obj.Entry(emp1).State=System.Data.Entity.EntityState.Added;
                obj.SaveChanges();
                List<EMPMAPPING> lst = new List<EMPMAPPING>();
                foreach(int did in emp.MAP)
                {
                    EMPMAPPING eMPMAPPING = new EMPMAPPING();
                    eMPMAPPING.DID = did;
                    eMPMAPPING.EID = emp.EID;
                    lst.Add(eMPMAPPING);
                }
                obj.EMPMAPPINGs.AddRange(lst);
                obj.SaveChanges();
                return "Data Saved.";

            }
        }
        public string Update(EMP1 emp)
        {
            using (Database1Entities obj = new Database1Entities())
            {
                EMP emp1 = obj.EMPs.SingleOrDefault(m => m.EID == emp.EID);
                emp1.NAME = emp.NAME;
                obj.Entry(emp1).State = System.Data.Entity.EntityState.Modified;
                obj.SaveChanges();
                obj.EMPMAPPINGs.RemoveRange(obj.EMPMAPPINGs.Where(m => m.EID == emp.EID));
                obj.SaveChanges();
                List<EMPMAPPING> lst = new List<EMPMAPPING>();
                foreach (int did in emp.MAP)
                {
                    EMPMAPPING eMPMAPPING = new EMPMAPPING();
                    eMPMAPPING.DID = did;
                    eMPMAPPING.EID = emp.EID;
                    lst.Add(eMPMAPPING);
                }
                obj.EMPMAPPINGs.AddRange(lst);
                obj.SaveChanges();
                return "Data Updated.";

            }
        }
        public string Delete(int EID)
        {
            using (Database1Entities obj = new Database1Entities())
            {
                EMP emp1 = obj.EMPs.SingleOrDefault(m => m.EID == EID);
                obj.Entry(emp1).State = System.Data.Entity.EntityState.Deleted;
                obj.SaveChanges();
                obj.EMPMAPPINGs.RemoveRange(obj.EMPMAPPINGs.Where(m => m.EID == EID));
                obj.SaveChanges();
                return "Data Deleted.";

            }
        }
        public JsonResult Getd()
        {
            using (Database1Entities obj = new Database1Entities())
            {
               return Json( obj.DEPTs.ToList(),JsonRequestBehavior.AllowGet);
            }
        }
    }
    public class EMP1
    {
        public int EID{get;set;}
        public string NAME{get;set;}
        public List<int> MAP{get;set;}
    }
    public class EMP2
    {
        public int EID { get; set; }
        public string NAME { get; set; }
        public List<DEPT> LDEPT { get; set; }
    }
}

View  Code :


@{
    ViewBag.Title = "Index";
}
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap-theme.css" rel="stylesheet" />
<script src="~/Scripts/angular.js"></script>
<h2>Jay Jagannath...</h2>
<br /><br />
<div class="container" ng-app="app" ng-controller="ctrl">
    <form class="form-horizontal" name="frmEmp" novalidate>
        <div class="form-group" ng-class="{'has-error':frmEmp.txtEid.$invalid}">
            <label class="control-label col-lg-4">EID</label>
            <div class="col-lg-4">
                <input type="text" class="form-control" ng-model="EMP1.EID" name="txtEid" ng-required="frmEmp.txtEid.$invalid" />
            </div>
            <span class="help-block has-error" ng-show="frmEmp.txtEid.$invalid">
                EID should not be blank.
            </span>
        </div>
        <div class="form-group" ng-class="{'has-error':frmEmp.txtName.$invalid}">
            <label class="control-label col-lg-4">NAME</label>
            <div class="col-lg-4">
                <input type="text" class="form-control" ng-model="EMP1.NAME" name="txtName" ng-required="frmEmp.txtName.$invalid" />
            </div>
            <span class="help-block has-error" ng-show="frmEmp.txtName.$invalid">
                Name should not be blank.
            </span>
        </div>
        <div class="form-group" ng-class="{'has-error':frmEmp.txtMap.$invalid}">
            <label class="control-label col-lg-4">DEPARTMENT NAME</label>
            <div class="col-lg-4">
                <select multiple class="form-control" ng-options="c.DID as c.DNAME for c in list" ng-model="EMP1.MAP" name="txtMap" ng-required="frmEmp.txtMap.$invalid" ></select>
            </div>
            <span class="help-block has-error" ng-show="frmEmp.txtMap.$invalid">
                Department name should not be blank.
            </span>
        </div>
        <div class="form-group" ng-class="{'has-error':frmEmp.txtMap.$invalid}">
            <label class="control-label col-lg-4"></label>
            <div class="col-lg-4">
              <input type="button" value="Save" ng-click="save()" class="btn btn-primary" style="width:80px" />
                <input type="button" value="Update" ng-click="update()" class="btn btn-primary" style="width:80px" />
                <input type="button" value="Reset" ng-click="reset()" class="btn btn-primary" style="width:80px" />
            </div>
           
        </div>
        <div class="row">
            <table class="table table-bordered table-condensed table-hover table-responsive table-striped">
                <thead class="bg-primary">
                    <tr>
                        <th>EID</th>
                        <th>NAME</th>
                        <th>DEPARTMENT NAME</th>
                        <th>ACTION</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="c in liste">
                        <td>{{c.EID}}</td>
                        <td>{{c.NAME}}</td>
                        <td>
                            <table class="table table-bordered">
                                <thead class="bg-primary">
                                    <tr>
                                        <th>
                                            DID
                                        </th>
                                        <th>
                                            DNAME
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr ng-repeat="d in c.LDEPT">
                                        <td>{{d.DID}}</td>
                                        <td>{{d.DNAME}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                        <td>
                            <a ng-click="edit(c.EID)">Edit</a>|
                            <a ng-click="del(c.EID)">Delete</a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </form>
</div>
<script type="text/javascript">
    (function () {
        "use strict";
        angular.module("app", [])
        .controller("ctrl", function ($scope, empService) {
            function CLR()
            {
                $scope.EMP1 = new emp();
            } CLR();
            empService.Getd().then(function (response) {
                $scope.list = response.data;
            });
            $scope.save = function ()
            {
                empService.Save($scope.EMP1).then(function (response) {
                    alert(response.data);
                    CLR();
                    fill();
                });
            }
            $scope.update = function () {
                empService.Update($scope.EMP1).then(function (response) {
                    alert(response.data);
                    CLR();
                    fill();
                });
            }
            function fill()
            {
                empService.Gets().then(function (response) {
                    $scope.liste = response.data;
                });
            } fill();
            $scope.edit = function (s) {
                empService.Get(s).then(function (response) {
                    $scope.EMP1 = response.data;
                });

            }
            $scope.reset = function ()
            {
                CLR();
            }
            $scope.del = function (s)
            {
                if (confirm('Do you want to delete it ?'))
                {
                    empService.Delete(s).then(function (response) {
                        alert(response.data);
                        fill();
                    });
                }
            }
        })
        .service("empService", function ($http) {
            this.Getd = function ()
            {
                return $http.get("/Home/Getd");
            }
            this.Save = function (EMP)
            {
                return $http.post("/Home/Save", EMP);
            }
            this.Update = function (EMP) {
                return $http.post("/Home/Update", EMP);
            }
            this.Gets = function () {
                return $http.get("/Home/Gets");
            }
            this.Get = function (EID) {
                return $http.get("/Home/Get?EID="+EID);
            }
            this.Delete = function (EID) {
                return $http.get("/Home/Delete?EID=" + EID);
            }
        });
    }());
    function emp()
    {
        return {
            EID: null,
            NAME: null,
            MAP:[]
        }
    }
</script>

Thursday 15 December 2016

Example of listbox in angularjs


View Code :






<link href="~/Content/bootstrap.css" rel="stylesheet" />
<script src="~/Scripts/angular.js"></script>
<div class="container" ng-app="app" ng-controller="ctrl">
    <form class="form-horizontal"><br />
        <select ng-model="EMP.NAME" multiple class="form-control">
            <option value="1">A</option>
            <option value="2">B</option>
            <option value="3">C</option>
            <option value="4">D</option>
            <option value="5">E</option>
            <option value="6">F</option>
        </select><br /><br />
        <input type="button" value="Press Me" class="btn btn-primary"  ng-click="shwo()"/>
    </form>
</div>
<script type="text/javascript">
    angular.module("app", [])
    .controller("ctrl", function ($scope) {
        $scope.EMP = new emp();
        $scope.shwo = function ()
        {
         
            for (var i = 0; i < $scope.EMP.NAME.length; i++)
                alert($scope.EMP.NAME[i]);
        }
    });
    function emp()
    {
        return {
            NAME:[]
        }
    }
</script>

Tuesday 6 December 2016

CURD opration using Webapi,MVC & Angularjs

First create a class Library:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BO
{
    public class EMP
    {
        public int EID { get; set; }
        public string NAME { get; set; }
    }
}

Create a  web api :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using WebApplication13.Models;
using BO;

namespace WebApplication13.Controllers
{
    public class EmpserviceController : ApiController
    {
        [HttpGet]
        public List<BO.EMP> Gets()
        {
            using (Database1Entities obj = new Database1Entities())
            {
                return obj.EMPs.ToList().ConvertAll(m => new BO.EMP() { EID=m.EID,NAME=m.NAME });
            }
        }
        [HttpGet]
        public BO.EMP Gets(int EID)
        {
            using (Database1Entities obj = new Database1Entities())
            {
                return obj.EMPs.ToList().ConvertAll(m => new BO.EMP() { EID = m.EID, NAME = m.NAME }).FirstOrDefault(n => n.EID == EID);
            }
        }
        [HttpPost]
        public string Post(BO.EMP emp)
        {
            using (Database1Entities obj = new Database1Entities())
            {
                WebApplication13.Models.EMP emp1 = new Models.EMP();
                emp1.EID = emp.EID;
                emp1.NAME = emp.NAME;
                obj.EMPs.Add(emp1);
                obj.SaveChanges();
                return "Data Saved.";
            }
        }
        [HttpPut]
        public string Put(BO.EMP emp)
        {
            using (Database1Entities obj = new Database1Entities())
            {
               WebApplication13.Models.EMP emp1 = obj.EMPs.SingleOrDefault(m => m.EID == emp.EID);
               emp1.NAME = emp.NAME;
                obj.SaveChanges();
                return "Data Updated.";
            }
        }
        [HttpDelete]
        public string Delete(int EID)
        {
            using (Database1Entities obj = new Database1Entities())
            {
               WebApplication13.Models.EMP emp1 = obj.EMPs.SingleOrDefault(m => m.EID == EID);
                obj.EMPs.Remove(emp1);
                obj.SaveChanges();
                return "Data Deleted.";
            }
        }
    }
}

MVC controller :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net;
using Newtonsoft.Json;
using BO;
using System.Text;


namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
       
        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public JsonResult Gets()
        {
            using (WebClient wc = new WebClient())
            {
                string s = wc.DownloadString("http://localhost:63795/api/Empservice");
                List<EMP> lst = (List<EMP>)JsonConvert.DeserializeObject(s,typeof(List<EMP>));
                return Json(lst, JsonRequestBehavior.AllowGet);
            }
        }
        [HttpGet]
        public JsonResult Get(int EID)
        {
            using (WebClient wc = new WebClient())
            {
                string s = wc.DownloadString("http://localhost:63795/api/Empservice/Get?EID="+EID);
               EMP lst = (EMP)JsonConvert.DeserializeObject(s,typeof(EMP));
                return Json(lst, JsonRequestBehavior.AllowGet);
            }
        }
        [HttpPost]
        public string Save(EMP emp)
        {
            using (WebClient wc = new WebClient())
            {
                wc.Encoding = Encoding.UTF8;
                wc.Headers["Content-Type"] = "application/json";
                wc.UploadString("http://localhost:63795/api/Empservice/Post", "Post", JsonConvert.SerializeObject(emp));
                return "Data Saved.";
            }
        }
        [HttpPost]
        public string Update(EMP emp)
        {
            using (WebClient wc = new WebClient())
            {
                wc.Encoding = Encoding.UTF8;
                wc.Headers["Content-Type"] = "application/json";
                wc.UploadString("http://localhost:63795/api/Empservice/Put", "Put", JsonConvert.SerializeObject(emp));
                return "Data Updated.";
            }
        }
        [HttpGet]
        public string Delete(int EID)
        {
            using (WebClient wc = new WebClient())
            {
                wc.Encoding = Encoding.UTF8;
                wc.Headers["Content-Type"] = "applicaton/json";
                wc.UploadString("http://localhost:63795/api/Empservice/Delete?EID=" + EID, "Delete", JsonConvert.SerializeObject(EID));
                return "Data Deleted.";
            }
        }
    }
}

View :



<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap-theme.css" rel="stylesheet" />
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-route.js"></script>

<div class="container" ng-app="app" ng-controller="ctrl">
    <form class="form-horizontal" novalidate name="frmEmp">
        <div class="form-group" ng-class="{'has-error':frmEmp.txtEid.$invalid,'has-success':frmEmp.txtEid.$valid}">
            <label class="control-label col-lg-4">EID</label>
            <div class="col-lg-4">
                <input type="text" name="txtEid" id="txtEid" ng-model="EMP.EID" ng-required="frmEmp.txtEid.$invalid" class="form-control">
            </div>
            <span class="has-error help-block " ng-show="frmEmp.txtEid.$invalid">
                Eid should not be blank.
            </span>
        </div>
        <div class="form-group" ng-class="{'has-error':frmEmp.txtName.$invalid,'has-success':frmEmp.txtName.$valid}">
            <label class="control-label col-lg-4">NAME</label>
            <div class="col-lg-4">
                <input type="text" name="txtName" ng-model="EMP.NAME" ng-required="frmEmp.txtName.$invalid" class="form-control">
            </div>
            <span class="has-error help-block" ng-show="frmEmp.txtName.$invalid">
                Name should not be blank.
            </span>
        </div>
        <div class="form-group" >
            <label class="control-label col-lg-4"></label>
            <div class="col-lg-4">
                <input type="button" value="Save" class="btn btn-primary" style="width:80px" ng-click="save(frmEmp.$valid)">
                <input type="button" value="Update" class="btn btn-primary" style="width:80px" ng-click="update(frmEmp.$valid)">
                <input type="button" value="Reset" class="btn btn-primary" style="width:80px" ng-click="reset()">
            </div>
        </div>
        <div class="row">
            <table class="table table-bordered table-condensed table-hover table-responsive table-striped">
               <thead class="bg-primary">
                   <tr>
                       <th>EID</th>
                       <th>NAME</th>
                       <th>ACTION</th>
                   </tr>
               </thead>
                <tbody>
                    <tr ng-repeat="c in list">
                        <td>{{c.EID}}</td>
                        <td>{{c.NAME}}</td>
                        <td><a ng-click="edit(c.EID)">Edit</a>|<a ng-click="del(c.EID)">Delete</a></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </form>
</div>
<script type="text/javascript">
    (function ()
    {
        "use strict";
        angular.module("app", ['ngRoute'])
    .controller("ctrl", function ($scope, EmpService, $route) {
        var emp = {
            EID: null,
            NAME: null
        };
        function CLR() {
            $scope.EMP = emp;

        } CLR();
        function fill() {
            EmpService.Gets().then(function (response) {
                $scope.list = response.data;
            });
        } fill();
        $scope.save = function (isValid) {
            if (isValid) {
                EmpService.Save($scope.EMP).then(function (response) {
                    alert(response.data);
                    $route.reload();
                    CLR();
                    fill();
                });
            }
        }
        $scope.update = function (isValid) {
            if (isValid) {
                EmpService.Update($scope.EMP).then(function (response) {
                    alert(response.data);
                    $route.reload();
                    CLR();
                    fill();
                });
            }
        }
        $scope.del = function (s) {
            if (confirm('Do you want to delete it ?')) {
                EmpService.Delete(s).then(function (response) {
                    alert(response.data);
                    $templateCache.removeAll();
                    fill();
                });
            }
        }
        $scope.edit = function (s) {
            EmpService.Get(s).then(function (response) {
                $scope.EMP = response.data;
            });
        }
        $scope.reset = function ()
        {
            CLR();
        }
    })
    .factory("EmpService", function ($http) {
        var fac = {};
        fac.Save = function (x) {
            return $http({
                url: "/Home/Save",
                method: "Post",
                data: x
            });
        }
        fac.Update = function (x) {
            return $http({
                url: "/Home/Update",
                method: "Post",
                data: x
            });
        }
        fac.Gets = function () {
            return $http({
                url: "/Home/Gets",
                method: "Get"
            });
        }
        fac.Get = function (S) {
            return $http({
                url: "/Home/Get?EID=" + S,
                method: "Get"
            });
        }
        fac.Delete = function (S) {
            return $http({
                url: "/Home/Delete?EID=" + S,
                method: "Get"
            });
        }
        return fac;
    });
    }());
    
</script>


Friday 2 December 2016

Use of strote procedure in EDM in code first approch.

using Nop.Core;
using Nop.Core.Data;
using Nop.Data;
using Nop.Services.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Services.PriceGroup
{
    public class PriceGroupService : IPriceGroupService
    {
        private readonly IRepository<Core.Domain.PriceGroup.PriceGroup> _priceGroupRepository;
        private readonly IEventPublisher _eventPublisher;
        private readonly IDataProvider _dataProvider;
        private readonly IDbContext _dbContext;
        private readonly IRepository<Core.Domain.PriceGroup.PriceGroupStatus> _priceGroupStatusRepository;

        public PriceGroupService(IRepository<Core.Domain.PriceGroup.PriceGroup> priceGroupRepository, IEventPublisher eventPublisher, IDataProvider dataProvider, IDbContext dbContext, IRepository<Core.Domain.PriceGroup.PriceGroupStatus> priceGroupStatusRepository)
        {

            this._priceGroupRepository = priceGroupRepository;
            this._eventPublisher = eventPublisher;
            this._dataProvider = dataProvider;
            this._dbContext = dbContext;
            this._priceGroupStatusRepository = priceGroupStatusRepository;
        }

        public string InsertPriceGroup(Nop.Core.Domain.PriceGroup.PriceGroup entity)
        {
            string sqlResult = string.Empty;
            try
            {
                StringBuilder sbSql = new StringBuilder();
                sbSql.Append("EXEC");
                sbSql.Append(" EmpProcedure");
                sbSql.Append(" @PriceGroupId,");
                sbSql.Append("@PriceGroupName,");
                sbSql.Append("@Percentage,");
                sbSql.Append("@CreatedOnUtc,");
                sbSql.Append("@CreatedBy,");
                sbSql.Append("@UpdatedOnUtc,");
                sbSql.Append("@UpdatedBy,");
                sbSql.Append("@IsDeleted,");
                sbSql.Append("@StatusId,");
                sbSql.Append("@ResultMessage OUT");
                var pOutput = new SqlParameter();
                pOutput.ParameterName = "@ResultMessage";
                pOutput.Direction = ParameterDirection.Output;
                pOutput.SqlDbType = SqlDbType.VarChar;
                pOutput.SqlValue = string.Empty;
                _dbContext.ExecuteSqlCommand(sbSql.ToString(), falsenull,
                            new SqlParameter("@PriceGroupId", entity.Id),
                            new SqlParameter("@PriceGroupName", entity.PriceGroupName),
                            new SqlParameter("@Percentage", entity.Percentage),
                            new SqlParameter("@CreatedOnUtc", entity.CreatedOnUtc),
                            new SqlParameter("@CreatedBy", entity.CreatedBy),
                            new SqlParameter("@UpdatedOnUtc", entity.UpdatedOnUtc),
                            new SqlParameter("@UpdatedBy", entity.UpdatedBy),
                            new SqlParameter("@IsDeleted", entity.IsDeleted),
                            new SqlParameter("@StatusId", entity.StatusId), pOutput
                        );
               sqlResult = Convert.ToString(pOutput.Value);
                _eventPublisher.EntityInserted(entity);
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }

            return sqlResult;
        }

        public IPagedList<Core.Domain.PriceGroup.PriceGroup> GetAllPriceGroup(int pageIndex, int pageSize = int.MaxValue, int groupId = 0,string searchText="")
        {
            var pPriceGroupId = _dataProvider.GetParameter();
            pPriceGroupId.ParameterName = "PriceGroupId";
            pPriceGroupId.Value = groupId;
            pPriceGroupId.DbType = DbType.Int32;
            var psearchText = _dataProvider.GetParameter();
            psearchText.ParameterName = "SearchText";
            psearchText.Value = searchText;
            psearchText.DbType = DbType.String;
            var priceGroupList = _dbContext.ExecuteStoredProcedureList<Nop.Core.Domain.PriceGroup.PriceGroup>(
                   "GetPriceGroupDetails",
                   pPriceGroupId,psearchText);
            var priceGroupPagedList = new PagedList<Core.Domain.PriceGroup.PriceGroup>(priceGroupList.ToList(), pageIndex, pageSize);
            return priceGroupPagedList;

        }
        public void MarkAsDeleted(int Id)
        {
            var data = _priceGroupRepository.Table.Where(pg => pg.Id == Id).SingleOrDefault();
            data.IsDeleted = true;
            _priceGroupRepository.Update(data);
            _eventPublisher.EntityUpdated(data);

        }

        public List<Core.Domain.PriceGroup.PriceGroup> GetAllPriceGroup()
        {
            var priceGroupList = _dbContext.ExecuteStoredProcedureList<Nop.Core.Domain.PriceGroup.PriceGroup>(
                   "GetPriceGroupDetails");

            var priceGroupPagedList = priceGroupList.ToList();
            return priceGroupPagedList;
        }

        public string PriceGroupUpdate(Core.Domain.PriceGroup.PriceGroup entity)
        {
            string sqlResult = string.Empty;
            try
            {
                StringBuilder sbSql = new StringBuilder();
                sbSql.Append("EXEC");
                sbSql.Append(" AddEditPriceGroup");
                sbSql.Append(" @PriceGroupId,");
                sbSql.Append("@PriceGroupName,");
                sbSql.Append("@Percentage,");
                sbSql.Append("@CreatedOnUtc,");
                sbSql.Append("@CreatedBy,");
                sbSql.Append("@UpdatedOnUtc,");
                sbSql.Append("@UpdatedBy,");
                sbSql.Append("@IsDeleted,");
                sbSql.Append("@StatusId,");
                sbSql.Append("@ResultMessage OUT");
                var pOutput = new SqlParameter();
                pOutput.ParameterName = "@ResultMessage";
                pOutput.Direction = ParameterDirection.Output;
                pOutput.SqlDbType = SqlDbType.VarChar;
                pOutput.SqlValue = string.Empty;
                _dbContext.ExecuteSqlCommand(sbSql.ToString(), falsenull,
                            new SqlParameter("@PriceGroupId", entity.Id),
                            new SqlParameter("@PriceGroupName", entity.PriceGroupName.Trim()),
                            new SqlParameter("@Percentage", entity.Percentage),
                            new SqlParameter("@UpdatedOnUtc", entity.UpdatedOnUtc),
                            new SqlParameter("@UpdatedBy", entity.UpdatedBy),
                            new SqlParameter("@IsDeleted", entity.IsDeleted),
                            new SqlParameter("@StatusId", entity.StatusId), pOutput
                        );
                sqlResult = Convert.ToString(pOutput.Value);
                _eventPublisher.EntityInserted(entity);
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
            _eventPublisher.EntityUpdated(entity);
            return sqlResult;

        }
       
        #endregion 
        #region PrivateMethods
        #endregion
    }
}