Exemplo n.º 1
0
        public void AddQuestion(Question question, IEnumerable <string> tags)
        {
            using var ctx = new PeopleCarsContext(_connectionString);
            ctx.Questions.Add(question);
            ctx.SaveChanges();
            foreach (string tag in tags)
            {
                Tag t = GetTag(tag);
                int tagId;
                if (t == null)
                {
                    tagId = AddTag(tag);
                }
                else
                {
                    tagId = t.Id;
                }
                ctx.QuestionsTags.Add(new QuestionsTags
                {
                    QuestionId = question.Id,
                    TagId      = tagId
                });
            }

            ctx.SaveChanges();
        }
Exemplo n.º 2
0
 public void AddCar(Car car)
 {
     using (var context = new PeopleCarsContext(_connectionString))
     {
         context.Cars.Add(car);
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
        private int AddTag(string name)
        {
            using var ctx = new PeopleCarsContext(_connectionString);
            var tag = new Tag {
                Name = name
            };

            ctx.Tags.Add(tag);
            ctx.SaveChanges();
            return(tag.Id);
        }
Exemplo n.º 4
0
 public void AddPerson(Person person)
 {
     using var context = new PeopleCarsContext(_connectionString);
     context.People.Add(person);
     context.SaveChanges();
 }