public void ArchiveConcept_Returns_Deleted_Concept_On_Archive_Successful() { A.CallTo(() => ConceptRepository.GetById(A <int> ._)).Returns(Mock.MockConcept(_status)); A.CallTo(() => StatusRepository.GetByName(A <string> ._)).Returns(_status); A.CallTo(() => ConceptRepository.Update(A <Concept> ._)).Returns(Mock.MockConcept(_status)); var response = Service.ArchiveConcept(0, allowedUserEmail); Assert.NotNull(response.Data); Assert.IsType <ConceptDto>(response.Data); }
protected override async Task HandleTransacted(RenameConceptCommand command, CancellationToken cancellationToken = default(CancellationToken)) { var concept = await _conceptRepository.Get(command.ConceptId, cancellationToken); if (concept == null) { throw new EntityNotFoundException("The requested concept was not found."); } concept.Rename(command.Name); await _conceptRepository.Update(concept); }
public Response UpdateConcept(UpdateConceptDto dto) { var newConceptVersion = Mapper.Map <Concept>(dto); var viewModel = new Response(); var oldConceptVersion = _conceptRepository.GetById(newConceptVersion.Id); // Concept does not exist in the database, so cannot update it. if (oldConceptVersion == null) { return(null); } var language = GetLanguage(viewModel, dto.MetaIds); if (language == null) { return(viewModel); } // Readonly fields newConceptVersion.LanguageId = language.Id; newConceptVersion.Created = oldConceptVersion.Created; newConceptVersion.ExternalId = oldConceptVersion.ExternalId; newConceptVersion.MediaIds = oldConceptVersion.MediaIds; newConceptVersion.AuthorName = oldConceptVersion.AuthorName; newConceptVersion.AuthorEmail = oldConceptVersion.AuthorEmail; newConceptVersion.GroupId = oldConceptVersion.GroupId; newConceptVersion.UrlToContent = oldConceptVersion.UrlToContent; try { _conceptRepository.Update(newConceptVersion); } catch (Exception e) { viewModel.Errors.TryAddModelError("errorMessage", "An database error has occured. Could not update concept."); return(viewModel); } //updating meta list for concept var oldMetaList = oldConceptVersion.Meta; List <MetaData> newMetaIdList = _metaRepository.GetLanguageVariationForThisList(oldMetaList, language.Id); List <int> metaIds = new List <int>(); foreach (var metaData in newMetaIdList) { metaIds.Add(metaData.Id); } // Updating media for concept var toBeDeleted = oldConceptVersion.Media .Where(x => !dto.Media.Exists(y => y.ExternalId == x.ExternalId && y.MediaTypeId == x.MediaTypeId)) .Select(x => x.Id) .ToList(); var toBeInserted = dto.Media .Where(x => !oldConceptVersion.Media.Exists(y => y.ExternalId == x.ExternalId && y.MediaTypeId == x.MediaTypeId)) .ToList(); try { if (toBeDeleted.Count > 0) { _conceptMediaRepository.DeleteConnectionBetweenConceptAndMedia(oldConceptVersion.Id, toBeDeleted); } } catch (Exception e) { viewModel.Errors.TryAddModelError("errorMessage", "An database error has occured. Could not delete medias for concept."); return(viewModel); } try { _conceptMediaRepository.InsertMediaForConcept(oldConceptVersion.Id, toBeInserted); } catch (Exception e) { viewModel.Errors.TryAddModelError("errorMessage", "An database error has occured. Could not insert media on concept."); return(viewModel); } viewModel.Data = Mapper.Map <ConceptDto>(_conceptRepository.GetById(dto.Id)); return(viewModel); }