Beispiel #1
0
        //for simplicity keep it bool, but an enum with different status codes would be more useful
        //also would probably want to return the order
        /// <summary>
        ///     Creates the specified customer.
        /// </summary>
        /// <param name="customer">The customer.</param>
        /// <param name="evt">The evt.</param>
        /// <param name="amount">The amount.</param>
        /// <param name="quantity">The quantity.</param>
        /// <param name="creditCard">The credit card.</param>
        /// <returns></returns>
        public OrderResult Create(Customer customer, Event evt, int amount, int quantity, CreditCard creditCard)
        {
            var result = new OrderResult();
            try
            {
                //as above, don't believe permission logic  belongs here

                var user = (User) Thread.CurrentPrincipal.Identity;
                var order = new Order(Guid.NewGuid(), customer, creditCard, amount, quantity, evt, DateTime.Now, user);

                //validation on order failed
                if (order.HasErrors())
                {
                    result.Status = Status.Fail;
                    result.Data = order.Errors;
                    return result;
                }

                //order successful
                result.Id = order.Id;
                result.Status = Status.Ok;
                return result;
            }
                //not sure if this should really occur at a lover level
            catch (Exception ex)
            {
                File.AppendAllText(@"C:\Errors.txt", ex.Message);
                result.Status = Status.Fail;
                return result;
            }
        }
Beispiel #2
0
 //use pence rather than decimals for currency, find easier to work with, potentially less space in the db
 //customer and credit card will have their own invariants upon creation
 //event should be part of the order
 //I like the idea of having an errors array in DomainAggregate
 /// <summary>
 ///     Initializes a new instance of the <see cref="Order" /> class.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="customer">The customer.</param>
 /// <param name="card">The card.</param>
 /// <param name="amount">The amount.</param>
 /// <param name="quantity">The quantity.</param>
 /// <param name="evt">The evt.</param>
 /// <param name="created">The created.</param>
 /// <param name="user">The user.</param>
 public Order(Guid id, Customer customer, CreditCard card, decimal amount, int quantity, Event evt,
     DateTime created, User user)
 {
     Customer = customer;
     Card = card;
     Amount = amount;
     Quantity = quantity;
     Evt = evt;
     Created = created;
     User = user;
     Id = id;
     CreateOrder();
 }