/// <summary> /// Maps a given note view model to the Note model entitiy class. /// </summary> /// <param name="noteViewModel">The note view model we want to transform to a note entity class object.</param> /// <returns><see cref="Note"/> object transformed from the note view model.</returns> public static Note ToNoteEntity(NoteViewModel noteViewModel) { var note = new Note() { Id = noteViewModel.Id, Board = new Board() { Id = noteViewModel.BoardId }, Text = noteViewModel.Text, Title = noteViewModel.Title, Top = noteViewModel.Top, Left = noteViewModel.Left, }; return note; }
/// <summary> /// Map the domain model for the Note object to the NoteViewModel object. /// </summary> /// <param name="note">The domain <see cref="Note"/> object</param> /// <returns>Returns a <see cref="NoteViewModel"/> object</returns> public static NoteViewModel ToNoteViewModel(Note note) { var noteViewModel = new NoteViewModel() { Id = note.Id, Text = note.Text, BoardId = note.Board == null ? Guid.Empty : note.Board.Id, Title = note.Title, Top = note.Top, Left = note.Left }; return noteViewModel; }
public ActionResult SaveNote(NoteViewModel noteViewModel) { // Create a json result view model object that will be returned to the client calling code. var result = new JsonResultViewModel(); // Transform the view model to the Domain note object var note = NoteMappings.ToNoteEntity(noteViewModel); // Try and to save or update the note using the note service var noteUpdated = _noteService.SaveOrUpdateNote(note); // If we succeeded in saving or updating the note the updated note will have a concrete value if (noteUpdated != null) { // Set the apropriate json result object values. result.Success = true; result.Message = "Successfully saved the note"; // Map the Note from the domain object to the NoteViewModel result.Data = NoteMappings.ToNoteViewModel(noteUpdated); // return the result view model as json return Json(result); } else { // If something went wrong with the service call set the // apropriate values on the json result object. result.Success = false; result.Message = "Failed to save or update the note"; result.Data = null; // Return the Json Result object in json format to the client code return Json(result); } }