Monday 18 January 2016

BAXA DOCUMENT

(4.BusinessEntities)

using System;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace OLS.BusinessEntities.Model
{
    [DataContract(Name="EMPModel")]
    public class EMPModel
    {
        [DataMember(Name = "EID")]
        public int EID
        {
            get;
            set;
        }
        [DataMember(Name = "NAME")]
        public string NAME
        {
            get;
            set;
        }
    }
}

(2.DataLayers)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OLS.BusinessEntities.Model;

namespace OLS.DomainModel.Data.Repositories.Interface
{
  public  interface IEMPRepository
    {
      List<EMPModel> Gets(string applicationConnectionString);
      EMPModel Get(int Id, string applicationConnectionString);
      void Post(EMPModel emp, string applicationConnectionString);
      void Put(EMPModel emp, string applicationConnectionString);
      void Delete(EMPModel emp, string applicationConnectionString);
    }
}



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OLS.DomainModel.Data.Repositories.Interface;
using OLS.BusinessEntities.Model;
using Contesto.Core.Data;
using System.Data.Common;
using System.Data;
using OLS.DomainModel.Data.NonTracking;
using OLS.BusinessEntities.Model.Exceptions;
using System.IO;

namespace OLS.DomainModel.Data.Repositories
{
  public  class EMPRepository : IEMPRepository

    {
      public List<EMPModel> Gets(string applicationConnectionString)
        {
            Database db = new Database(applicationConnectionString);
            DbConnection connection = null;
            DbCommand command = null;
            List<DbParameter> dbParams = new List<DbParameter>();
            var result = new List<EMPModel>();
            db.AddInParam(dbParams, "mark", DbType.Int32, 4);
         
            DbDataReader objReader = db.ExecuteReader(ref connection, ref command, "p", CommandType.StoredProcedure, dbParams.ToArray());

            using (var context = new OnlineSalesContainer())
            {
                result.AddRange(context.Translate<EMPModel>(objReader));
            }
            return result;
        }

      public EMPModel Get(int Id, string applicationConnectionString)
        {
            Database db = new Database(applicationConnectionString);
            DbConnection connection = null;
            DbCommand command = null;
            List<DbParameter> dbParams = new List<DbParameter>();
            var result = new List<EMPModel>();
            db.AddInParam(dbParams, "eid", DbType.Int32, Id);
            db.AddInParam(dbParams, "mark", DbType.Int32, 5);
            DbDataReader objReader = db.ExecuteReader(ref connection, ref command, "p", CommandType.StoredProcedure, dbParams.ToArray());

            using (var context = new OnlineSalesContainer())
            {
                result.AddRange(context.Translate<EMPModel>(objReader));
            }
            return result.SingleOrDefault();
           
        }

      public void Post(EMPModel emp, string applicationConnectionString)
        {
            Database db = new Database(applicationConnectionString);
            List<DbParameter> dbparams = new List<DbParameter>();
            db.AddInParam(dbparams, "eid", DbType.Int32, emp.EID);
            db.AddInParam(dbparams, "name", DbType.String, emp.NAME);
            db.AddInParam(dbparams, "mark", DbType.Int32, 1);
            db.ExecuteNonQuery("p", CommandType.StoredProcedure, dbparams.ToArray());
        }

      public void Put(EMPModel emp, string applicationConnectionString)
        {
            Database db = new Database(applicationConnectionString);
            List<DbParameter> dbparams = new List<DbParameter>();
            db.AddInParam(dbparams, "eid", DbType.Int32, emp.EID);
            db.AddInParam(dbparams, "name", DbType.String, emp.NAME);
            db.AddInParam(dbparams, "mark", DbType.Int32, 2);
            db.ExecuteNonQuery("p", CommandType.StoredProcedure, dbparams.ToArray());
        }

      public void Delete(EMPModel emp, string applicationConnectionString)
        {
            Database db = new Database(applicationConnectionString);
            List<DbParameter> dbparams = new List<DbParameter>();
            db.AddInParam(dbparams, "eid", DbType.Int32, emp.EID);
            db.AddInParam(dbparams, "mark", DbType.Int32, 3);
            db.ExecuteNonQuery("p", CommandType.StoredProcedure, dbparams.ToArray());
        }
    }
}


(3.ServiceLayers)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using OLS.BusinessEntities.Model.Exceptions;
using OLS.BusinessEntities.Model;
using Contesto.Core.Utility.Context;

