Пример #1
0
        public void SaveMemento()
        {
            CustomerMemento customerMemento = new
                                              CustomerMemento(this.Name, this.Address, this.City, this.StateProvince, this.PostalCode);

            this.customerMementoes.Add(customerMemento);
        }
Пример #2
0
        public void SaveMemento()
        {
            CustomerMemento customerMemento =
                new CustomerMemento(Name, Address, City, StateProvince, PostalCode);

            _customerMementoes.Add(customerMemento);
        }
Пример #3
0
 private void SetPropertyValuesFromMemento(CustomerMemento memento)
 {
     Name          = memento.Name;
     Address       = memento.Address;
     City          = memento.City;
     StateProvince = memento.StateProvince;
     PostalCode    = memento.PostalCode;
 }
Пример #4
0
 private void SetPropertyValuesFormMemento(CustomerMemento lastMemento)
 {
     this.Name          = lastMemento.Name;
     this.Address       = lastMemento.Address;
     this.City          = lastMemento.City;
     this.StateProvince = lastMemento.StateProvince;
     this.PostalCode    = lastMemento.PostalCode;
 }
Пример #5
0
        public void ReverToLastValues()
        {
            CustomerMemento lastMemento = this.customerMementoes.LastOrDefault();

            if (lastMemento != null)
            {
                SetPropertyValuesFormMemento(lastMemento);
            }
        }
Пример #6
0
        public Customer(int id, string name, string address, string city, string stateProvince, string postalCode)
        {
            ID            = id;
            Name          = name;
            Address       = address;
            City          = city;
            StateProvince = stateProvince;
            PostalCode    = postalCode;

            // Save the originally-passed values to the "memento".
            _customerMemento = new CustomerMemento(name, address, city, stateProvince, postalCode);
        }
        public void RevertToLastValues()
        {
            // Get the last memento, if there is one (there always should be at least one).
            CustomerMemento lastMemento = _customerMementoes.LastOrDefault();

            // Check for null, just to be safe.
            if (null != lastMemento)
            {
                SetPropertyValuesFromMemento(lastMemento);
                // Remove last memento except the first one
                if (_customerMementoes.First() != lastMemento)
                {
                    _customerMementoes.Remove(lastMemento);
                }
            }
        }
        public void RevertToOriginalValues()
        {
            // Get the first memento, if there is one (there always should be at least one).
            CustomerMemento firstMemento = _customerMementoes.FirstOrDefault();

            // Check for null, just to be safe.
            if (null != firstMemento)
            {
                SetPropertyValuesFromMemento(firstMemento);
                // Remove all mementoes except the first one
                if (_customerMementoes.Count > 1)
                {
                    _customerMementoes.RemoveRange(1, _customerMementoes.Count - 1);
                }
            }
        }