/// <summary> /// Add answer description. /// </summary> /// <param name="answerDescription"></param> /// <returns></returns> public DataOperationResult AddAnswerDescription(AnswerDescriptionDto answerDescription) { var answerDescriptionObject = new AnswerDescription(); answerDescriptionObject.FromDto(answerDescription); // Save to database _repository.Insert(answerDescriptionObject); _repository.SaveChangesAsync().Wait(); // Add to cache. var cachedData = GetCachedData(); cachedData.Insert(answerDescriptionObject); // Add to user cache if there is a user if (answerDescriptionObject.UserId != null) { var userCachedData = GetUserCachedData(); userCachedData.Insert(new AnswerDescriptionUserMask(answerDescriptionObject)); } return(new DataOperationResult() { IsNew = true, IntId = answerDescriptionObject.AnswerId }); }
public void AnswerDescriptionTests_IDtoConvertable_Converts() { var dto = _answerDescription.ToDto(); Assert.Equal(dto.Id, _answerDescription.Id); Assert.Equal(dto.AnswerId, _answerDescription.AnswerId); Assert.Equal(dto.Description, _answerDescription.Description); Assert.Equal(dto.UserId, _answerDescription.UserId); Assert.Equal(dto.DateAdded, _answerDescription.DateAdded); var newAnswerDescription = new AnswerDescription(); newAnswerDescription.FromDto(dto); Assert.Equal(newAnswerDescription.Id, _answerDescription.Id); Assert.Equal(newAnswerDescription.Description, _answerDescription.Description); Assert.Equal(newAnswerDescription.AnswerId, _answerDescription.AnswerId); Assert.Equal(newAnswerDescription.UserId, _answerDescription.UserId); Assert.NotEqual(newAnswerDescription.DateAdded, _answerDescription.DateAdded); }