namespace OLS.ServiceInterface
{
    [ServiceContract]
   public  interface IEMPService
    {
        [OperationContract]
        List<EMPModel> Gets();
          [OperationContract]
        EMPModel Get(int Id);
          [OperationContract]
        void Post(EMPModel emp);
          [OperationContract]
        void Put(EMPModel emp);
          [OperationContract]
        void Delete(EMPModel emp);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OLS.ServiceInterface;
using OLS.DomainModel.Data.Repositories.Interface;
using OLS.BusinessEntities.Model;
using Contesto.Core.Utility.Context;
using OLS.BusinessEntities.Model.Exceptions;
using Contesto.Core.ProxyService.Helper;
using System.Threading;
using System.Web.Configuration;
using System.IO;
using OLS.Common;
using System.Configuration;
using System.ComponentModel;
using System.Drawing;
using System.Net;
using System.Xml;
using Newtonsoft.Json;

namespace OLS.ServiceAdapter
{
   public class EMPAdapter:BaseAdapter,IEMPService
    {
       private readonly IEMPRepository _repository = null;
       public EMPAdapter(IEMPRepository repository)
       {
           _repository = repository;
       }
        public List<EMPModel> Gets()
        {
         return   _repository.Gets(this.ConnectionString);
        }

        public EMPModel Get(int Id)
        {
          return  _repository.Get(Id, this.ConnectionString);
        }

        public void Post(EMPModel emp)
        {
            _repository.Post(emp, this.ConnectionString);
        }

        public void Put(EMPModel emp)
        {
            _repository.Put(emp, this.ConnectionString);
        }

        public void Delete(EMPModel emp)
        {
            _repository.Delete(emp, this.ConnectionString);
        }
    }
}



using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using OLS.ServiceInterface;
using Contesto.IOC;
using OLS.ServiceAdapter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using OLS.ServiceInterface;
using Contesto.IOC;
using OLS.ServiceAdapter;
using Microsoft.Practices.Unity;
using OLS.BusinessEntities.Model;
using Contesto.Core.Utility.Context;
using OLS.BusinessEntities.Model.Exceptions;
using System.Collections.Generic;

namespace OLS.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "EMPService" in code, svc and config file together.
    public class EMPService :IEMPService
    {
        private IEMPService _adapter;
        public EMPService()
        {
            _adapter = IocContainer.Container.Resolve<EMPAdapter>();
        }
        public List<EMPModel> Gets()
        {
            return _adapter.Gets();
        }

        public EMPModel Get(int Id)
        {
            return _adapter.Get(Id);
        }

        public void Post(EMPModel emp)
        {
            _adapter.Post(emp);
        }

        public void Put(EMPModel emp)
        {
            _adapter.Put(emp);
        }

        public void Delete(EMPModel emp)
        {
            _adapter.Delete(emp);
        }
    }
}




then copy the url



5.Presentation(UI)


Right click on the service refernce clikc on the


Copy the url and paste in the address bar  and give a name for namespace in the below picture.


 5.Presentation(UI)
Context folder

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OLS.BusinessEntities.Model;
using Contesto.IOC;
using OLS.BusinessEntities.Model.Exceptions;
using System.ServiceModel;
using OLS.UI.ServiceProxies.EMPService;
using Microsoft.Practices.Unity;
using OLS.Common.Extensions;
using OLS.UI.ServiceProxies.FileUploadService;
using Contesto.Core.Utility.Context;

namespace OLS.UI.ServiceProxies.Context
{
   public  class EMPContext
    {
        #region Init

        /// <summary>
        /// Prevents a default instance of the <see cref="CustomerContext"/> class from being created.
        /// </summary>
        private EMPContext() { }

        /// <summary>
        /// Initializes the <see cref="PaymentContext"/> class.
        /// </summary>
        static EMPContext() { }

