예제 #1
0
        public ICategory Save(ICategory category)
        {
            using (var context = new NoteTakingContext(_connectionString))
            {
                context.Database.EnsureCreated();
                var mySqlCategory = _mapper.Map <MySqlCategory>(category);

                context.Category.Attach(mySqlCategory);

                foreach (var note in mySqlCategory.Notes)
                {
                    if (context.Note.Any(x => x.Id.Equals(note.Id)))
                    {
                        context.Note.Update(note);
                    }
                    else
                    {
                        context.Note.Add(note);
                    }
                }
                context.SaveChanges();

                return(category);
            }
        }
예제 #2
0
 public void Delete(Guid id)
 {
     using (var context = new NoteTakingContext(_connectionString))
     {
         context.Database.EnsureCreated();
         var toRemove = context.Category.FirstOrDefault(x => x.Id == id);
         context.Remove(toRemove);
         context.SaveChanges();
     }
 }
예제 #3
0
        public ICategory Add(ICategory category)
        {
            using (var context = new NoteTakingContext(_connectionString))
            {
                context.Database.EnsureCreated();
                var mySqlCategory = _mapper.Map <MySqlCategory>(category);
                context.Category.Add(mySqlCategory);
                context.SaveChanges();

                return(_mapper.Map <Category>(mySqlCategory));;
            }
        }