// 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);
            }
        }
示例#2
0
        public void AddTestData()
        {
            Publisher trondheimPublisher = new Publisher
            {
                Id   = 100,
                Name = "Trondheim kommune"
            };
            Publisher bodoPublisher = new Publisher
            {
                Id   = 101,
                Name = "Bodø kommune"
            };

            AddRange(trondheimPublisher, bodoPublisher);

            User trondheimUser = new User
            {
                Id          = 100,
                Username    = "******",
                PublisherId = 100
            };
            User bodoUser = new User
            {
                Id          = 101,
                Username    = "******",
                PublisherId = 101
            };

            AddRange(trondheimUser, bodoUser);

            Category landskap = new Category
            {
                Id   = 100,
                Name = "Landskap"
            };
            Category kultur = new Category
            {
                Id   = 101,
                Name = "Kultur"
            };
            Category theater = new Category
            {
                Id        = 102,
                BroaderId = 101,
                Name      = "Theater"
            };

            AddRange(landskap, kultur, theater);

            Dataset strandTrondheim = new Dataset
            {
                Id                = 100,
                Title             = "Strand",
                Identifier        = "/api/datasets/100",
                Description       = "Strender i Trondheim",
                DateLastUpdated   = System.DateTime.Parse("2019-07-04"),
                DatePublished     = System.DateTime.Parse("2019-07-04"),
                PublicationStatus = EPublicationStatus.published,
                AccessLevel       = EAccessLevel.green,
                PublisherId       = 100,
                CategoryId        = 100,
                InterestCounter   = 0
            }; // Id set manually due to in-memory provider
            Dataset strandBodo = new Dataset
            {
                Id                   = 101,
                Title                = "Strand",
                Identifier           = "/api/datasets/101",
                Description          = "Strender i Bodø",
                DateLastUpdated      = System.DateTime.Parse("2020-11-24"),
                DatePublished        = System.DateTime.Parse("2020-11-24"),
                PublicationStatus    = EPublicationStatus.plannedPublished,
                DatePlannedPublished = System.DateTime.Parse("2020-10-15"),
                AccessLevel          = EAccessLevel.yellow,
                PublisherId          = 101,
                CategoryId           = 100,
                InterestCounter      = 0
            };

            AddRange(strandTrondheim, strandBodo);

            Distribution jsonDist = new Distribution
            {
                Id         = 100,
                Title      = "URL til json fil",
                DatasetId  = 100,
                Uri        = "http://www.opendata.no/files/100.json",
                FileFormat = EFileFormat.json
            };
            Distribution xmlDist = new Distribution
            {
                Id         = 101,
                Title      = "URL til xml fil",
                DatasetId  = 101,
                Uri        = "http://www.opendata.no/files/101.xml",
                FileFormat = EFileFormat.xml
            };

            AddRange(jsonDist, xmlDist);

            Tags cultureTag = new Tags
            {
                Id   = 100,
                Name = "Culture"
            };
            Tags bicycleTag = new Tags
            {
                Id   = 101,
                Name = "Bicycle"
            };

            AddRange(cultureTag, bicycleTag);

            DatasetTags cultureDataTag = new DatasetTags
            {
                DatasetId = 100,
                TagsId    = 100
            };
            DatasetTags bicycleDataTag = new DatasetTags
            {
                DatasetId = 101,
                TagsId    = 101
            };

            AddRange(cultureDataTag, bicycleDataTag);

            CoordinationTags cultureCoordTag = new CoordinationTags
            {
                CoordinationId = 100,
                TagsId         = 100
            };
            CoordinationTags bicycleCoordTag = new CoordinationTags
            {
                CoordinationId = 101,
                TagsId         = 101
            };

            AddRange(cultureCoordTag, bicycleCoordTag);

            Coordination bicycleCoordination = new Coordination
            {
                Id              = 100,
                Title           = "Bicycle coordination",
                Description     = "Dette er en samordning av datasett om strender",
                PublisherId     = 101,
                CategoryId      = 101,
                DateLastUpdated = DateTime.Now,
                DatePublished   = DateTime.Now,
                AccessLevel     = EAccessLevel.green
            };

            Coordination beachCoordination = new Coordination
            {
                Id              = 101,
                Title           = "Strand samordning",
                Description     = "Dette er en samordning av datasett om strender",
                PublisherId     = 100,
                CategoryId      = 101,
                DateLastUpdated = DateTime.Now,
                DatePublished   = DateTime.Now,
                AccessLevel     = EAccessLevel.yellow
            };

            AddRange(bicycleCoordination, beachCoordination);

            Subscription sub1 = new Subscription
            {
                Id        = 100,
                DatasetId = 100,
                UserId    = 100,
            };
            Subscription sub2 = new Subscription
            {
                Id        = 101,
                DatasetId = 101,
                UserId    = 101
            };
            Subscription sub3 = new Subscription
            {
                Id             = 102,
                CoordinationId = 101,
                UserId         = 101
            };

            AddRange(sub1, sub2, sub3);

            Notification not1 = new Notification
            {
                Id             = 100,
                DatasetId      = 100,
                UserId         = 100,
                Title          = "Strand - Trondheim kommune",
                Description    = "Datasett 'Strand' har blitt oppdatert.",
                TimeOfCreation = DateTime.Now
            };
            Notification not2 = new Notification
            {
                Id             = 101,
                DatasetId      = 101,
                UserId         = 100,
                Title          = "Sykkel - Bodø kommune",
                Description    = "Datasett 'Sykkel' har blitt oppdatert.",
                TimeOfCreation = DateTime.Now
            };

            AddRange(not1, not2);

            Application app = new Application
            {
                Id             = 100,
                DatasetId      = 100,
                CoordinationId = 100,
                Reason         = "Kan vi verme?"
            };

            AddRange(app);

            SaveChanges();
        }
示例#3
0
 public void Remove(CoordinationTags tags)
 {
     _context.CoordinationTags.Remove(tags);
 }