Example #1
0
        public static Note Create(Note note)
        {
            note.CreationDate = DateTime.Now;
            note.EditionDate  = DateTime.Now;

            using (MemoTestContext ctx = new MemoTestContext(GetConnectionString()))
            {
                ctx.Notes.Add(note);
                ctx.SaveChanges();
            }
            return(note);
        }
Example #2
0
        public static Note Update(Note note)
        {
            using (MemoTestContext ctx = new MemoTestContext(GetConnectionString()))
            {
                var result = ctx.Notes.FirstOrDefault(n => n.Id == note.Id);
                if (result != null)
                {
                    result.Name        = note.Name;
                    result.Data        = note.Data;
                    result.IsMarked    = note.IsMarked;
                    result.EditionDate = DateTime.Now;
                    ctx.SaveChanges();
                }

                return(result);
            }
        }
Example #3
0
        public static void Delete(int id)
        {
            using (MemoTestContext ctx = new MemoTestContext(GetConnectionString()))
            {
                Note note = new Note()
                {
                    Id = id
                };
                ctx.Notes.Attach(note);
                ctx.Notes.Remove(note);
                ctx.SaveChanges();


                //var result = ctx.Notes.FirstOrDefault(n => n.Id == id);
                //if (result != null)
                //{
                //    ctx.Notes.Remove(result);
                //    ctx.SaveChanges();
                //}
            }
        }