Example #1
0
        public static CountryResponse AddCountry(CountryRequest request)
        {
            var response = new CountryResponse();
            var countryRepository = new CountryRepository();
            try
            {
                var newCountry = new country
                                  {
                                      country_name = request.CountryName,
                                      created_date = DateTime.Now,
                                      modified_date = DateTime.Now,
                                      modified_by = request.ModifiedBy
                                  };
                countryRepository.Add(newCountry);
                countryRepository.SaveChanges();
            }
            catch (InvalidOperationException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (ArgumentNullException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (NullReferenceException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (UpdateException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            finally
            {
                countryRepository.Dispose();
            }

            return response;
        }
Example #2
0
        public static CountryResponse GetAllCountries()
        {
            var response = new CountryResponse();
            var countryRepository = new CountryRepository();
            try
            {
                var listCountries = countryRepository.Query().Where(x => x.is_active == 1).ToList();
                foreach (var country in listCountries)
                {
                    countryRepository.Detach(country);
                    response.Countries.Add(AutoMapper.Mapper.Map<country, countryDto>(country));

                }
            }
            catch (InvalidOperationException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (ArgumentNullException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (NullReferenceException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (UpdateException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            finally
            {
                countryRepository.Dispose();
            }

            return response;
        }