public bool UpdateNote(NoteEdit model) { var entity = _ctx .Notes .Single(e => e.NoteId == model.NoteId && e.OwnerId == _userId); entity.Title = model.Title; entity.Content = model.Content; entity.ModifiedUtc = DateTimeOffset.UtcNow; entity.IsStarred = model.IsStarred; return(_ctx.SaveChanges() == 1); }
public IHttpActionResult Put(NoteEdit note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateNoteService(); if (!service.UpdateNote(note)) { return(InternalServerError()); } return(Ok()); }
public async Task <IActionResult> UpdateNote([FromRoute] int noteId, [FromBody] NoteEdit updatedNote) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!await _service.UpdateNoteAsync(noteId, updatedNote)) { return(StatusCode(StatusCodes.Status500InternalServerError)); } return(Ok()); }
public bool UpdateNote(NoteEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Notes.Single(e => e.NoteId == model.NoteId && e.OwnerId == _userId); entity.Title = model.Title; entity.Content = model.Content; entity.ModifiedUtc = DateTimeOffset.Now; entity.IsStarred = model.IsStarred; return(ctx.SaveChanges() == 1); } }
public Note Save(NoteEdit editInput, string username) { User user = null; Note dbNote = null; this.CheckSaveForAuthorization(ref user, ref dbNote, username, editInput.Id); this.utilService.UpdatePropertiesReflection(editInput, dbNote, new string[] { "Lines", "Id", "Name", "Description" }); this.UpdateExistingNotes(dbNote, editInput); this.DeleteRemovedLines(editInput, dbNote); this.SaveNewLines(editInput); context.SaveChanges(); return(dbNote); }
public ActionResult Edit(int id) { var service = CreateNoteService(); var detail = service.GetNoteById(id); var model = new NoteEdit { NoteId = detail.NoteId, Title = detail.Title, Content = detail.Content }; return(View(model)); }
public void DeleteRemovedLines(NoteEdit editInput, Note dbNote) { var currentDbIds = dbNote.Lines.Select(x => x.Id).ToArray(); var currentPageIds = editInput.Lines.Where(x => x.Id > 0).Select(x => x.Id).ToArray(); var removedIds = currentDbIds.Where(x => !currentPageIds.Contains(x)); var codeLinesToRemove = dbNote.Lines.Where(x => removedIds.Contains(x.Id)); var now = DateTime.UtcNow; foreach (var item in codeLinesToRemove) { item.DeletedOn = now; item.IsDeleted = true; } }
public bool UpdateNote(NoteEdit model, int id) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Notes .Single(e => e.NoteId == id && e.UserRecipe.UserId == _userId.ToString()); entity.Text = model.Text; return(ctx.SaveChanges() == 1); } }
public void SetupScintilla(AppSettings s) { var theme = ThemeManager.Inst.CurrentTheme; NoteEdit.Lexer = Lexer.Container; NoteEdit.CaretForeColor = theme.Get <ColorRef>("scintilla.caret:foreground").ToDCol(); NoteEdit.CaretLineBackColor = theme.Get <ColorRef>("scintilla.caret:background").ToDCol(); NoteEdit.CaretLineBackColorAlpha = theme.Get <int>("scintilla.caret:background_alpha"); NoteEdit.CaretLineVisible = theme.Get <bool>("scintilla.caret:visible"); NoteEdit.WhitespaceSize = theme.Get <int>("scintilla.whitespace:size"); NoteEdit.ViewWhitespace = s.SciShowWhitespace ? WhitespaceMode.VisibleAlways : WhitespaceMode.Invisible; NoteEdit.SetWhitespaceForeColor(!theme.Get <ColorRef>("scintilla.whitespace:color").IsTransparent, theme.Get <ColorRef>("scintilla.whitespace:color").ToDCol()); NoteEdit.SetWhitespaceBackColor(!theme.Get <ColorRef>("scintilla.whitespace:background").IsTransparent, theme.Get <ColorRef>("scintilla.whitespace:background").ToDCol()); UpdateMargins(s); NoteEdit.BorderStyle = BorderStyle.FixedSingle; NoteEdit.Markers[ScintillaHighlighter.STYLE_MARKER_LIST_OFF].DefineRgbaImage(Properties.Resources.ui_off); NoteEdit.Markers[ScintillaHighlighter.STYLE_MARKER_LIST_ON].DefineRgbaImage(Properties.Resources.ui_on); NoteEdit.MultipleSelection = s.SciMultiSelection; NoteEdit.MouseSelectionRectangularSwitch = s.SciMultiSelection; NoteEdit.AdditionalSelectionTyping = s.SciMultiSelection; NoteEdit.VirtualSpaceOptions = s.SciMultiSelection ? VirtualSpace.RectangularSelection : VirtualSpace.None; NoteEdit.EndAtLastLine = !s.SciScrollAfterLastLine; var fnt = string.IsNullOrWhiteSpace(s.NoteFontFamily) ? FontNameToFontFamily.StrDefaultValue : s.NoteFontFamily; NoteEdit.Font = new Font(fnt, (int)s.NoteFontSize); _highlighterDefault.SetUpStyles(NoteEdit, s); NoteEdit.WrapMode = s.SciWordWrap ? WrapMode.Whitespace : WrapMode.None; NoteEdit.ZoomChanged -= ZoomChanged; NoteEdit.ZoomChanged += ZoomChanged; NoteEdit.UseTabs = s.SciUseTabs; NoteEdit.TabWidth = s.SciTabWidth * 2; NoteEdit.ReadOnly = s.IsReadOnlyMode; ResetScintillaScrollAndUndo(); ForceNewHighlighting(s); }
//GET: Note Edit public ActionResult Edit(int?id) { var service = CreateNoteService(); var model = service.GetNoteById(id); var detail = new NoteEdit { NoteId = model.NoteId, Title = model.Title, Content = model.Content, CategoryId = model.CategoryId, IsStarred = model.IsStarred }; return(View(detail)); }
public IHttpActionResult Put(NoteEdit model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var noteService = new NoteService(Guid.Parse(User.Identity.GetUserId())); var temp = noteService.GetNoteById(model.NoteId); if (temp == null) { return(NotFound()); } return(Ok(noteService.UpdateNote(model))); }
public ActionResult Edit(decimal id, NoteEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.NoteId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } return(View()); }
//public IHttpActionResult Get() //{ // NoteService postService = CreateNoteService(); // var post = postService.GetAllNotes(); // return Ok(post); //} //public IHttpActionResult Get(int id) //{ // NoteService noteService = CreateNoteService(); // var note = noteService.GetNoteById(id); // return Ok(note); //} public IHttpActionResult Put([FromUri] int id, [FromBody] NoteEdit updatedNote) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateNoteService(); if (!service.UpdateNote(updatedNote, id)) { return(InternalServerError()); } return(Ok()); }
public async Task <bool> UpdateNoteAsync(int noteId, NoteEdit updatedNote) { var originalNote = await _db.Notes.FindAsync(noteId); if (originalNote == null || originalNote.OwnerId != _userId) { return(false); } originalNote.Title = updatedNote.Title; originalNote.Content = updatedNote.Content; originalNote.ModifiedUtc = DateTimeOffset.UtcNow; return(await _db.SaveChangesAsync() == 1); }
public bool UpdateNote(NoteEdit model) { using (var dbContext = new ApplicationDbContext()) { var entity = dbContext.Notes .Single(x => x.NoteID == model.NoteID && x.OwnerID == _userID); entity.Title = model.Title; entity.Content = model.Content; entity.ModifiedUtc = DateTimeOffset.UtcNow; entity.IsStarred = model.IsStarred; return(dbContext.SaveChanges() == 1); } }
private void NoteEdit_StyleNeeded(object sender, StyleNeededEventArgs e) { bool listHighlight = (Settings.ListMode == ListHighlightMode.Always) || (Settings.ListMode == ListHighlightMode.WithTag && _viewmodel?.SelectedNote?.HasTagCaseInsensitive(AppSettings.TAG_LIST) == true); var startPos = NoteEdit.GetEndStyled(); var endPos = e.Position; GetHighlighter(Settings).Highlight(NoteEdit, startPos, endPos, Settings); if (listHighlight) { GetHighlighter(Settings).UpdateListMargin(NoteEdit, startPos, endPos); } }
public async Task <bool> Update(NoteEdit note) { var noteToUpdate = await GetById(note.NoteId); if (noteToUpdate == null) { return(false); } noteToUpdate.Title = note.Title; noteToUpdate.Content = note.Content; noteToUpdate.ModifiedUtc = DateTimeOffset.UtcNow; return(true); }
public ActionResult Edit(int id) { var service = CreateNoteService(); var detail = service.GetNoteById(id); var model = new NoteEdit { NoteId = detail.NoteId, Title = detail.Title, Content = detail.Content }; ViewBag.Category = new SelectList(CreateNoteService().GetDb().Categories.ToList(), "CategoryId", "Name", detail.CategoryRefId); return(View(model)); }
public bool UpdateNote(NoteEdit model) // returns a bool based on if the NoteId is in the database and the note belongs to the specific _userId { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Notes .Single(e => e.NoteId == model.NoteId && e.OwnerId == _userId); entity.Title = model.Title; entity.Content = model.Content; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
//GET: Notes/Edit/{id} public ActionResult Edit(int id) { var service = CreateNoteService(); var detail = service.GetNoteById(id); var model = new NoteEdit { NoteId = detail.NoteId, Title = detail.Title, Content = detail.Content }; var svc = new CategoryService(); ViewBag.CategoryId = new SelectList(svc.GetCategories(), "CategoryId", "CategoryName", detail.Category); return(View(model)); }
// UPDATE public bool UpdateNote(NoteEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Notes .Single(e => e.NoteId == model.NoteId && e.UserId == _userId.ToString()); entity.NoteTitle = model.NoteTitle; entity.NoteText = model.NoteText; entity.ModifiedUtc = DateTimeOffset.Now; return(ctx.SaveChanges() == 1); } }
//This is a bool because we want to know if it updated properly or not. public bool UpdateNote(NoteEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Notes .Single(e => e.NoteId == model.NoteId); entity.Title = model.Title; entity.Content = model.Content; entity.ModifiedUtc = DateTimeOffset.UtcNow; //remember that this tells us how many rows are updated return(ctx.SaveChanges() == 1); } }
private bool SetStarState(int noteId, bool newState) { _service = new Lazy <INoteService>(CreateNoteService); var detail = _service.Value.GetNoteById(noteId); var updatedNote = new NoteEdit { NoteId = detail.NoteId, Title = detail.Title, Content = detail.Content, IsStarred = newState }; return(_service.Value.UpdateNote(updatedNote)); }
//update public IHttpActionResult Put(NoteEdit note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); //400 } NoteService service = CreateNoteService(); if (!service.UpdateNote(note)) { //Update note returns a bool, this runs if false return(InternalServerError()); } return(Ok()); }
private bool SetStarState(int noteId, bool newState) { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new NoteService(userId); var detail = service.GetNoteById(noteId); var updatedNote = new NoteEdit { NoteId = detail.NoteId, Title = detail.Title, Content = detail.Content, IsStarred = newState }; return(service.UpdateNote(updatedNote)); }
public bool UpdateNote(NoteEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Notes.Single(e => e.Id == model.Id); entity.Id = model.Id; entity.NoteTitle = model.NoteTitle; entity.NoteDate = model.NoteDate; entity.NoteContent = model.NoteContent; entity.TypeOfNote = model.TypeOfNote; entity.HiveId = model.HiveId; entity.QueenId = model.QueenId; entity.LocationId = model.LocationId; return(ctx.SaveChanges() == 1); } }
public bool ToggleStar(int id) { var service = CreateNoteService(); var detail = service.GetNoteById(id); var updatedNote = new NoteEdit { NoteId = detail.NoteId, Title = detail.Title, Content = detail.Content, IsStarred = !detail.IsStarred }; return(service.UpdateNote(updatedNote)); }
public IHttpActionResult Put(NoteEdit note) { //if the user inputted model is not valid if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateNoteService(); //if the DbContext did not save the changes we made for some reason if (!service.UpdateNote(note)) { return(InternalServerError()); } //good :) return(Ok()); }
public bool UpdateNote(NoteEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Notes .Single(e => e.NoteID == model.NoteID && e.OwnerID == _userID); entity.Title = model.Title; entity.Content = model.Content; entity.ClassSubject = model.ClassSubject; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
public bool UpdateNotes(NoteEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Notes .Single(e => e.NoteId == model.NoteId && e.NoteOwnerId == _noteUserId); entity.NoteId = model.NoteId; entity.NoteTitle = model.NoteTitle; entity.NoteContent = model.NoteContent; entity.VehicleHistoryId = model.VehicleHistoryId; return(ctx.SaveChanges() == 1); } }