public void should_insert_new_order_with_line_items()
        {
            string newName = "A very funny customer " + new Random().Next(14345);

            var newOrder = new OrderModel(){CustomerName = newName};

            newOrder.AddLineItem(new LineItemModel() {Name = "line item 1"});

            _systemUnderTest.SaveOrUpdate(newOrder);

            _systemUnderTest.Session.Flush();

            int maxId = _systemUnderTest.MaxId();

            var check = _systemUnderTest.FetchById(maxId);

            Assert.AreEqual(newName, check.CustomerName);
        }
        public void ShouldMapRootPropertiesWithChildList()
        {
            var orderModel = new OrderModel(){CustomerName = "A customer"

                                             };
            orderModel.AddLineItem(new LineItemModel(){Name = "Linteitme1"});
            var result = new OrderTranslator().From(orderModel);

            Assert.AreEqual(orderModel.CustomerName, result.CustomerName);
            Assert.Greater(result.LineItems.Count, 0);
            Assert.AreEqual(result.LineItems[0].Name, "Linteitme1");

            // Kevin got another solution here: http://frankmao.com/2011/04/01/my-2-cents-about-new-csla/#comment-881
            // I just created a MarkOld method to do the similar thing.
            Assert.IsFalse(result.IsDirty, "Dirty flag is messed up.");
            Assert.IsFalse(result.IsNew);
            Assert.IsTrue(result.IsValid);

            Console.WriteLine(result.CustomerName);
            Console.WriteLine(result.LineItems.Count);
        }
 public void Delete(OrderModel order)
 {
     Session.Delete(order);
     Session.Flush();
 }
 public void SaveOrUpdate(OrderModel order)
 {
     Session.SaveOrUpdate(order);
     Session.Flush(); // For demo purpose
 }
        public TweekedCsla.Order Update(TweekedCsla.Order obj)
        {
            if (!obj.IsDirty) return obj;

            OrderModel orderToSave;
            if (obj.Id > 0)
            {
                orderToSave = OrderRepository.FetchById(obj.Id);

                orderToSave.LineItems.Clear();
            }
            else
            {
                orderToSave = new OrderModel();
            }

            orderToSave.CustomerName = obj.CustomerName;

            foreach (LineItem lineItem in obj.LineItems)
            {
                orderToSave.AddLineItem(new LineItemModel
                                            {
            //                                                Id = lineItem.Id,
            // LineItem treat as ValueObject, delete/insert everytime,
            // id will change after each save,
            // but who cares? name is the only thing important in order
                                                Name = lineItem.Name,
                                                Order = orderToSave
                                            });
            }

            OrderRepository.SaveOrUpdate(orderToSave);

            TweekedCsla.Order result = Fetch(new SingleCriteria<TweekedCsla.Order, int>(orderToSave.Id));
            return result;
        }