Exemple #1
0
        public async Task <ActionResult <Note> > Patch(string id, JsonPatchDocument <Note> note)
        {
            logger.LogDebug($"Patching note: {id}");

            var noteToPatch = await notesService.GetNoteAsync(id);

            if (noteToPatch == null)
            {
                logger.LogDebug($"Unable to find note: {id}");
                return(NotFound());
            }

            var placeholderNote = new Note(noteToPatch);

            var validationResults = new NoteValidator().Validate(placeholderNote);

            if (!validationResults.IsValid)
            {
                return(BadRequest(validationResults.Errors));
            }

            note.ApplyTo(placeholderNote);

            var patchedNote = await notesService.UpdateNoteAsync(id, placeholderNote.Title, placeholderNote.Content);

            logger.LogDebug($"Patched note {noteToPatch.Id}");

            return(Ok(new Note(patchedNote)));
        }
 private void SetupTestEnv()
 {
     InsertSeedRecords();
     _user      = LookupRepo.GetEntities <Author>().FirstOrDefault();
     _validator = new NoteValidator(NoteRepository);
     _manager   = new HmmNoteManager(NoteRepository, _validator, DateProvider);
 }
Exemple #3
0
        public void AlertWithNoteAndMessageTypeErrorIsValid()
        {
            var alert = new Alert();
            alert.Note = "maxOccurs";
            alert.MessageType = MessageType.Error;

            var noteValidator = new NoteValidator(alert);
            Assert.True(noteValidator.IsValid);
        }
Exemple #4
0
        public void AlertWithNoteAndStatusExerciseIsValid()
        {
            var alert = new Alert();
            alert.Note = "maxOccurs";
            alert.Status = Status.Excercise;

            var noteValidator = new NoteValidator(alert);
            Assert.True(noteValidator.IsValid);
        }
Exemple #5
0
        public void AlertWithNoteNullAndStatusDifferentFromExerciseIsValid()
        {
            var alert = new Alert();
            alert.Note = null;
            alert.MessageType = MessageType.Cancel;

            var noteValidator = new NoteValidator(alert);
            Assert.True(noteValidator.IsValid);
        }
Exemple #6
0
 private void SetupTestEnv()
 {
     InsertSeedRecords();
     _validator = new NoteValidator(NoteRepository);
     _author    = AuthorRepository.GetEntities().FirstOrDefault();
     _catalog   = CatalogRepository.GetEntities().FirstOrDefault();
     Assert.NotNull(_author);
     Assert.NotNull(_catalog);
 }
Exemple #7
0
        public void AlertWithNoteNullAndMessageTypeErrorIsInvalid()
        {
            var alert = new Alert();
            alert.Note = null;
            alert.MessageType = MessageType.Error;

            var noteValidator = new NoteValidator(alert);
            Assert.False(noteValidator.IsValid);
            Assert.Equal(typeof(NoteError), noteValidator.Errors.ElementAt(0).GetType());
        }
Exemple #8
0
        public void AlertWithNoteNullAndStatusExerciseIsInvalid()
        {
            var alert = new Alert();
            alert.Note = null;
            alert.Status = Status.Excercise;

            var noteValidator = new NoteValidator(alert);
            Assert.False(noteValidator.IsValid);
            Assert.Equal(typeof(NoteError), noteValidator.Errors.ElementAt(0).GetType());
        }
Exemple #9
0
        public void AlertWithNoteAndMessageTypeErrorIsValid()
        {
            var alert = new Alert();

            alert.Note        = "maxOccurs";
            alert.MessageType = MessageType.Error;

            var noteValidator = new NoteValidator(alert);

            Assert.True(noteValidator.IsValid);
        }
Exemple #10
0
        public void AlertWithNoteNullAndStatusDifferentFromExerciseIsValid()
        {
            var alert = new Alert();

            alert.Note        = null;
            alert.MessageType = MessageType.Cancel;

            var noteValidator = new NoteValidator(alert);

            Assert.True(noteValidator.IsValid);
        }
Exemple #11
0
        public void AlertWithNoteAndStatusExerciseIsValid()
        {
            var alert = new Alert();

            alert.Note   = "maxOccurs";
            alert.Status = Status.Exercise;

            var noteValidator = new NoteValidator(alert);

            Assert.True(noteValidator.IsValid);
        }
