public Note CreateNote(Note createdNote) { var note = db.Add(createdNote); db.SaveChanges(); return(note.Entity); }
public ActionResult Create(Note note) { int userId = Convert.ToInt32(Session["userid"]); note.Title = Request.Form["title"]; note.Detail = Request.Form["detail"]; note.Posted_by = userId; note.Trash = "false"; var notes = db.Notes.Where(x => x.Posted_by == userId).ToList(); var finalNotes = notes.Where(f => f.Trash == "false").ToList(); if (note.Title == "") { ViewBag.TitleError = "Title is required"; return(View("Index", notes)); } else if (note.Detail == "") { ViewBag.DetailError = "Note is required"; return(View("Index", notes)); } else { db.Notes.Add(note); db.SaveChanges(); return(RedirectToAction("Index", notes)); } }
public IHttpActionResult PutNote(int id, Note note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != note.Id) { return(BadRequest()); } db.Entry(note).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!NoteExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ResponseUserAccount RegisterUser(RegisterUserAccount user) { if (!UserDB.UserAccounts.Any(u => u.Email == user.Email)) { user.Password = passwordEncryption.EncryptPassword(user.Password); UserDB.UserAccounts.Add( new UserAccount { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Password = user.Password }); UserDB.SaveChanges(); return(UserDB.UserAccounts.Where(u => u.Email.Equals(user.Email)).Select(u => new ResponseUserAccount { UserID = u.UserId, FirstName = u.FirstName, LastName = u.LastName, Email = u.Email }).ToList().First()); } else { throw new UserAccountException(UserAccountException.ExceptionType.EMAIL_ALREADY_EXIST, "email id already registered"); } }
public void Insert(int idUser, NoteModel item) { item.UserId = idUser; item.Create = DateTime.Now; _db.NoteModels.Add(item); _db.SaveChanges(); }
public Note Add(Note note) { var entry = context.Add(note); context.SaveChanges(); return(entry.Entity); }
public void EditNote(int id, NoteWithCategories newNote) { var oldNote = _context.Notes.Where(n => n.NoteID == id && n.Timestamp == newNote.Timestamp).FirstOrDefault(); if (oldNote == null) { throw new Exception("The file does not exist or has been changed"); } // Find differences in standard fields and replace if needed if (oldNote.Title != newNote.Title || oldNote.Description != newNote.Description || oldNote.NoteDate != newNote.NoteDate || oldNote.IsMarkdown != newNote.IsMarkdown) { oldNote.Title = newNote.Title; oldNote.Description = newNote.Description; oldNote.NoteDate = newNote.NoteDate; oldNote.IsMarkdown = newNote.IsMarkdown; } // Find differences in categories var categoriesInDb = _context.NoteCategories .Where(nc => nc.Note == oldNote) .Include(nc => nc.Category); var newCategories = newNote.Categories .Except(categoriesInDb.Select(c => c.Category.Title)); foreach (var newCategory in newCategories) { var categoryInDb = _context.Categories .Where(c => c.Title == newCategory) .FirstOrDefault(); if (categoryInDb == null) { categoryInDb = new Category { Title = newCategory }; } _context.Add(new NoteCategory { Note = oldNote, Category = categoryInDb }); } var deletedCategories = categoriesInDb .Where(c => !newNote.Categories.Contains(c.Category.Title)); _context.RemoveRange(deletedCategories); _context.SaveChanges(); }
public void Insert(NoteModel newNote) { if (newNote == null) { throw new ArgumentNullException(nameof(newNote)); } _notesContext.Notes.Add(newNote); _notesContext.SaveChanges(); }
public ActionResult Create([Bind(Include = "ID,DueDate,DueTime,HomeworkTitle,Priority,Department,CourseNumber,Notes")] HWnotes hWnotes) { if (ModelState.IsValid) { db.Notes.Add(hWnotes); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hWnotes)); }
public ActionResult Create([Bind(Include = "ID,Title,Text,Now")] Notes notes) { if (ModelState.IsValid) { db.Notes.Add(notes); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(notes)); }
public ActionResult Create([Bind(Include = "FeaturedJamID,Title,Author,DatePublished,Content")] FeaturedJam featuredJam) { if (ModelState.IsValid) { db.FeaturedJams.Add(featuredJam); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(featuredJam)); }
public ActionResult Create([Bind(Include = "ID,Category")] Group group) { if (ModelState.IsValid) { db.Category.Add(group); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(group)); }
public ActionResult Create([Bind(Include = "NoteId,NoteBody")] Note note) { if (ModelState.IsValid) { db.Notes.Add(note); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(note)); }
public ActionResult Create([Bind(Include = "noteId,fullname,telephone")] Note note) { if (ModelState.IsValid) { db.notes.Add(note); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(note)); }
public IActionResult Post([FromBody] User item) { if (item == null) { return(BadRequest()); } _context.User.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetUser", new { id = item.Id }, item)); }
public void Add(UserProfile user) { try { db.UserProfiles.Add(user); db.SaveChanges(); } catch (Exception ex) { throw ex; } }
public void Add(Note note) { try { db.Notes.Add(note); db.SaveChanges(); } catch (Exception ex) { throw ex; } }
public IActionResult Create([Bind("ID,Title,Content,FinishDate,Finished,Importance")] Note note) { if (ModelState.IsValid) { if (note.Finished) { note.FinishedDate = DateTime.Now; } _context.Add(note); _context.SaveChanges(); return(RedirectToAction("Index")); } return(BadRequest()); }
private void NewCommand_Executed(object sender, ExecutedRoutedEventArgs e) { var item = treeView.SelectedItem; if (item is DataAccess.Table) { var popup = new NewStack(((DataAccess.Table)item).TableID); Stack stack; if (popup.ShowDialog().GetValueOrDefault()) { stack = popup.Stack; } else { return; } using (var db = new NotesContext()) { db.Stacks.Add(stack); db.SaveChanges(); } treeView.Items.Refresh(); treeView.UpdateLayout(); } }
private string GenerateData(int count) { var context = new NotesContext(App.StoreConnectionString); var categories = new List <ICategory>(); var rng = new Random(); for (int i = 0; i < count / 10; i++) { var category = context.Categories.Create(); category.Label = String.Format("Generated Category #{0}", i + 1); categories.Add(category); } int catCount = categories.Count; for (int i = 0; i < count; i++) { var category = categories[rng.Next(catCount)]; var note = context.Notes.Create(); note.Category = category; note.Label = "Note " + DateTime.Now.Ticks; note.Content = "Lorem ipsum etc etc etc."; } context.SaveChanges(); return(categories[rng.Next(count / 10)].CategoryId); }
public ActionResult Create([Bind(Include = "Band,Song,ShowDate,Description,Link")] SingleUserViewModel userVm) { if (ModelState.IsValid) { var band = (from b in db.Bands where b.Name == userVm.Band select b).FirstOrDefault <Band>(); var song = (from s in db.Songs where s.Title == userVm.Song select s).FirstOrDefault <Song>(); var user = (from u in db.Users where u.UserID == 1 // eventually, UserId will be passed in as a parameter select u).FirstOrDefault <User>(); Note note = new Note(); note.UserID = user.UserID; note.BandID = band.BandID; note.SongID = song.SongID; note.ShowDate = userVm.ShowDate; note.Description = userVm.Description; note.Link = userVm.Link; db.Notes.Add(note); db.SaveChanges(); return(RedirectToAction("MyNotes")); } return(View(userVm)); }
public IActionResult Create(Notes item) { _context.Notes.Add(item); _context.SaveChanges(); return(CreatedAtRoute("Notes", new { id = item.ID }, item)); }
public void DeleteTodo(ToDo toDo) { using (var dbContext = new NotesContext()) { dbContext.Remove(toDo); dbContext.SaveChanges(); } }
public void Add(Notes notes) { using (notesContext = new NotesContext()) { notesContext.Notes.Add(notes); notesContext.SaveChanges(); } }
public static void SaveNote(Note note) { using (var context = new NotesContext()) { context.Entry(note).State = EntityState.Modified; context.SaveChanges(); } }
public static void AddUser(User user) { using (var context = new NotesContext()) { context.Users.Add(user); context.SaveChanges(); } }
public void DeleteNote(Note note) { using (var dbContext = new NotesContext()) { dbContext.Remove(note); dbContext.SaveChanges(); } }
public ActionResult Create(Note note) { var notes = db.Notes.ToList(); if (ModelState.IsValid) { note.Title = Request.Form["title"]; note.Detail = Request.Form["detail"]; int sessionId = Convert.ToInt32(Session["userid"]); note.User_id = sessionId; db.Notes.Add(note); db.SaveChanges(); return(RedirectToAction("Index", notes)); } else { return(View("Index", notes)); } }
public static void DeleteNote(Note selectedNote) { using (var context = new NotesContext()) { selectedNote.DeleteDatabaseValues(); context.Notes.Attach(selectedNote); context.Notes.Remove(selectedNote); context.SaveChanges(); } }
public ActionResult DeleteNote(int id, string a) { using (NotesContext context = new NotesContext()) { Notes note = context.Notes.Where(x => x.Id == id).FirstOrDefault(); context.Notes.Remove(note); context.SaveChanges(); } return(RedirectToAction("Notes")); }