Exemplo n.º 1
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 int AddLanguage(Language language)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         if (uow.LanguageRepository.GetAll()
             .Any(l => l.Name == language.Name))
         {
             return -1;
         }
         uow.LanguageRepository.Add(language);
         uow.Save();
         return language.Id;
     }
     //using (var context = new WorldOfWordsDatabaseContext())
     //{
     //    if (context
     //        .Languages
     //        .Any(l => l.Name == language.Name))
     //    {
     //        return -1;
     //    }
     //    context.Languages.Add(language);
     //    context.SaveChanges();
     //    return language.Id;
     //}
 }
Exemplo n.º 2
0
 public LanguageModel ToApiModel(Language domainModel)
 {
     LanguageModel result = new LanguageModel
     {
         Id = domainModel.Id,
         Name = domainModel.Name
     };
     return result;
 }
 public LanguageModel ToApiModel(Language domainModel)
 {
     return new LanguageModel
     {
         Id = domainModel.Id,
         Name = domainModel.Name,
         ShortName = domainModel.ShortName
     };
 }
Exemplo n.º 4
0
 public Language ToDomainModel(LanguageModel apiModel)
 {
     Language result = new Language
     {
         Name = apiModel.Name
     };
     if (apiModel.Id != null)
     {
         result.Id = (int)apiModel.Id;
     }
     return result;
 }
Exemplo n.º 5
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 int AddLanguage(Language language)
 {
     using (var context = new WorldOfWordsDatabaseContext())
     {
         if (context
             .Languages
             .Any(l => l.Name == language.Name))
         {
             return -1;
         }
         context.Languages.Add(language);
         context.SaveChanges();
         return language.Id;
     }
 }