Exemple #1
0
        internal IResult <Note> Execute(INotebookKey notebookKey, DateTime timestamp, ICreateNoteParameters parameters)
        {
            if (notebookKey == null)
            {
                throw new ArgumentNullException("notebookKey");
            }
            if (timestamp == null)
            {
                throw new ArgumentNullException("timestamp");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var employeeResult = new GetEmployeeCommand(_notebookUnitOfWork).GetEmployee(parameters);

            if (!employeeResult.Success)
            {
                return(employeeResult.ConvertTo((Note)null));
            }

            var notebookKeyFind = new NotebookKey(notebookKey);
            var notebook        = _notebookUnitOfWork.NotebookRepository.FindByKey(notebookKeyFind);

            if (notebook == null)
            {
                return(new InvalidResult <Note>(null, string.Format(UserMessages.NotebookNotFound, notebookKeyFind)));
            }
            return(Execute(notebook, timestamp, employeeResult.ResultingObject, parameters.Text));
        }
        public IResult <INotebookReturn> GetNotebook(string notebookKey)
        {
            if (notebookKey == null)
            {
                throw new ArgumentNullException("notebookKey");
            }

            var keyResult = KeyParserHelper.ParseResult <INotebookKey>(notebookKey);

            if (!keyResult.Success)
            {
                return(keyResult.ConvertTo((INotebookReturn)null));
            }
            var key = new NotebookKey(keyResult.ResultingObject);

            var predicate = key.FindByPredicate;
            var select    = NotebookProjectors.Select();

            var notebook = _notebookUnitOfWork.NotebookRepository.Filter(predicate).AsExpandable().Select(select).FirstOrDefault();

            if (notebook == null)
            {
                return(new InvalidResult <INotebookReturn>(null, string.Format(UserMessages.NotebookNotFound, notebookKey)));
            }

            return(new SuccessResult <INotebookReturn>(notebook));
        }
        public IResult <INoteReturn> AddNote(string notebookKey, ICreateNoteParameters parameters)
        {
            if (notebookKey == null)
            {
                throw new ArgumentNullException("notebookKey");
            }

            var keyResult = KeyParserHelper.ParseResult <INotebookKey>(notebookKey);

            if (!keyResult.Success)
            {
                return(keyResult.ConvertTo <INoteReturn>());
            }
            var key = new NotebookKey(keyResult.ResultingObject);

            var createNoteResult = new CreateNoteCommand(_notebookUnitOfWork).Execute(key, _timeStamper.CurrentTimeStamp, parameters);

            if (!createNoteResult.Success)
            {
                return(createNoteResult.ConvertTo <INoteReturn>());
            }

            _notebookUnitOfWork.Commit();

            return(SyncParameters.Using(new SuccessResult <INoteReturn>(new[] { createNoteResult.ResultingObject }.Select(NoteProjectors.Select().Compile()).FirstOrDefault()), key));
        }
            public void Creates_new_Note_record_as_expected_on_success()
            {
                //Arrange
                var notebookKey = new NotebookKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Notebook>());

                //Act
                var result = Service.AddNote(notebookKey.KeyValue, new CreateNoteParameters
                {
                    Text      = "ARGARGHRAGH!!!!",
                    UserToken = TestUser.UserName
                });

                //Assert
                result.AssertSuccess();
                RVCUnitOfWork.NoteRepository.Filter(n => true, n => n.Employee).Single().AssertEqual(result.ResultingObject);
            }