Beispiel #1
0
        private void CheckForAdd(IList <CountryDto> provincesDtos, int countryId)
        {
            try
            {
                var newprovinces = provincesDtos.Where(x => x.Id == 0);
                if (newprovinces.Any())
                {
                    foreach (var newprovince in newprovinces)
                    {
                        var provinceInsertDto = new ProvinceInsertDto()
                        {
                            Name          = newprovince.Name,
                            MainCountryId = countryId,
                            CreatedBy     = _appSession.GetUserName()
                        };

                        _provinceAppService.Insert(provinceInsertDto);
                    }
                }
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
            }
        }
        public ProvinceDto Insert(ProvinceInsertDto dto)
        {
            ProvinceDto provinceDto = null;

            try
            {
                var province = Mapper.Map <ProvinceInsertDto, Country>(dto);
                province.CreatedBy = _appSession.GetUserName();
                province.IsEnabled = true;
                _unitOfWork.CreateTransaction();

                _unitOfWork.GenericRepository <Country>().Insert(province);
                _unitOfWork.Save();

                _unitOfWork.Commit();

                provinceDto = Mapper.Map <Country, ProvinceDto>(province);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(provinceDto);
        }