public Result Create(QuizCreateAdminDto dto) { var result = _validatorCreate.ValidateResult(dto); if (!result.Success) { return(result); } var entity = Mapper.Map <Quiz>(dto); entity.Slug = _quizRepository.GenerateUniqueSlug(entity.Title); _quizRepository.Insert(entity); _unitOfWork.Commit(); QuizCacheManager.ClearCache(); result.Id = entity.Id; return(result.SetSuccess(Messages.RecordSaved)); }
public Result Edit(int id, QuizEditAdminDto dto) { dto.Id = id; var result = _validatorEdit.ValidateResult(dto); if (!result.Success) { return(result); } if (dto.Id > 0) { var entity = _quizRepository.AsNoTracking.FirstOrDefault(w => w.Id == dto.Id); if (entity == null) { return(result.SetError("There are error for update record. Please try again with refresh.")); } Mapper.Map <Quiz>(dto, entity); _quizRepository.Update(entity); _unitOfWork.Commit(); result.Id = entity.Id; } else { var entity = Mapper.Map <Quiz>(dto); _quizRepository.Insert(entity); _unitOfWork.Commit(); result.Id = entity.Id; } QuizCacheManager.ClearCache(); return(result.SetSuccess(Messages.RecordSaved)); }