public ResultDTO UpdateCountry(int CountryId, BusinessEntities.CountryEntity CountryEntity) { var result = new ResultDTO { IsSuccess = false }; if (CountryEntity != null) { var isExist = _unitOfWork.CountryRepository.GetManyQueryable(c => c.CountryName.ToLower() == CountryEntity.CountryName.ToLower() && c.CountryCode == CountryEntity.CountryCode).Count() > 0; if (!isExist) { using (var scope = new TransactionScope()) { var country = _unitOfWork.CountryRepository.GetByID(CountryId); if (country != null) { country.CountryId = CountryEntity.CountryId; country.CountryName = CountryEntity.CountryName; country.CountryCode = CountryEntity.CountryCode; country.IsActive = CountryEntity.IsActive; country.ModifiedBy = CountryEntity.ModifiedBy; country.ModifiedOn = DateTime.Now; _unitOfWork.CountryRepository.Update(country); _unitOfWork.Save(); scope.Complete(); result.IsSuccess = true; result.Message = "Updated Country Successfully"; } } } else { result.IsSuccess = false; result.Message = "Country name already exist"; } } return(result); }
public ResultDTO CreateCountry(BusinessEntities.CountryEntity Country) { var result = new ResultDTO { IsSuccess = false }; var isExist = _unitOfWork.CountryRepository.GetManyQueryable(c => c.CountryName.ToLower() == Country.CountryName.ToLower() && c.CountryCode == Country.CountryCode).Count() > 0; if (!isExist) { using (var scope = new TransactionScope()) { var country = new DataModel.Country { CountryName = Country.CountryName, CountryCode = Country.CountryCode, CreatedBy = Country.CreatedBy, CreatedOn = DateTime.Now, ModifiedBy = Country.CreatedBy, ModifiedOn = DateTime.Now, IsActive = true, }; _unitOfWork.CountryRepository.Insert(country); _unitOfWork.Save(); scope.Complete(); result.IsSuccess = true; result.Message = "Inserted Country Successfully"; } } else { result.IsSuccess = false; result.Message = "Country name already exist"; } return(result); }