/// <summary>
 /// Adds a new language to the database.
 /// </summary>
 /// <param name="language"></param>
 /// <returns></returns>
 public int Post(LanguageModel language)
 {
     if (language == null)
     {
         throw new ArgumentException("Language cannot be null!", "language");
     }
     return _service.AddLanguage(_mapper.ToDomainModel(language));
 }
Example #2
0
 public LanguageModel ToApiModel(Language domainModel)
 {
     LanguageModel result = new LanguageModel
     {
         Id = domainModel.Id,
         Name = domainModel.Name
     };
     return result;
 }
Example #3
0
 public Language ToDomainModel(LanguageModel apiModel)
 {
     Language result = new Language
     {
         Name = apiModel.Name
     };
     if (apiModel.Id != null)
     {
         result.Id = (int)apiModel.Id;
     }
     return result;
 }
        /// <summary>
        /// Adds a new language to the database.
        /// </summary>
        /// <param name="language">The language to be added to the database.</param>
        /// <returns>The id of a new database record, or -1, if such language already exists.</returns>
        public async Task<int> AddAsync(LanguageModel model)
        {
            using (var uow = unitOfWorkFactory.GetUnitOfWork())
            {
                Language language = languageMapper.ToDomainModel(model);

                if (uow.LanguageRepository.GetAll().Any(l => l.Name == language.Name))
                {
                    return -1;
                }

                uow.LanguageRepository.Add(language);

                await uow.SaveAsync();

                return language.Id;
            }
        }
 public async Task<int> Post(LanguageModel model)
 {
     return await languageService.AddAsync(model);
 }