Beispiel #1
0
        public ActionResult CreateNote(Note note)
        {
            _context.Notes.Add(note);
            _context.SaveChanges();

            return(CreatedAtRoute(nameof(GetNote), new { Id = note.Id }, note));
        }
        public Note Add(Note note)
        {
            _context.Notes.Add(note);
            _context.SaveChanges(); // If we are making changes in the Database we need to save those changes

            return(note);
        }
Beispiel #3
0
        public User Add(User user)
        {
            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }
Beispiel #4
0
        public int AddNote(NoteFormModel model)
        {
            var note = CreateNote(model);

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

            return(note.Id);
        }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "Id,Name,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Beispiel #6
0
        public void CreateNote(NoteDTO obj)
        {
            Note CreateNote = new Note();

            CreateNote.Title      = obj.Title;
            CreateNote.Body       = obj.Body;
            CreateNote.CreateDate = obj.CreateDate;
            CreateNote.UpdateDate = obj.UpdateDate;

            _db.Entry(CreateNote).State = Microsoft.EntityFrameworkCore.EntityState.Added;
            _db.SaveChanges();
        }
Beispiel #7
0
 public bool CreateUser(User user)
 {
     if (!IsUserExists(user.Username))
     {
         authDb.Add(user);
         int ret = authDb.SaveChanges();
         return(ret > 0 ? true : false);
     }
     else
     {
         throw new Exception("User Name already exists");
     }
 }
Beispiel #8
0
 public bool AddNote(tbl_Notes model)
 {
     try
     {
         model.CreateDate = DateTime.Now;
         db.tbl_Notes.Add(model);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
        public void RestoreTestData()
        {
            foreach (var note in _db.Notes)
            {
                _db.Entry(note).State = EntityState.Deleted;
            }

            _db.Notes.Add(new Note
            {
                Title       = "Yeah it's called a shrug..",
                Description = @"¯\_(ツ)_/¯",
                Importance  = 2,
                CreatedAt   = DateTime.Now
            });

            _db.Notes.Add(new Note
            {
                Title       = "Important Note",
                Description = "This one is a very important note:\nDON'T DELETE ME",
                Importance  = 4,
                CreatedAt   = DateTime.Now.AddDays(-2).AddHours(-1)
            });

            _db.Notes.Add(new Note
            {
                Title       = "Finished Note",
                Description = "An already finished note! Wooh",
                Importance  = 3,
                CreatedAt   = DateTime.Now.AddHours(-20),
                FinishedAt  = DateTime.Now.AddHours(-2)
            });

            _db.SaveChanges();
        }
Beispiel #10
0
        public static void RenameNote(string user_id, string noteoldname, string notenewname)
        {
            NoteDbContext db   = new NoteDbContext();
            var           note = db.Notes.First(x => x.UserId == user_id && x.NoteName == noteoldname);

            note.NoteName = notenewname;
            db.SaveChanges();
        }
Beispiel #11
0
        /// <summary>
        /// Get tag by tag name.
        /// </summary>
        /// <param name="tagname"></param>
        /// <returns></returns>
        public Tag GetTagByName(string tagname)
        {
            var tag = _context.Tags.AsTracking().FirstOrDefault(x => x.Name.ToLower() == tagname.ToLower());

            if (tag == null)
            {
                var insertedTag = _context.Tags.Add(new Tag()
                {
                    Name = tagname.ToLower()
                });

                _context.SaveChanges();
                return(insertedTag.Entity);
            }

            return(tag);
        }
Beispiel #12
0
        public static void EditNote(string user_id, string name, string oldtext, string newtext)
        {
            NoteDbContext db   = new NoteDbContext();
            var           note = db.Notes.First(x => x.UserId == user_id && x.NoteName == name && x.NoteText == oldtext);

            note.NoteText = newtext;
            db.SaveChanges();
        }
Beispiel #13
0
        public static void CreateNote(string user_id, string notename, string notetext)
        {
            NoteDbContext db = new NoteDbContext();

            db.Notes.Add(new NoteModel {
                UserId = user_id, NoteName = notename, NoteText = notetext
            });
            db.SaveChanges();
        }
Beispiel #14
0
        private void confirm(object sender, EventArgs e)
        {
            Catagory_info info = new Catagory_info();

            info.Catagory_Nama = txt_title.Text;

            NoteDbContext context = new NoteDbContext();

            context.Catagory.Add(info);
            context.SaveChanges();
        }
Beispiel #15
0
        public static void DeleteAll(string user_id)
        {
            NoteDbContext db   = new NoteDbContext();
            var           note = db.Notes.Where(x => x.UserId == user_id).ToArray();

            if (note != null)
            {
                db.Notes.RemoveRange(note);
            }
            db.SaveChanges();
        }
Beispiel #16
0
        public static void DeleteNote(string id, string notename)
        {
            NoteDbContext db   = new NoteDbContext();
            var           note = db.Notes.First(x => x.UserId == id && x.NoteName == notename);

            if (note != null)
            {
                db.Notes.Remove(note);
            }
            db.SaveChanges();
        }
 public Task DeleteAsync(int id)
 {
     return(Task.Run(() =>
     {
         Note note = _NoteContext.Notes.Find(id);
         if (note != null)
         {
             _NoteContext.Notes.Remove(note);
             _NoteContext.SaveChanges();
         }
     }));
 }
Beispiel #18
0
        public ActionResult Create(string Title, string Text, int Category)
        {
            NoteDbContext notesdb = new NoteDbContext();
            Note          silence = new Note();

            silence.Title    = Title;
            silence.Text     = Text;
            silence.Category = notesdb.Categories.Find(Category);
            notesdb.Notes.Add(silence);
            notesdb.SaveChanges();

            return(View());
        }
Beispiel #19
0
        public IActionResult <AllUsernamesViewModel> Register(RegisterUserBindingModel registerUserBinding)
        {
            var user = new User
            {
                Username = registerUserBinding.Username,
                Password = registerUserBinding.Password
            };

            using (var context = new NoteDbContext())
            {
                context.Users.Add(user);
                context.SaveChanges();
            }

            return(this.All());
        }
Beispiel #20
0
        public IActionResult <UserProfileModel> Profile(int id, NoteViewModel model)
        {
            using (var db = new NoteDbContext())
            {
                var note = new Note
                {
                    Title   = model.Title,
                    Content = model.Content,
                    UserId  = id
                };

                db.Notes.Add(note);
                db.SaveChanges();
            }


            return(this.Profile(id));
        }
 public void Add(UserDTO entity)
 {
     _db.Users.Add(entity);
     _db.SaveChanges();
 }
 private void AddTestData(params Note[] notes)
 {
     _dbContext.Notes.AddRange(notes);
     _dbContext.SaveChanges();
 }
Beispiel #23
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
 public void Add(NoteDTO entity)
 {
     _db.Notes.Add(entity);
     _db.SaveChanges();
 }