Exemple #12
0
        public void AlertWithNoteNullAndMessageTypeErrorIsInvalid()
        {
            var alert = new Alert();

            alert.Note        = null;
            alert.MessageType = MessageType.Error;

            var noteValidator = new NoteValidator(alert);

            Assert.False(noteValidator.IsValid);
            Assert.Equal(typeof(NoteError), noteValidator.Errors.ElementAt(0).GetType());
        }
Exemple #13
0
        public void AlertWithNoteNullAndStatusExerciseIsInvalid()
        {
            var alert = new Alert();

            alert.Note   = null;
            alert.Status = Status.Exercise;

            var noteValidator = new NoteValidator(alert);

            Assert.False(noteValidator.IsValid);
            Assert.Equal(typeof(NoteError), noteValidator.Errors.ElementAt(0).GetType());
        }
Exemple #14
0
 public bool Remove(Guid id)
 {
     try
     {
         NoteValidator.Check(id);
         return(_noteDAO.Remove(id));
     }
     catch (Exception e)
     {
         //TO DO: log here
         return(false);
     }
 }
Exemple #15
0
 public NoteDTO Get(Guid id)
 {
     try
     {
         NoteValidator.Check(id);
         return(_noteDAO.Get(id));
     }
     catch (Exception e)
     {
         //TO DO: log here
         return(new NoteDTO());
     }
 }
Exemple #16
0
 public bool Add(NoteDTO noteDTO)
 {
     try
     {
         NoteValidator.Check(noteDTO, true);
         return(_noteDAO.Add(noteDTO));
     }
     catch (Exception e)
     {
         //TO DO: log here
         return(false);
     }
 }
Exemple #17
0
 public IEnumerable <NoteDTO> Find(string query)
 {
     try
     {
         query = query.ToLower();
         NoteValidator.Check(nameof(query), query);
         return(_noteDAO.GetAll().Where(x => x.LastName.ToLower().Contains(query) ||
                                        x.FirstName.ToLower().Contains(query) ||
                                        x.PhoneNumber.Contains(query)));
     }
     catch (Exception e)
     {
         //TO DO: log here
         return(new NoteDTO[0]);
     }
 }
Exemple #18
0
        private void SaveOrUpdate()
        {
            NoteValidator validator        = new NoteValidator();
            var           validationResult = validator.Validate(Note);

            if (validationResult.IsValid)
            {
                if (ActionName.Equals("Save"))
                {
                    Note note = new Note
                    {
                        Title       = Note.Title,
                        Content     = Note.Content,
                        CreatedDate = DateTime.Now,
                        UpdatedDate = DateTime.Now,
                        UserId      = _loggedInUser.Id
                    };

                    UnitOfWork.Notes.Add(note);
                }
                else
                {
                    Note foundNote = UnitOfWork.Notes.SingleOrDefault(n => n.Id == Note.Id);

                    foundNote.Title       = Note.Title;
                    foundNote.Content     = Note.Content;
                    foundNote.UpdatedDate = DateTime.Now;
                }

                if (UnitOfWork.Complete() > 0)
                {
                    MessageBox.Show($"Note Title: '{Note.Title}' {ActionName.ToLower()}d.", $"Note {ActionName}", MessageBoxButton.OK, MessageBoxImage.Information);
                    NavigateNotesPage();
                }
                else
                {
                    ErrorText = $"Note could not {ActionName.ToLower()}d.";
                }
            }
            else
            {
                // show first error message
                ErrorText = validationResult.Errors[0].ErrorMessage;
            }
        }
Exemple #19
0
 public NoteValidatorTests()
 {
     this.validator = new NoteValidator();
 }
Exemple #20
0
 /// <summary>
 /// Validated entered birth year
 /// </summary>
 /// <param name="birthYear">Validated value</param>
 /// <returns>Is value expected match with max human age property</returns>
 public static bool Check(int birthYear)
 {
     return(NoteValidator.Check(birthYear, false));
 }
 public NoteService(INoteRepository noteRepository, IPatientService patientService)
 {
     _noteRepository = noteRepository;
     _patientService = patientService;
     _noteValidator  = new NoteValidator();
 }