Exemplo n.º 1
0
 public Notes GetNote(int noteId)
 {
     using (var context = new MiniCMSEntities())
     {
         return GetNoteInternal(noteId, context);
     }
 }
Exemplo n.º 2
0
 public int GetNotesCount()
 {
     using (var context = new MiniCMSEntities())
     {
         return context.Notes.Count();
     }
 }
Exemplo n.º 3
0
        private static Notes GetNoteInternal(int noteId, MiniCMSEntities context)
        {
            var note = context.Notes.FirstOrDefault(x => x.Id == noteId);
            if (note != null)
                return note;

            throw new InvalidOperationException("Note with this id does not exist");
        }
Exemplo n.º 4
0
 public void DeleteNote(int noteId)
 {
     using (var context = new MiniCMSEntities())
     {
         var note = GetNoteInternal(noteId, context);
         context.Notes.Remove(note);
         context.SaveChanges();
     }
 }
Exemplo n.º 5
0
        public IList<Notes> GetNotes(int currentPage)
        {
            using (var context = new MiniCMSEntities())
            {
                var skip = (currentPage - 1) * PageSize; 

                return context.Notes.OrderByDescending(x => x.Id).Skip(skip).Take(10).ToList();
            }
        }
Exemplo n.º 6
0
        public int AddNote(Notes note)
        {
            using (var context = new MiniCMSEntities())
            {
                if (IsExistName(note.Name, context))
                    throw new InvalidOperationException("This name is already used");

                context.Notes.Add(note);
                context.SaveChanges();

                return note.Id;
            }
        }
Exemplo n.º 7
0
        public void ChangeNote(int noteId, string noteName, string htmlContent, string shortNote)
        {
            using (var context = new MiniCMSEntities())
            {
                var note = GetNoteInternal(noteId, context);

                if (note.Name != noteName)
                {
                    if (IsExistName(noteName, context))
                        throw new InvalidOperationException("This name is already used");
                }

                note.Name = noteName;
                note.HTML = htmlContent;
                note.ShortNote = shortNote;

                context.SaveChanges();
            }
        }
Exemplo n.º 8
0
 bool IsExistName(string name, MiniCMSEntities context)
 {
     return context.Notes.Count(x => x.Name == name) > 0;
 }