/// <summary> /// Saves the specified object to the repository and evicts it from the session. /// </summary> /// <exception cref="ArgumentNullException"><paramref name="repository" /> is <see langword="null" />.</exception> public static void SaveAndEvict <T, TId>(this IRepositoryWithTypedId <T, TId> repository, T entity) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } repository.Evict(repository.Save(entity)); }
/// <summary> /// Saves the specified object to the repository and evicts it from the session. /// </summary> /// <exception cref="ArgumentNullException"><paramref name="repository" /> or <paramref name="entity"/> is <see langword="null" />.</exception> public static void SaveAndEvict <T, TId>([NotNull] this IRepositoryWithTypedId <T, TId> repository, [NotNull] T entity) where T : class { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } if (entity == null) { throw new ArgumentNullException(nameof(entity)); } repository.Evict(repository.Save(entity)); }
public async Task <IActionResult> Post(int id) { var category = new Category() { Name = "etst" + new Random().Next() }; _context.Set <Category>().Add(category); var multipleChoicesQuestion = _questionRepo.GetById(id) as MultipleChoicesQuestion; multipleChoicesQuestion.AnswerVariants = new List <AnswerVariant>() { new AnswerVariant() }; _questionRepo.Save(multipleChoicesQuestion); await _context.SaveChangesAsync(); return(Ok(id)); }