public JokeCategoryViewModel InsertJokeCategory(JokeCategoryViewModel jokeCategory) { if (!ValidateInsertJokeCategory(jokeCategory)) throw new Exception(ThrowMessage.JokeCategoryNotAdded.ToString()); return ValidateGetInsertedJokeCategory(jokeCategory); }
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; }
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; }
private bool ValidateInsertJokeCategory(JokeCategoryViewModel jokeCategory) { if (IsJokeCategoryContentExists(jokeCategory)) throw new Exception(ThrowMessage.ThisJokeCategoryExists.ToString()); return IsMainJokeCategoryTranslation(jokeCategory) ? InsertMainJokeCategoryTranslation(jokeCategory) : InsertAnotherJokeCategoryTranslation(jokeCategory); }
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; }
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; }
private bool IsMainJokeCategoryTranslation(JokeCategoryViewModel jokeCategory) { return jokeCategory.Id == 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; }
private bool IsJokeCategoryContentExists(JokeCategoryViewModel jokeCategory) { return RepositoryFactory.Context.JokeCategoryDetails.Any( x => x.JokeCategoryName == jokeCategory.JokeCategoryName); }
private bool IsAnotherJokeCategoryTranslationToEdit(JokeCategoryViewModel jokeCategory) { return jokeCategory.JokeCategoryId > 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; }
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; }
public bool RemoveJokeCategory(JokeCategoryViewModel jokeCategory) { return jokeCategory.TemporarySeveralTranslationDelete ? RemoveAllJokeCategoryTranslation(jokeCategory) : RemoveSelectedJokeCategoryTranslation(jokeCategory); }