        #endregion
        public static EMPModel[] Gets()
        {
         
            return IocContainer.Container.Resolve<EMPServiceClient>()
                .TryInvoke < EMPServiceClient,EMPModel[]>(proxy =>proxy.Gets());
        }
        public static EMPModel Get(int Id)
        {

            return IocContainer.Container.Resolve<EMPServiceClient>()
                .TryInvoke<EMPServiceClient, EMPModel>(proxy => proxy.Get(Id));
        }
        public void Post(EMPModel emp)
        {
             IocContainer.Container.Resolve<EMPServiceClient>()
                          .TryInvoke<EMPServiceClient>(proxy => proxy.Post(emp));
        }
        public void Put(EMPModel emp)
        {
            IocContainer.Container.Resolve<EMPServiceClient>()
                         .TryInvoke<EMPServiceClient>(proxy => proxy.Put(emp));
        }
        public void Delete(EMPModel emp)
        {
            IocContainer.Container.Resolve<EMPServiceClient>()
                         .TryInvoke<EMPServiceClient>(proxy => proxy.Delete(emp));
        }
    }
}

5.Presentation(UI)\ServiceProxies\OLS.UI.ServiceProxies\app.config
copy the endpoint form the above path
<endpoint address="http://localhost:5000/EMPService.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IEMPService" contract="EMPService.IEMPService"
        name="BasicHttpBinding_IEMPService" />


5.Presentation(UI)\WebSite\OLS.UI.Web.Customer\Config\devwcfClient.config
paste here
<endpoint address="http://localhost:5000/EMPService.svc" binding="basicHttpBinding" bindingConfiguration="DefaultBindingConfiguration" contract="EMPService.IEMPService" name="BasicHttpBinding_IEMPService" />



3.ServiceLayers\OLS.Service\Config\unity.config
add below code

<alias alias="IEMPRepository" type="OLS.DomainModel.Data.Repositories.Interface.IEMPRepository, OLS.DomainModel.Data" />
  <alias alias="EMPRepositoryImplementation" type="OLS.DomainModel.Data.Repositories.EMPRepository, OLS.DomainModel.Data" />


  <register type="IEMPRepository" mapTo="EMPRepositoryImplementation">
      <lifetime type="singleton" />
    </register>


controller

using System;
using System.Configuration;
using System.IO;
using System.Net;
using System.ServiceModel;
using System.Text;
using System.Web.Mvc;
using Contesto.Core.StateManagement.Session;
using Contesto.Web.Common.Entities;
using OLS.BusinessEntities.Model;
using OLS.Common.Extensions;
using OLS.Common.MVC;
using OLS.UI.ServiceProxies.Constants;
using OLS.UI.ServiceProxies.Context;

using OLS.UI.Web.Customer.Helpers;
using OLS.UI.Web.Customer.Models;
using System.Collections.Generic;
using OLS.UI.ServiceProxies.EMPService;



namespace OLS.UI.Web.Customer.Controllers
{
    public class TestController : Controller
    {
        EMPServiceClient _client;
        public TestController()
        {
            _client = new EMPServiceClient();
        }
        public ActionResult Index()
        {
            EMPModel[] m = _client.Gets();
            List<EMPVM> lst = new List<EMPVM>();
            foreach (EMPModel n in m)
            {
                EMPVM vm = new EMPVM();
                vm.EID = n.EID;
                vm.NAME = n.NAME;
                lst.Add(vm);
            }

            return View(lst);
                return View();
        }
        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]
        [ActionName("Create")]
        public ActionResult Create1()
        {
            EMPVM vm = new EMPVM();
            TryUpdateModel(vm);
            if (ModelState.IsValid)
            {
                EMPModel em = new EMPModel();
                em.EID = vm.EID;
                em.NAME = vm.NAME;
                _client.Post(em);
                return RedirectToAction("Index");
            }
            return View();
         
        }
        [HttpGet]
        public ActionResult Edit(int id)
        {
            EMPModel em = _client.Get(id);
            EMPVM vm = new EMPVM();
            vm.EID = em.EID;
            vm.NAME = em.NAME;
            return View(vm);
            return View();
        }
        [HttpPost]
        public ActionResult Edit()
        {
            EMPVM vm = new EMPVM();
            TryUpdateModel(vm);
            if (ModelState.IsValid)
            {
                EMPModel em = new EMPModel();
                em.EID = vm.EID;
                em.NAME = vm.NAME;
                _client.Put(em);
                return RedirectToAction("Index");
            }
            return View();
        }
        [HttpGet]
        public ActionResult Delete(int id)
        {
            EMPModel em = _client.Get(id);
            EMPVM vm = new EMPVM();
            vm.EID = em.EID;
            vm.NAME = em.NAME;
            return View(vm);
            return View();
        }
        [HttpPost]
        public ActionResult Delete()
        {
            EMPVM vm = new EMPVM();
            TryUpdateModel(vm);
            if (ModelState.IsValid)
            {
                EMPModel em = new EMPModel();
                em.EID = vm.EID;
                em.NAME = vm.NAME;
                _client.Delete(em);
                return RedirectToAction("Index");
            }
            return View();
        }

    }
}









No comments:

Post a Comment