Exemplo n.º 1
0
 private void SaveItems(List <OrderItem> items)
 {
     foreach (var item in items)
     {
         if (item.HasChanges)
         {
             if (item.IsValid)
             {
                 if (item.IsNew)
                 {
                     _itemStorage.AddRecord(
                         new KeyValuePair <string, string>("Guid", item.Guid.ToString()),
                         new KeyValuePair <string, string>("OrderGuid", item.OrderGuid.ToString()),
                         new KeyValuePair <string, string>("ProductGuid", item.ProductGuid.ToString()),
                         new KeyValuePair <string, string>("PurchasePrice", item.PurchasePrice.ToString()),
                         new KeyValuePair <string, string>("Quantity", item.Quantity.ToString()));
                 }
                 else
                 {
                     _itemStorage.UpdateRecord(item.Guid.ToString(),
                                               new KeyValuePair <string, string>("OrderGuid", item.OrderGuid.ToString()),
                                               new KeyValuePair <string, string>("ProductId", item.ProductGuid.ToString()),
                                               new KeyValuePair <string, string>("PurchasePrice", item.PurchasePrice.ToString()),
                                               new KeyValuePair <string, string>("Quantity", item.Quantity.ToString()));
                 }
             }
         }
     }
 }
        public bool Save(Product product)
        {
            var result = true;

            if (product.HasChanges)
            {
                if (product.IsValid)
                {
                    if (product.IsNew)
                    {
                        result = _storage.AddRecord(
                            new KeyValuePair <string, string>("Guid", product.Guid.ToString()),
                            new KeyValuePair <string, string>("Name", product.Name),
                            new KeyValuePair <string, string>("Description", product.Description),
                            new KeyValuePair <string, string>("Price", product.Price.ToString()));
                    }
                    else
                    {
                        result = _storage.UpdateRecord(product.Guid.ToString(),
                                                       new KeyValuePair <string, string>("Name", product.Name),
                                                       new KeyValuePair <string, string>("Description", product.Description),
                                                       new KeyValuePair <string, string>("Price", product.Price.ToString()));
                    }
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }
            return(result);
        }
        public bool Save(Customer customer)
        {
            var result = true;

            if (customer.HasChanges)
            {
                if (customer.IsValid)
                {
                    if (customer.IsNew)
                    {
                        result = _storage.AddRecord(
                            new KeyValuePair <string, string>("Guid", customer.Guid.ToString()),
                            new KeyValuePair <string, string>("FirstName", customer.FirstName),
                            new KeyValuePair <string, string>("LastName", customer.LastName),
                            new KeyValuePair <string, string>("Email", customer.Email),
                            new KeyValuePair <string, string>("Type", ((int)customer.Type).ToString()));
                    }
                    else
                    {
                        result = _storage.UpdateRecord(customer.Guid.ToString(),
                                                       new KeyValuePair <string, string>("FirstName", customer.FirstName),
                                                       new KeyValuePair <string, string>("LastName", customer.LastName),
                                                       new KeyValuePair <string, string>("Email", customer.Email),
                                                       new KeyValuePair <string, string>("Type", ((int)customer.Type).ToString()));
                        _customerToAddressStorage.RemoveAllMatchingRecords("CustomerGuid", customer.Guid.ToString());
                    }
                    foreach (var address in customer.Addresses)
                    {
                        _customerToAddressStorage.AddRecord(
                            new KeyValuePair <string, string>("CustomerGuid", customer.Guid.ToString()),
                            new KeyValuePair <string, string>("AddressGuid", address.Guid.ToString()));
                    }
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }
            return(result);
        }
Exemplo n.º 4
0
        public bool Save(Address address)
        {
            var result = true;

            if (address.HasChanges)
            {
                if (address.IsValid)
                {
                    if (address.IsNew)
                    {
                        result = _storage.AddRecord(
                            new KeyValuePair <string, string>("Guid", address.Guid.ToString()),
                            new KeyValuePair <string, string>("StreetLine1", address.StreetLine1),
                            new KeyValuePair <string, string>("StreetLine2", address.StreetLine2),
                            new KeyValuePair <string, string>("City", address.City),
                            new KeyValuePair <string, string>("StateOrRegion", address.StateOrRegion),
                            new KeyValuePair <string, string>("Country", address.Country),
                            new KeyValuePair <string, string>("Code", address.Code),
                            new KeyValuePair <string, string>("Type", ((int)address.Type).ToString()));
                    }
                    else
                    {
                        result = _storage.UpdateRecord(address.Guid.ToString(),
                                                       new KeyValuePair <string, string>("StreetLine1", address.StreetLine1),
                                                       new KeyValuePair <string, string>("StreetLine2", address.StreetLine2),
                                                       new KeyValuePair <string, string>("City", address.City),
                                                       new KeyValuePair <string, string>("StateOrRegion", address.StateOrRegion),
                                                       new KeyValuePair <string, string>("Country", address.Country),
                                                       new KeyValuePair <string, string>("Code", address.Code),
                                                       new KeyValuePair <string, string>("Type", ((int)address.Type).ToString()));
                    }
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }
            return(result);
        }
Exemplo n.º 5
0
        public bool Save(Order order)
        {
            var result = true;

            if (order.HasChanges)
            {
                if (order.IsValid)
                {
                    if (order.IsNew)
                    {
                        result = _storage.AddRecord(
                            new KeyValuePair <string, string>("Guid", order.Guid.ToString()),
                            new KeyValuePair <string, string>("Id", order.Id.ToString()),
                            new KeyValuePair <string, string>("CustomerGuid", order.CustomerGuid.ToString()),
                            new KeyValuePair <string, string>("AddressGuid", order.Address?.Guid.ToString()),
                            new KeyValuePair <string, string>("Date", order.Date.ToString()));
                    }
                    else
                    {
                        result = _storage.UpdateRecord(order.Guid.ToString(),
                                                       new KeyValuePair <string, string>("Id", order.Id.ToString()),
                                                       new KeyValuePair <string, string>("CustomerGuid", order.CustomerGuid.ToString()),
                                                       new KeyValuePair <string, string>("AddressGuid", order.Address?.Guid.ToString()),
                                                       new KeyValuePair <string, string>("Date", order.Date.ToString()));
                    }
                    SaveItems(order.Items);
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }
            return(result);
        }