Ejemplo n.º 1
0
 /// <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)));
 }
Ejemplo n.º 2
0
        /// <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);
            }
        }