// Method to add tags based on the id and a bit messy because it is sent as a string. private async Task addTags(Coordination coordination) { try { // Tries to parse tag ids from string to int foreach (string idString in coordination.TagsIds.Split(',')) { if (idString == null || idString == "") { continue; } int tagId = Int32.Parse(idString.Trim()); Tags existingTag = await _tagsRepository.FindByIdAsync(tagId); if (existingTag != null) { // If the tag exists, add it to the list of tags in the coordination CoordinationTags coordinationTag = new CoordinationTags { Coordination = coordination, Tags = existingTag }; coordination.CoordinationTags.Add(coordinationTag); } } await _unitOfWork.CompleteAsync(); } catch (Exception ex) { await _unitOfWork.CompleteAsync(); Console.WriteLine(ex.Message); } }
private async Task addTags(Dataset dataset) { try { // Tries to parse tag ids from string to int foreach (string idString in dataset.TagsIds.Split(',')) { if (idString == null || idString == "") { continue; } int id = Int32.Parse(idString.Trim()); Tags existingTag = await _tagsRepository.FindByIdAsync(id); if (existingTag != null) { // If the tag exists, add it to the list of tags in the dataset DatasetTags datasetTag = new DatasetTags { Dataset = dataset, Tags = existingTag }; dataset.DatasetTags.Add(datasetTag); } } await _unitOfWork.CompleteAsync(); } catch (Exception ex) { await _unitOfWork.CompleteAsync(); Console.WriteLine(ex.Message); } }
public async Task <TagsResponse> UpdateAsync(int id, Tags tags) { var existingTags = await _tagsRepository.FindByIdAsync(id); if (existingTags == null) { return(new TagsResponse("tags not found.")); } existingTags.Name = tags.Name; try { _tagsRepository.Update(existingTags); await _unitOfWork.CompleteAsync(); return(new TagsResponse(existingTags)); } catch (Exception ex) { // Do some logging stuff return(new TagsResponse($"An error occurred when updating the tags: {ex.Message}")); } }