Exemple #1
0
        public bool DeleteNote(int noteId)
        {
            using (var ctx = new ElevenNoteDbContext())
            {
                var entity =
                    ctx
                    .Notes
                    .SingleOrDefault(e => e.OwnerId == _userId && e.NoteId == noteId);

                // TODO: Handle note not found

                ctx.Notes.Remove(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
        public bool DeleteNote(int noteId)
        {
            using (var ctx = new ElevenNoteDbContext())
            {
                var entity = GetNoteFromDatabase(ctx, noteId);

                if (entity == null)
                {
                    return(false);
                }

                ctx.Notes.Remove(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
        public bool UpdateProfile(ProfileViewModel vm)
        {
            using (var ctx = new ElevenNoteDbContext())
            {
                var entity =
                    ctx
                    .Profiles
                    .SingleOrDefault(e => e.Email == vm.Email);

                entity.FirstName   = vm.FirstName;
                entity.LastName    = vm.LastName;
                entity.Address     = vm.Address;
                entity.PhoneNumber = vm.PhoneNumber;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemple #4
0
        public bool CreateNote(NoteCreateViewModel vm)
        {
            using (var ctx = new ElevenNoteDbContext())
            {
                var entity =
                    new NoteEntity
                {
                    OwnerId    = _userId,
                    Title      = vm.Title,
                    Content    = vm.Content,
                    CreatedUtc = DateTimeOffset.UtcNow
                };

                ctx.Notes.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
        public ProfileEntity UpdateEmail()
        {
            ProfileEntity entity;

            using (var ctx = new ElevenNoteDbContext())
            {
                entity =
                    new ProfileEntity
                {
                    Email = _email
                };

                ctx.Profiles.Add(entity);
                ctx.SaveChanges();
            }

            return(entity);
        }
Exemple #6
0
        public bool UpdateNote(NoteEditViewModel vm)
        {
            using (var ctx = new ElevenNoteDbContext())
            {
                var entity =
                    ctx
                    .Notes
                    .SingleOrDefault(e => e.OwnerId == _userId && e.NoteId == vm.NoteId);

                // TODO: Handle note not found

                entity.Title       = vm.Title;
                entity.Content     = vm.Content;
                entity.IsStarred   = vm.IsStarred;
                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
        public bool UpdateNote(NoteEditModel model)
        {
            using (var ctx = new ElevenNoteDbContext())
            {
                var entity = GetNoteFromDatabase(ctx, model.NoteId);

                if (entity == null)
                {
                    return(false);
                }

                entity.Title       = model.Title;
                entity.Content     = model.Content;
                entity.ModifiedUtc = DateTime.UtcNow;
                entity.IsStarred   = model.IsStarred;

                return(ctx.SaveChanges() == 1);
            }
        }
        public bool Delete(int id, Guid userId)
        {
            using (var ctx = new ElevenNoteDbContext())
            {
                var note =
                    ctx
                        .Notes
                        .Where(
                            n => n.Id == id
                                 && n.ApplicationUserId == userId)
                        .SingleOrDefault();

                if (note == null) return false;

                ctx.Notes.Remove(note);

                return ctx.SaveChanges() == 1;
            }
        }
        public bool Create(NoteDetailViewModel vm, Guid userId)
        {
            using (var ctx = new ElevenNoteDbContext())
            {
                var note =
                    new Note
                    {
                        Title = vm.Title,
                        Contents = vm.Contents,
                        DateCreated = DateTime.UtcNow,
                        ApplicationUserId = userId,
                        IsFavorite = vm.IsFavorite
                    };

                ctx.Notes.Add(note);

                return ctx.SaveChanges() == 1;
            }
        }
Exemple #10
0
        public bool CreateNote(NoteCreateViewModel vm)
        {
            using (var context = new ElevenNoteDbContext())
            {
                var entity =
                    new NoteEntity
                {
                    OwnerId    = _userId,
                    Title      = vm.Title,
                    Content    = vm.Content,
                    CreatedUtc = DateTime.UtcNow
                };

                context.Notes.Add(entity);

                //  return true if exactly one item added to the database
                //  else, returns false
                return(context.SaveChanges() == 1);
            }
        }
Exemple #11
0
        public bool UpdateNote(NoteEditViewModel model)
        {
            using (var context = new ElevenNoteDbContext())
            {
                var entity = context
                             .Notes
                             .SingleOrDefault(e => e.NoteId == model.NoteId && e.OwnerId == _userId);

                if (entity == null)
                {
                    return(false);
                }

                entity.Title       = model.Title;
                entity.Content     = model.Content;
                entity.ModifiedUtc = DateTimeOffset.Now;
                entity.IsStarred   = model.IsStarred;

                return(context.SaveChanges() == 1);
            }
        }
        public bool Update(NoteDetailViewModel vm, Guid userId)
        {
            using (var ctx = new ElevenNoteDbContext())
            {
                var note =
                    ctx
                        .Notes
                        .Where(
                            n => n.Id == vm.Id
                                 && n.ApplicationUserId == userId)
                        .SingleOrDefault();

                if (note == null) return false;

                note.Contents = vm.Contents;
                note.Title = vm.Title;
                note.IsFavorite = vm.IsFavorite;
                note.DateModified = DateTime.UtcNow;

                return ctx.SaveChanges() == 1;
            }
        }