/// <summary>
        /// Add New Customer Into Database
        /// </summary>
        /// <param name="customerModel">Object Of Customer</param>
        /// <returns>Returns Status Of The Operation in Boloean</returns>
        public bool AddCustomer(CustomerModel customerModel)
        {
            Customer customer = ModelMapperService.Map <CustomerModel, Customer>(customerModel);

            DBContext.Customers.Add(customer);
            DBContext.SaveChanges();
            return(true);
        }
Esempio n. 2
0
 /// <summary>
 /// Returns State From Database Matching With Given Id
 /// </summary>
 /// <param name="id">State Id</param>
 /// <returns>State Model</returns>
 public StateModel GetState(int id)
 {
     return(ModelMapperService
            .Map <State, StateModel>(
                DBContext
                .States
                .Where(x => x.StateId == id)
                .FirstOrDefault()));
 }
        /// <summary>
        /// Returns Customer From Database Matching With Given Id
        /// </summary>
        /// <param name="id">Customer Id</param>
        /// <returns>CustomerModel</returns>
        public CustomerModel GetCustomer(int id)
        {
            Customer customer = DBContext
                                .Customers
                                .Where(x => x.CustomerId == id)
                                .FirstOrDefault();

            return(ModelMapperService.Map <Customer, CustomerModel>(customer));
        }
Esempio n. 4
0
 public CountryModel GetCountry(int id)
 {
     return(ModelMapperService
            .Map <Country, CountryModel>(
                DBContext
                .Countries
                .Where(x => x.CountryId == id)
                .FirstOrDefault()));
 }
Esempio n. 5
0
 /// <summary>
 /// Returns City From Database Matching With Given Id
 /// </summary>
 /// <param name="id">City Id</param>
 /// <returns>City Model</returns>
 public CityModel GetCity(int id)
 {
     return(ModelMapperService
            .Map <City, CityModel>(
                DBContext
                .Cities
                .Where(x => x.CityId == id)
                .FirstOrDefault()));
 }
        public bool UpdateCustomer(CustomerModel customerModel)
        {
            DBContext
            .Entry(
                ModelMapperService
                .Map <CustomerModel, Customer>(customerModel)
                ).State = System.Data.Entity.EntityState.Modified;

            DBContext.SaveChanges();

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Returns All States List From Database
        /// </summary>
        /// <returns>List<StateModel></returns>
        public List <StateModel> GetAllStates()
        {
            //Get Source Data Into DatabaseEntites
            List <State> source = DBContext.States.ToList();

            //Create BusinessEntites List
            List <StateModel> destination = new List <StateModel>();

            foreach (State state in source)
            {
                //Convert DatabaseEntity Into BusinessEntity And Add Into The List
                destination.Add(ModelMapperService.Map <State, StateModel>(state));
            }

            return(destination);
        }
        /// <summary>
        /// Returns All Customer List From Database
        /// </summary>
        /// <returns>List<CustomerModel></returns>
        public List <CustomerModel> GetAllCustomers()
        {
            //Get Source Data Into DatabaseEntites
            List <Customer> source = DBContext.Customers.ToList();

            //Create BusinessEntites List
            List <CustomerModel> destination = new List <CustomerModel>();

            foreach (Customer customer in source)
            {
                //Convert DatabaseEntity Into BusinessEntity And Add Into The List
                destination.Add(ModelMapperService.Map <Customer, CustomerModel>(customer));
            }

            return(destination);
        }
Esempio n. 9
0
        /// <summary>
        /// Returns All Country List From Database
        /// </summary>
        /// <returns>List<CountryModel></returns>
        public List <CountryModel> GetAllCountries()
        {
            //Get Source Data Into DatabaseEntites
            List <Country> source = DBContext.Countries.ToList();

            //Create BusinessEntites List
            List <CountryModel> destination = new List <CountryModel>();

            foreach (Country country in source)
            {
                //Convert DatabaseEntity Into BusinessEntity And Add Into The List
                destination.Add(ModelMapperService.Map <Country, CountryModel>(country));
            }

            return(destination);
        }
Esempio n. 10
0
        /// <summary>
        /// Get List Of City By State Id
        /// </summary>
        /// <param name="id">Id Of State</param>
        /// <returns>List Of CityModel</returns>
        public List <CityModel> GetAllCities(int id)
        {
            //Get Source Data Into DatabaseEntites
            List <City> source = DBContext
                                 .Cities
                                 .Where(x => x.StateId == id)
                                 .ToList();

            //Create BusinessEntites List
            List <CityModel> destination = new List <CityModel>();

            foreach (City city in source)
            {
                //Convert DatabaseEntity Into BusinessEntity And Add Into The List
                destination.Add(ModelMapperService.Map <City, CityModel>(city));
            }

            return(destination);
        }