Esempio n. 1
0
        /// <summary>
        /// Submit the order - save to the database (still editable).
        /// </summary>
        /// <returns></returns>
        public bool Submit()
        {
            if (this.ItemsOrdered.Count == 0)
            {
                Statics.DebugOut("Error: cannot submit an order without an items");
                return(false);
            }


            using (InvContext ctx = new InvContext())
            {
                // ensure the context knows about this item in reference to the database
                ctx.Customers.Attach(this.Customer);

                ctx.Entry(this).State = this.OrderID == default(int) ? EntityState.Added : EntityState.Modified;


                // tell the database that this item already exists or needs to be added

                this.DateOrdered = DateTime.Now;
                this.OrderCode   = "ABC" + Statics.rand.Next(0, 999).ToString().PadLeft(3, '0');

                ctx.SaveChanges();
            }

            return(true);
        }