Friday 3 July 2015

Eample of gride and popup in mvc and kendo ui












using System;


using System.Collections.Generic;


using System.Linq;


using System.Text;


using System.Threading.Tasks;





namespace Nop.Core.Domain.Emp


{


public class Emp :BaseEntity


{


public string NAME { get; set; }


}


}








using System;


using System.Collections.Generic;


using System.Linq;


using System.Text;


using System.Threading.Tasks;





namespace Nop.Data.Mapping.Emp


{


public class EmpMap : NopEntityTypeConfiguration<Nop.Core.Domain.Emp.Emp>


{


public EmpMap()


{


this.ToTable("EMP");


this.HasKey(m => m.Id);


this.Property(m => m.NAME).IsRequired();


}


}


}





using Nop.Web.Framework;


using Nop.Web.Framework.Mvc;


using System;


using System.Collections.Generic;


using System.Linq;


using System.Web;





namespace Nop.Admin.Models.Emp


{


public partial class EmpModel : BaseNopEntityModel


{


public string NAME { get; set; }


}


}








using FluentValidation;


using Nop.Admin.Models.Emp;


using Nop.Services.Localization;


using Nop.Web.Framework.Validators;





namespace Nop.Admin.Validators.Emp


{


public class EmpValidator : BaseNopValidator<EmpModel>


{


public EmpValidator(ILocalizationService localizationService)


{


RuleFor(x => x.NAME).NotEmpty().WithMessage(localizationService.GetResource("Admin.Promotions.Discounts.Fields.Name.Required"));


}


}


}








namespace Nop.Admin.Infrastructure


{


public class AutoMapperStartupTask : IStartupTask


{


public void Execute()


{


//dbentity to model mapping


Mapper.CreateMap<Emp, EmpModel>();


//model to dbentity mapping


Mapper.CreateMap<EmpModel, Emp>();


}


}


}











namespace Nop.Admin.Extensions


{


public static class MappingExtensions


{


public static TDestination MapTo<TSource, TDestination>(this TSource source)


{


return Mapper.Map<TSource, TDestination>(source);


}





public static TDestination MapTo<TSource, TDestination>(this TSource source, TDestination destination)


{


return Mapper.Map(source, destination);


}





#region Emp


public static EmpModel ToModel(this Emp entity)


{


return entity.MapTo<Emp, EmpModel>();


}





public static Emp ToEntity(this EmpModel model)


{


return model.MapTo<EmpModel, Emp>();


}


#endregion Emp


}


}











namespace Nop.Services.Emp


{


public interface IEmpService


{


void InsertEmp(Nop.Core.Domain.Emp.Emp entity);


IPagedList<Nop.Core.Domain.Emp.Emp> GetAllEmpg(int pageIndex, int pageSize);


void MarkAsDeleted(int Id);


void EmpUpdate(Core.Domain.Emp.Emp entity);


List<Core.Domain.Emp.Emp> GetAllEmp();


Core.Domain.Emp.Emp GetById(int id);


}


}





namespace Nop.Services.Emp


{


public class EmpService:IEmpService


{


private readonly IRepository<Core.Domain.Emp.Emp> _empRepository;


private readonly IEventPublisher _eventPublisher;


public EmpService(IRepository<Core.Domain.Emp.Emp> empRepository, IEventPublisher eventPublisher)


{





this._empRepository = empRepository;


this._eventPublisher = eventPublisher;


}


public void InsertEmp(Core.Domain.Emp.Emp entity)


{


_empRepository.Insert(entity);


_eventPublisher.EntityInserted(entity);


}





public IPagedList<Core.Domain.Emp.Emp> GetAllEmpg(int pageIndex, int pageSize)


{


var query = _empRepository.Table;





var Items = new PagedList<Core.Domain.Emp.Emp>(query.ToList(), pageIndex, pageSize);


return Items;


}





public void MarkAsDeleted(int Id)


{


var data = _empRepository.Table.Where(pg => pg.Id == Id).SingleOrDefault();


_empRepository.Delete(data);


_eventPublisher.EntityDeleted(data);


}





public void EmpUpdate(Core.Domain.Emp.Emp entity)


{


var data = _empRepository.Table.Where(pg => pg.Id == entity.Id).SingleOrDefault();


data.NAME = entity.NAME;


_empRepository.Update(entity);


_eventPublisher.EntityUpdated(entity);


}





public List<Core.Domain.Emp.Emp> GetAllEmp()


{


return this._empRepository.Table.ToList();


}


public Core.Domain.Emp.Emp GetById(int id)


{


return this._empRepository.GetById(id);


}


}


}








namespace Nop.Web.Framework


{


public class DependencyRegistrar : IDependencyRegistrar


{


public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)


{





builder.RegisterType<EmpService>().As<IEmpService>().InstancePerRequest();




}


}


}





using Nop.Admin.Models.Emp;


using Nop.Core;


using Nop.Services.Localization;


using Nop.Services.Emp;


using Nop.Services.Security;


using System;


using System.Collections.Generic;


using System.Linq;


using System.Web;


using System.Web.Mvc;


using Nop.Admin.Extensions;


using Nop.Web.Framework.Kendoui;


using Nop.Services.Customers;


using Nop.Admin.Models.Catalog;


using Nop.Services.Catalog;


using Nop.Core.Domain.Catalog;


using Nop.Services.Media;





namespace Nop.Admin.Controllers


{


public class EmpController : Controller


{


// GET: Emp


private readonly IEmpService _empService;


private readonly ILocalizationService _localizationService;


private readonly IWorkContext _workContext;


private readonly IWebHelper _webHelper;


private readonly IPermissionService _permissionService;


private readonly ICustomerService _customerService;


private readonly IProductService _productService;


private readonly IPictureService _pictureService;


public EmpController(


ILocalizationService localizationService, IWorkContext workContext, IWebHelper webHelper,


IPermissionService permissionService, IEmpService empService, ICustomerService customerService,


IProductService productService, IPictureService pictureService


)


{


this._localizationService = localizationService;


this._workContext = workContext;


this._webHelper = webHelper;


this._permissionService = permissionService;


this._empService = empService;


this._customerService = customerService;


this._productService = productService;


this._pictureService = pictureService;


}


[HttpGet]


public ActionResult Index()


{


var m = this._empService.GetAllEmp().Select(n => n.ToModel()).ToList();


return View(m);


}


[HttpPost]


public ActionResult IndexKendoData(DataSourceRequest command)


{


var gridModel = new DataSourceResult();


var data =_empService.GetAllEmpg(command.Page - 1, command.PageSize);


gridModel.Data = data.Select(x => new { Id = x.Id, Name = x.NAME});


return Json(gridModel, JsonRequestBehavior.AllowGet);


}


[HttpPost]


public ActionResult Create()


{


EmpModel emp = new EmpModel();


TryUpdateModel(emp);


_empService.InsertEmp(emp.ToEntity());


return RedirectToAction("Index");


}


[HttpPost]


public void Edit(EmpModel emp)


{


_empService.EmpUpdate(emp.ToEntity());


}


[HttpPost]


public void Delete(int Id)


{


_empService.MarkAsDeleted(Id);


}




}


}





















































No comments:

Post a Comment