Example #1
0
        /// <summary>
        /// Search Country by id.
        /// </summary>
        /// <param name="request">The Country Request Pivot to retrive.</param>
        /// <returns>Country Response Pivot response.</returns>
        public CountryResponsePivot FindCountries(CountryRequestPivot request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            List <CountryPivot> results = new List <CountryPivot>();
            CountryPivot        result  = new CountryPivot();

            switch (request.FindCountryPivot)
            {
            case FindCountryPivot.CountryId:
                result = _unitOfWork.CountryRepository.GetById(request.CountryPivot.CountryId)?.ToPivot();
                break;

            case FindCountryPivot.CountryCode:
                result = _unitOfWork.CountryRepository.Get(c => c.CountryCode == request.CountryPivot.CountryCode).FirstOrDefault().ToPivot();
                break;

            case FindCountryPivot.CountryShortName:
                result = _unitOfWork.CountryRepository.Get(c => c.CountryShortName == request.CountryPivot.CountryShortName).FirstOrDefault().ToPivot();
                break;
            }
            return(new CountryResponsePivot
            {
                CountryPivotList = results,
                CountryPivot = result
            });
        }
Example #2
0
        /// <summary>
        /// Remove Country.
        /// </summary>
        /// <param name="request">The Country Request Pivot to remove.</param>
        public void DeleteCountry(CountryRequestPivot request)
        {
            if (request.CountryPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            Country country = _unitOfWork.CountryRepository.GetById(request.CountryPivot.CountryId);

            _unitOfWork.CountryRepository.Delete(country);
            _unitOfWork.Save();
        }
Example #3
0
        /// <summary>
        /// Change Country values.
        /// </summary>
        /// <param name="request">The Country Request Pivot to change.</param>
        public void UpdateCountry(CountryRequestPivot request)
        {
            if (request.CountryPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            Country country = _unitOfWork.CountryRepository.GetById(request.CountryPivot.CountryId);

            if (request.CountryPivot.CountryImage != null)
            {
                country.CountryImage = request.CountryPivot.CountryImage;
            }
            _unitOfWork.Save();
        }
Example #4
0
        /// <summary>
        /// Create new Country.
        /// </summary>
        /// <param name="request">The Country Request Pivot to add.</param>
        /// <returns>Country Response Pivot created.</returns>
        public CountryResponsePivot CreateCountry(CountryRequestPivot request)
        {
            if (request.CountryPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            Country country = request.CountryPivot.ToEntity();

            _unitOfWork.CountryRepository.Insert(country);
            _unitOfWork.Save();
            return(new CountryResponsePivot
            {
                CountryPivot = country.ToPivot()
            });
        }