public void UpdateRequest(string persistentId, RequestEntityData data)
        {
            EnsureRepositoryOpen("UpdateRequest");

            var request = _allRequests.Single(r => r.PersistentId == persistentId);
            SetRequestData(request, data);
            _persistenceHandler.SaveChanges(new SavingTask(FilePath, request.Clone()));
        }
        public string CreateRequest(RequestEntityData data)
        {
            EnsureRepositoryOpen("CreateRequest");

            var request = new RequestEntityImp();
            SetRequestData(request, data);
            _allRequests.Add(request);
            _persistenceHandler.SaveChanges(new SavingTask(FilePath, request.Clone()));

            return request.PersistentId;
        }
        public void CreateRequest(bool withCategory)
        {
            CreateCategoriesInRepository(3);
            CreateRequestsInRepository(new[] { new DateTime(2014, 1, 1) }, new[] { 10 });

            var categoryEntity = Repository.QueryAllCategories().First();
            var requestData = new RequestEntityData
            {
                Date = new DateTime(2014, 6, 1),
                Description = "My Description",
                Value = -11,
                CategoryPersistentId = withCategory ? categoryEntity.PersistentId : null
            };

            PersistenceHandler.ClearReceivedCalls();
            var persistentId = Repository.CreateRequest(requestData);

            var createdRequest = Repository.QueryRequest(persistentId);

            Assert.That(createdRequest.PersistentId, Is.EqualTo(persistentId));
            Assert.That(createdRequest.Description, Is.EqualTo(requestData.Description));
            Assert.That(createdRequest.Value, Is.EqualTo(requestData.Value));

            if (withCategory)
            {
                Assert.That(createdRequest.Category.PersistentId, Is.EqualTo(categoryEntity.PersistentId));
            }
            else
            {
                Assert.That(createdRequest.Category, Is.Null);
            }

            PersistenceHandler.Received(1).SaveChanges(Arg.Is<SavingTask>(t => t.RequestsToUpdate.Count == 1 &&
                                                                               t.CategoriesToUpdate.Count == 0 &&
                                                                               t.EntitiesToDelete.Count == 0 &&
                                                                               t.StandingOrdersToUpdate.Count == 0 &&
                                                                               t.FilePath == DatabaseFile));
        }
 private void SetRequestData(RequestEntityImp request, RequestEntityData data)
 {
     request.Date = data.Date;
     request.Description = data.Description;
     request.Value = data.Value;
     request.Category = _allCategories.SingleOrDefault(c => c.PersistentId == data.CategoryPersistentId);
 }
        private void OnEditRequest(RequestDialogViewModel requestDialog)
        {
            var currentRequestEntityId = Requests.Value.EntityId;
            var requestEntityData = new RequestEntityData
            {
                Date = requestDialog.DateProperty.Value,
                Description = requestDialog.DescriptionProperty.Value,
                Value = requestDialog.CalculateValue,
                CategoryPersistentId = requestDialog.Categories.Value != null ? requestDialog.Categories.Value.EntityId : null
            };
            Application.Repository.UpdateRequest(currentRequestEntityId, requestEntityData);

            Requests.Value.Refresh();
            UpdateSaldoForCurrentMonth();
        }
        public void UpdateRequest()
        {
            var originalRequest = CreateRequestInRepository(DateTime.Now.Date, "Testdescription", 12.75);
            var persistentId = originalRequest.PersistentId;
            PersistenceHandler.ClearReceivedCalls();

            var newData = new RequestEntityData
            {
                Date = new DateTime(2013, 7, 6),
                Description = "New Description",
                Value = 11.11
            };
            Repository.UpdateRequest(persistentId, newData);

            var queriedRequest = Repository.QueryRequest(persistentId);

            Assert.That(queriedRequest.Description, Is.EqualTo("New Description"));
            Assert.That(queriedRequest.Value, Is.EqualTo(11.11));

            PersistenceHandler.Received(1).SaveChanges(Arg.Is<SavingTask>(t => t.RequestsToUpdate.Count == 1 &&
                                                                               t.CategoriesToUpdate.Count == 0 &&
                                                                               t.EntitiesToDelete.Count == 0 &&
                                                                               t.StandingOrdersToUpdate.Count == 0 &&
                                                                               t.FilePath == DatabaseFile));
        }