Beispiel #1
0
        private CountryDTO Create(CountryViewModel viewModel)
        {
            try
            {
                log.Debug(CountryViewModel.FormatCountryViewModel(viewModel));

                CountryDTO country = new CountryDTO();

                // copy values
                viewModel.UpdateDTO(country, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                country.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                country.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_countryService.AddCountry - " + CountryDTO.FormatCountryDTO(country));

                int id = _countryService.AddCountry(country);

                country.CountryId = id;

                log.Debug("result: 'success', id: " + id);

                return(country);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Beispiel #2
0
        private CountryDTO Update(CountryViewModel viewModel)
        {
            try
            {
                log.Debug(CountryViewModel.FormatCountryViewModel(viewModel));

                // get
                log.Debug("_countryService.GetCountry - countryId: " + viewModel.CountryId + " ");

                var existingCountry = _countryService.GetCountry(viewModel.CountryId);

                log.Debug("_countryService.GetCountry - " + CountryDTO.FormatCountryDTO(existingCountry));

                if (existingCountry != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingCountry, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_countryService.UpdateCountry - " + CountryDTO.FormatCountryDTO(existingCountry));

                    _countryService.UpdateCountry(existingCountry);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingCountry: null, CountryId: " + viewModel.CountryId);
                }

                return(existingCountry);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }