public void UpdateStandingOrder(string entityId, StandingOrderEntityData requestData)
        {
            EnsureRepositoryOpen("UpdateStandingOrder");

            var standingOrder = _allStandingOrders.Single(r => r.PersistentId == entityId);

            SetRequestEntityImpData(standingOrder, requestData);
            _persistenceHandler.SaveChanges(new SavingTask(FilePath, standingOrder.Clone()));
        }
        public string CreateStandingOrder(StandingOrderEntityData requestData)
        {
            EnsureRepositoryOpen("CreateStandingOrder");

            var standingOrder = new StandingOrderEntityImp(_applicationContext);

            SetRequestEntityImpData(standingOrder, requestData);
            _allStandingOrders.Add(standingOrder);
            _persistenceHandler.SaveChanges(new SavingTask(FilePath, standingOrder.Clone()));

            return(standingOrder.PersistentId);
        }
        private void OnSaveRequestDetails(StandingOrderEntityData entityData)
        {
            if (string.IsNullOrEmpty(Details.EntityId))
            {
                var entityId = _application.Repository.CreateStandingOrder(entityData);
                Details.EntityId = entityId;

                var requestEntityViewModel = new StandingOrderEntityViewModel(_application, entityId);
                StandingOrders.AddValue(requestEntityViewModel);
                StandingOrders.Value = requestEntityViewModel;
                _allStandingOrders.Add(requestEntityViewModel);
            }
            else
            {
                _application.Repository.UpdateStandingOrder(Details.EntityId, entityData);
            }

            Details.IsInEditMode = false;
            _application.Repository.UpdateStandingOrdersToCurrentMonth(_application.ApplicationContext.Now.Year, _application.ApplicationContext.Now.Month);
            StandingOrders.Value.Refresh();
            UpdateCommandStates();
            _onStandingOrderUpdated();
        }
        private void SetRequestEntityImpData(StandingOrderEntityImp standingOrder, StandingOrderEntityData data)
        {
            standingOrder.Description     = data.Description;
            standingOrder.FirstBookDate   = data.FirstBookDate;
            standingOrder.MonthPeriodStep = data.MonthPeriodStep;
            standingOrder.ReferenceDay    = data.ReferenceDay;
            standingOrder.ReferenceMonth  = data.ReferenceMonth;
            standingOrder.Value           = data.Value;

            if (data.PaymentCount.HasValue)
            {
                var monthsAddToFirstBookDate = data.MonthPeriodStep * data.PaymentCount.Value;
                standingOrder.LastBookDate = standingOrder.FirstBookDate.AddMonths(monthsAddToFirstBookDate);
            }
            else
            {
                standingOrder.LastBookDate = DateTime.MaxValue;
            }

            if (!string.IsNullOrEmpty(data.CategoryEntityId))
            {
                standingOrder.Category = _allCategories.Single(c => c.PersistentId == data.CategoryEntityId);
            }
        }