コード例 #1
0
 public JokeCategoryViewModel InsertJokeCategory(JokeCategoryViewModel jokeCategory)
 {
     if (!ValidateInsertJokeCategory(jokeCategory))
         throw new Exception(ThrowMessage.JokeCategoryNotAdded.ToString());
     return ValidateGetInsertedJokeCategory(jokeCategory);
 }
コード例 #2
0
 public bool PutJokeCategory(JokeCategoryViewModel jokeCategory)
 {
     var entity = GetJokeCategoryDetail(jokeCategory.JokeCategoryId);
     if (IsJokeCategoryContentExists(jokeCategory))
         throw new Exception(ThrowMessage.ThisJokeCategoryExists.ToString());
     entity.JokeCategoryName = jokeCategory.JokeCategoryName;
     RepositoryFactory.Context.SaveChanges();
     return true;
 }
コード例 #3
0
 private JokeCategoryViewModel ValidateGetInsertedJokeCategory(JokeCategoryViewModel jokeCategory)
 {
     var insertedJokeCategory =
            RepositoryFactory.Context.JokeCategoryDetails.FirstOrDefault(
                x => x.JokeCategoryName == jokeCategory.JokeCategoryName);
     if (insertedJokeCategory == null)
         throw new Exception(ThrowMessage.JokeCategoryNotAdded.ToString());
     jokeCategory.Id = insertedJokeCategory.JokeCategory.Id;
     jokeCategory.JokeCategoryId = insertedJokeCategory.Id;
     jokeCategory.JokeCategoryTranslations =FillAvailableJokeCategoryTranslation(jokeCategory.Id);
     return jokeCategory;
 }
コード例 #4
0
 private bool ValidateInsertJokeCategory(JokeCategoryViewModel jokeCategory)
 {
     if (IsJokeCategoryContentExists(jokeCategory))
         throw new Exception(ThrowMessage.ThisJokeCategoryExists.ToString());
     return IsMainJokeCategoryTranslation(jokeCategory) ?
         InsertMainJokeCategoryTranslation(jokeCategory) :
     InsertAnotherJokeCategoryTranslation(jokeCategory);
 }
コード例 #5
0
 private bool RemoveAllJokeCategoryTranslation(JokeCategoryViewModel jokeCategory)
 {
     var jokeCategoryDetail =
               RepositoryFactory.Context.JokeCategoryDetails.Where(x => x.JokeCategory.Id == jokeCategory.Id);
     RepositoryFactory.Context.JokeCategoryDetails.RemoveRange(jokeCategoryDetail);
     var mainJokeCategory = GetJokeCategory(jokeCategory.Id);
     if (mainJokeCategory != null)
         RepositoryFactory.Context.JokeCategories.Remove(mainJokeCategory);
     RepositoryFactory.Context.SaveChanges();
     return true;
 }
コード例 #6
0
 private bool RemoveSelectedJokeCategoryTranslation(JokeCategoryViewModel jokeCategory)
 {
     var jokeCategoryDetail = GetJokeCategoryDetail(jokeCategory.JokeCategoryId);
     RepositoryFactory.Context.JokeCategoryDetails.Remove(jokeCategoryDetail);
     int jokeCategoryTranslationCount = 0;
     jokeCategory.JokeCategoryTranslations?.ForEach(x =>
     {
         if (x.HasTranslation)
             jokeCategoryTranslationCount++;
     });
     if (jokeCategoryTranslationCount == 1)
     {
         var mainJokeCategory = GetJokeCategory(jokeCategory.Id);
         if (mainJokeCategory != null)
             RepositoryFactory.Context.JokeCategories.Remove(mainJokeCategory);
     }
     RepositoryFactory.Context.SaveChanges();
     return true;
 }
コード例 #7
0
 private bool IsMainJokeCategoryTranslation(JokeCategoryViewModel jokeCategory)
 {
     return jokeCategory.Id == 0;
 }
コード例 #8
0
 private bool PutJokeCategoryContent(JokeCategoryViewModel jokeCategory)
 {
     var jokeCategoryToEdit =
                 RepositoryFactory.Context.JokeCategoryDetails.FirstOrDefault(
                     x => x.Id == jokeCategory.JokeCategoryId);
     if (jokeCategoryToEdit == null)
         throw new Exception(ThrowMessage.JokeCategoryTranslationNotExists.ToString());
     jokeCategoryToEdit.JokeCategoryName = jokeCategory.JokeCategoryName;
     RepositoryFactory.Context.SaveChanges();
     return true;
 }
コード例 #9
0
 private bool IsJokeCategoryContentExists(JokeCategoryViewModel jokeCategory)
 {
     return
         RepositoryFactory.Context.JokeCategoryDetails.Any(
             x => x.JokeCategoryName == jokeCategory.JokeCategoryName);
 }
コード例 #10
0
 private bool IsAnotherJokeCategoryTranslationToEdit(JokeCategoryViewModel jokeCategory)
 {
     return jokeCategory.JokeCategoryId > 0;
 }
コード例 #11
0
 private bool InsertMainJokeCategoryTranslation(JokeCategoryViewModel jokeCategory)
 {
     JokeCategoryDao entity = new JokeCategoryDao
     {
         CreationDate = DateTime.UtcNow,
         JokeCategoryDetail = new List<JokeCategoryDetailDao>
         {
             new JokeCategoryDetailDao
             {
                 JokeCategoryName = jokeCategory.JokeCategoryName,
                 Language = GetLanguage(jokeCategory.LanguageId)
             }
         }
     };
     RepositoryFactory.Context.JokeCategories.Add(entity);
     RepositoryFactory.Context.SaveChanges();
     return true;
 }
コード例 #12
0
 private bool InsertAnotherJokeCategoryTranslation(JokeCategoryViewModel jokeCategory)
 {
     if (IsAnotherJokeCategoryTranslationToEdit(jokeCategory))
         return PutJokeCategoryContent(jokeCategory);
     var entity = GetJokeCategory(jokeCategory.Id);
     entity?.JokeCategoryDetail.Add(new JokeCategoryDetailDao { JokeCategoryName = jokeCategory.JokeCategoryName, Language = GetLanguage(jokeCategory.LanguageId) });
     RepositoryFactory.Context.SaveChanges();
     return true;
 }
コード例 #13
0
 public bool RemoveJokeCategory(JokeCategoryViewModel jokeCategory)
 {
     return jokeCategory.TemporarySeveralTranslationDelete
         ? RemoveAllJokeCategoryTranslation(jokeCategory)
         : RemoveSelectedJokeCategoryTranslation(jokeCategory);
 }