コード例 #1
0
        public void InsertCountryTranslations(Country country, int index)
        {
            string property = "translations";

            if (allCountries[index][property].HasValues)
            {
                country.CountryTranslations = new List <CountryTranslation>(4);
                int len          = allCountries[index][property].Count();
                var translations = allCountries[index]["translations"].ToList();

                for (int i = 0; i < len; i++)
                {
                    var single = (Newtonsoft.Json.Linq.JProperty)translations[i];
                    if (single != null)
                    {
                        //translation exist
                        var lan = db.CountryLanguages.FirstOrDefault(n => n.Code == single.Name);
                        if (lan != null && !String.IsNullOrEmpty((string)single.Value))
                        {
                            var trans = new CountryTranslation();
                            trans.Translation       = (string)single.Value;
                            trans.CountryLanguageID = lan.CountryLanguageID;
                            country.CountryTranslations.Add(trans);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Remove CountryTranslation.
        /// </summary>
        /// <param name="request">The CountryTranslation Request Pivot to remove.</param>
        public void DeleteCountryTranslation(CountryTranslationRequestPivot request)
        {
            if (request.CountryTranslationPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            CountryTranslation countryTranslation = _unitOfWork.CountryTranslationRepository.GetById(request.CountryTranslationPivot.TranslationId);

            _unitOfWork.CountryTranslationRepository.Delete(countryTranslation);
            _unitOfWork.Save();
        }
コード例 #3
0
        /// <summary>
        /// Change CountryTranslation values.
        /// </summary>
        /// <param name="request">The CountryTranslation Request Pivot to change.</param>
        public void UpdateCountryTranslation(CountryTranslationRequestPivot request)
        {
            if (request.CountryTranslationPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            CountryTranslation countryTranslation = _unitOfWork.CountryTranslationRepository.GetById(request.CountryTranslationPivot.TranslationId);

            countryTranslation.CountryName        = request.CountryTranslationPivot.CountryName;
            countryTranslation.CountryTitle       = request.CountryTranslationPivot.CountryTitle;
            countryTranslation.CountryDescription = request.CountryTranslationPivot.CountryDescription;
            countryTranslation.CountrySummary     = request.CountryTranslationPivot.CountrySummary;
            _unitOfWork.Save();
        }
コード例 #4
0
        /// <summary>
        /// Create new CountryTranslation.
        /// </summary>
        /// <param name="request">The CountryTranslation Request Pivot to add.</param>
        /// <returns>CountryTranslation Response Pivot created.</returns>
        public CountryTranslationResponsePivot CreateCountryTranslation(CountryTranslationRequestPivot request)
        {
            if (request.CountryTranslationPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            CountryTranslation countryTranslation = request.CountryTranslationPivot.ToEntity();

            _unitOfWork.CountryTranslationRepository.Insert(countryTranslation);
            _unitOfWork.Save();
            return(new CountryTranslationResponsePivot()
            {
                CountryTranslationPivot = countryTranslation.ToPivot()
            });
        }
コード例 #5
0
 /// <summary>
 /// Change UpdateCountryTranslationRange values.
 /// </summary>
 /// <param name="request">The CountryTranslation Request Pivot to change.</param>
 public void UpdateCountryTranslationRange(CountryTranslationRequestPivot request)
 {
     if (request.CountryTranslationPivotList == null)
     {
         throw new ArgumentNullException(nameof(request));
     }
     foreach (var item in request.CountryTranslationPivotList)
     {
         CountryTranslation countryTranslation = _unitOfWork.CountryTranslationRepository.GetById(item.TranslationId);
         countryTranslation.CountryName        = item.CountryName;
         countryTranslation.CountryTitle       = item.CountryTitle;
         countryTranslation.CountryDescription = item.CountryDescription;
         countryTranslation.CountrySummary     = item.CountrySummary;
         _unitOfWork.Save();
     }
 }
コード例 #6
0
 /// <summary>
 /// From CountryTranslation To CountryTranslation Pivot.
 /// </summary>
 /// <param name="countryTranslation">countryTranslation TO ASSEMBLE</param>
 /// <returns>CountryTranslationPivot result.</returns>
 public static CountryTranslationPivot ToPivot(this CountryTranslation countryTranslation)
 {
     if (countryTranslation == null)
     {
         return(null);
     }
     return(new CountryTranslationPivot
     {
         TranslationId = countryTranslation.TranslationId,
         CountryName = countryTranslation.CountryName,
         CountryTitle = countryTranslation.CountryTitle,
         CountryDescription = countryTranslation.CountryDescription,
         CountrySummary = countryTranslation.CountrySummary,
         CountryId = countryTranslation.CountryId,
         Country = countryTranslation.Country.ToPivot(),
         LanguageId = countryTranslation.LanguageId,
         Language = countryTranslation.Language.ToPivot(),
     });
 }