public Response <CountryModel> GetCountryByID(int iCountryID) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpCountry = unitOfWorkStore.GetRepository <Country>(); var obCountry = rpCountry.GetById(iCountryID); CountryModel CountryModel = new CountryModel() { Country_ID = obCountry.Country_ID, Name = obCountry.Name, }; return(new Response <CountryModel>((int)StatusResponses.Success, MessageResConst.Success, CountryModel)); } } catch (Exception ex) { return(new Response <CountryModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <List <CountryModel> > GetCountrys(int pageSize, int pageCurrent, string orderid, string sortDecOrInc, CountryModel CountryModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpCountry = unitOfWorkStore.GetRepository <Country>(); var listCountryEntity = rpCountry.GetAll(); var listCountryModel = (from Country in listCountryEntity select new CountryModel() { Country_ID = Country.Country_ID, Name = Country.Name, }).ToList(); // search if (CountryModel != null) { if (CountryModel.Name != null) { listCountryModel = listCountryModel.Where(x => x.Name.Contains(CountryModel.Name)).ToList(); } } int countData = listCountryModel.Count; listCountryModel = listCountryModel.Skip((pageCurrent - 1) * pageSize).Take(pageSize).ToList(); // order switch (orderid) { case "Name": if (sortDecOrInc == MessageResConst.Increase) { listCountryModel = listCountryModel.OrderBy(x => x.Name).ToList(); } else { listCountryModel = listCountryModel.OrderByDescending(x => x.Name).ToList(); } break; } return(new Response <List <CountryModel> >((int)StatusResponses.Success, countData, MessageResConst.Success, listCountryModel)); } } catch (Exception ex) { return(new Response <List <CountryModel> >((int)StatusResponses.ErrorSystem, 0, ex.Message, null)); } }