public ActionResult New() { var viewModel = new NoteFormViewModel(); string userName = ""; //OWIN or cookie auth if (Request.IsAuthenticated) { userName = System.Security.Claims.ClaimsPrincipal.Current.FindFirst("preferred_username").Value; } else { userName = User.Identity.GetUserName(); } var member = _context.Members.Single(m => m.Email == userName); viewModel.MadeBy = member.MemberId; viewModel.Members = _context.Members.ToList(); viewModel.DateCreated = DateTime.Now; viewModel.id = 0;//01.12.17 - BTo - Needed. Otherwise View will return a Model.IsValid = false return(View("NoteForm", viewModel)); }
public void UpdateNoteItemDoesntExist() { var model = new NoteFormViewModel { Title = "Note" }; Assert.IsNull(_repository.UpdateNoteItem(5, model)); }
public void TestAddNoteItem() { var model = new NoteFormViewModel() { Title = "Note" }; var item = _repository.AddNoteItem(model); Assert.NotNull(item); Assert.AreEqual("Note", item.Title); }
public ActionResult <NoteViewModel> EditNote(int id, [FromBody] NoteFormViewModel model) { var userId = GetUserId(User); if (!_journeyRepository.IsUsersNote(userId, id)) { return(StatusCode(403, "Note doesn't belong to the user")); } return(Ok(_journeyRepository.UpdateNoteItem(id, model))); }
public ActionResult <NoteViewModel> AddNote([FromBody] NoteFormViewModel model) { var userId = GetUserId(User); if (!_journeyRepository.IsUsersJourney(userId, model.JourneyId)) { return(StatusCode(403, "Journey doesn't belong to the user")); } return(Ok(_journeyRepository.AddNoteItem(model))); }
public NoteViewModel AddNoteItem(NoteFormViewModel model) { var note = new Note { JourneyId = model.JourneyId, Title = model.Title, Text = model.Text }; _context.Notes.Add(note); _context.SaveChanges(); return(new NoteViewModel { Id = note.Id, Title = note.Title, Text = note.Text }); }
public NoteViewModel UpdateNoteItem(int noteId, NoteFormViewModel model) { var note = _context.Notes.FirstOrDefault(n => n.Id == noteId); if (note == null) { return(null); } note.Title = model.Title; note.Text = model.Text; _context.Entry(note).State = EntityState.Modified; _context.SaveChanges(); return(new NoteViewModel { Id = note.Id, Title = note.Title, Text = note.Text }); }