Esempio n. 1
0
 public void AppendComment(string commentToAppend, SalesOrderHeader order) {
     if (order.Comment == null) {
         order.Comment = commentToAppend;
     }
     else {
         order.Comment += "; " + commentToAppend;
     }
 }
 public void AddAllItemsInCartToOrder(SalesOrderHeader order)
 {
     foreach (ShoppingCartItem item in Cart())
     {
         var detail = order.AddNewDetail(item.Product, (short)item.Quantity);
         Container.Persist<SalesOrderDetail>(ref detail);
     }
     EmptyCart();
 }
        public SalesOrderHeader CreateOrder()
        {
            SalesOrderHeader soh = OrderRepo.CreateNewOrder(Customer, true);

            soh.Status = (byte)OrderStatus.InProcess;
            Container.Persist(ref soh);

            foreach (OrderLine d in Details)
            {
                d.AddTo(soh);
            }

            return(soh);
        }
#pragma warning restore 612,618
        public static (SalesOrderHeader, IContext) AddNewDetail(
            this SalesOrderHeader soh,
            Product product,
            [DefaultValue((short)1), Range(1, 999)] short quantity,
            IContext context
            )
        {
            int stock = product.NumberInStock();
            var sod   = new SalesOrderDetail()
            {
                SalesOrderHeader    = soh,
                SalesOrderID        = soh.SalesOrderID,
                OrderQty            = quantity,
                SpecialOfferProduct = Product_Functions.BestSpecialOfferProduct(product, quantity, context)
            };

            //TODO:
            //sod.Recalculate();
            return(soh, context.WithPendingSave(sod).WithWarnUser(stock < quantity ? $"Current inventory of {product} is {stock}" : ""));
        }
#pragma warning restore 612,618
        public static (SalesOrderDetail, Action <IUserAdvisory>) AddNewDetail(
            this SalesOrderHeader soh,
            Product product,
            [DefaultValue((short)1), Range(1, 999)] short quantity,
            IQueryable <SpecialOfferProduct> sops
            )
        {
            int stock = product.NumberInStock();
            Action <IUserAdvisory> act = (IUserAdvisory ua) => ua.WarnUser(
                stock < quantity ? $"Current inventory of {product} is {stock}": "");
            var sod = new SalesOrderDetail
            {
                SalesOrderHeader    = soh,
                SalesOrderID        = soh.SalesOrderID,
                OrderQty            = quantity,
                SpecialOfferProduct = ProductFunctions2.BestSpecialOfferProduct(product, quantity, sops)
            };

            //TODO:
            //sod.Recalculate();
            return(sod, act);
        }
 public static string DisableRecalculate(this SalesOrderHeader soh) =>
 !soh.IsInProcess() ? "Can only recalculate an 'In Process' order" : null;
 public static string DisableShipDate(this SalesOrderHeader soh) => soh.DisableIfShipped();
Esempio n. 8
0
 public static void CommentAsUserUnhappy([ContributedAction(subMenu)] SalesOrderHeader order)
 {
     AppendComment("User unhappy", order);
 }
 public string ValidateAppendComment(string commentToAppend, SalesOrderHeader order) {
     return string.IsNullOrEmpty(commentToAppend) ? "Comment required" : null;
 }
 public void CommentAsUserUnhappy(SalesOrderHeader order)
 {
     AppendComment("User unhappy", order);
 }
 public void Persisted()
 {
     SalesOrderHeader.Details.Add(this);
     SalesOrderHeader.Recalculate();
 }
Esempio n. 12
0
 public static void CommentAsUserUnhappy(this SalesOrderHeader order)
 {
     AppendComment("User unhappy", order);
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the SalesOrderHeaders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSalesOrderHeaders(SalesOrderHeader salesOrderHeader)
 {
     base.AddObject("SalesOrderHeaders", salesOrderHeader);
 }
 /// <summary>
 /// Create a new SalesOrderHeader object.
 /// </summary>
 /// <param name="salesOrderID">Initial value of the SalesOrderID property.</param>
 /// <param name="revisionNumber">Initial value of the RevisionNumber property.</param>
 /// <param name="orderDate">Initial value of the OrderDate property.</param>
 /// <param name="dueDate">Initial value of the DueDate property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 /// <param name="onlineOrderFlag">Initial value of the OnlineOrderFlag property.</param>
 /// <param name="salesOrderNumber">Initial value of the SalesOrderNumber property.</param>
 /// <param name="customerID">Initial value of the CustomerID property.</param>
 /// <param name="contactID">Initial value of the ContactID property.</param>
 /// <param name="billToAddressID">Initial value of the BillToAddressID property.</param>
 /// <param name="shipToAddressID">Initial value of the ShipToAddressID property.</param>
 /// <param name="shipMethodID">Initial value of the ShipMethodID property.</param>
 /// <param name="subTotal">Initial value of the SubTotal property.</param>
 /// <param name="taxAmt">Initial value of the TaxAmt property.</param>
 /// <param name="freight">Initial value of the Freight property.</param>
 /// <param name="totalDue">Initial value of the TotalDue property.</param>
 /// <param name="rowguid">Initial value of the rowguid property.</param>
 /// <param name="modifiedDate">Initial value of the ModifiedDate property.</param>
 public static SalesOrderHeader CreateSalesOrderHeader(global::System.Int32 salesOrderID, global::System.Byte revisionNumber, global::System.DateTime orderDate, global::System.DateTime dueDate, global::System.Byte status, global::System.Boolean onlineOrderFlag, global::System.String salesOrderNumber, global::System.Int32 customerID, global::System.Int32 contactID, global::System.Int32 billToAddressID, global::System.Int32 shipToAddressID, global::System.Int32 shipMethodID, global::System.Decimal subTotal, global::System.Decimal taxAmt, global::System.Decimal freight, global::System.Decimal totalDue, global::System.Guid rowguid, global::System.DateTime modifiedDate)
 {
     SalesOrderHeader salesOrderHeader = new SalesOrderHeader();
     salesOrderHeader.SalesOrderID = salesOrderID;
     salesOrderHeader.RevisionNumber = revisionNumber;
     salesOrderHeader.OrderDate = orderDate;
     salesOrderHeader.DueDate = dueDate;
     salesOrderHeader.Status = status;
     salesOrderHeader.OnlineOrderFlag = onlineOrderFlag;
     salesOrderHeader.SalesOrderNumber = salesOrderNumber;
     salesOrderHeader.CustomerID = customerID;
     salesOrderHeader.ContactID = contactID;
     salesOrderHeader.BillToAddressID = billToAddressID;
     salesOrderHeader.ShipToAddressID = shipToAddressID;
     salesOrderHeader.ShipMethodID = shipMethodID;
     salesOrderHeader.SubTotal = subTotal;
     salesOrderHeader.TaxAmt = taxAmt;
     salesOrderHeader.Freight = freight;
     salesOrderHeader.TotalDue = totalDue;
     salesOrderHeader.rowguid = rowguid;
     salesOrderHeader.ModifiedDate = modifiedDate;
     return salesOrderHeader;
 }
 public static IQueryable <Product> AutoComplete0AddNewDetail(this SalesOrderHeader soh, [Range(2, 0)] string name, IQueryable <Product> products)
 {
     return(ProductRepository.FindProductByName(name, products));
 }
 public static IQueryable <Product> AutoComplete0AddNewDetail(this SalesOrderHeader soh, [Range(2, 0)] string name, IContext context) =>
 Product_MenuFunctions.FindProductByName(name, context);
        public FormCollection GetFormForOrderEdit(IObjectFacade order,
                                                  SalesOrderHeader soh,
                                                  string modifiedDate,
                                                  out IDictionary<string, string> idToRawValue) {
            var nakedObjectSpecification = order.Specification;
            var assocS = nakedObjectSpecification.Properties.Single(p => p.Id == "Status");
            var assocSC = nakedObjectSpecification.Properties.Single(p => p.Id == "StoreContact");
            var assocBA = nakedObjectSpecification.Properties.Single(p => p.Id == "BillingAddress");
            var assocPO = nakedObjectSpecification.Properties.Single(p => p.Id == "PurchaseOrderNumber");
            var assocSA = nakedObjectSpecification.Properties.Single(p => p.Id == "ShippingAddress");
            var assocSM = nakedObjectSpecification.Properties.Single(p => p.Id == "ShipMethod");
            var assocAN = nakedObjectSpecification.Properties.Single(p => p.Id == "AccountNumber");
            var assocCR = nakedObjectSpecification.Properties.Single(p => p.Id == "CurrencyRate");
            var assocCC = nakedObjectSpecification.Properties.Single(p => p.Id == "CreditCard");
            var assocC = nakedObjectSpecification.Properties.Single(p => p.Id == "Comment");
            var assocSP = nakedObjectSpecification.Properties.Single(p => p.Id == "SalesPerson");
            var assocST = nakedObjectSpecification.Properties.Single(p => p.Id == "SalesTerritory");
            var assocMD = nakedObjectSpecification.Properties.Single(p => p.Id == "ModifiedDate");

            string idS = IdHelper.GetFieldInputId(order, (assocS));
            string idSC = IdHelper.GetFieldInputId(order, (assocSC));
            string idBA = IdHelper.GetFieldInputId(order, (assocBA));
            string idPO = IdHelper.GetFieldInputId(order, (assocPO));
            string idSA = IdHelper.GetFieldInputId(order, (assocSA));
            string idSM = IdHelper.GetFieldInputId(order, (assocSM));
            string idAN = IdHelper.GetFieldInputId(order, (assocAN));
            string idCR = IdHelper.GetFieldInputId(order, (assocCR));
            string idCC = IdHelper.GetFieldInputId(order, (assocCC));
            string idC = IdHelper.GetFieldInputId(order, (assocC));
            string idSP = IdHelper.GetFieldInputId(order, (assocSP));
            string idST = IdHelper.GetFieldInputId(order, (assocST));
            string idMD = IdHelper.GetConcurrencyFieldInputId((order), (assocMD));

            var ct = soh.Contact;
            var cus = soh.Customer;
            var sc = FindStoreContactForContact(ct, cus);

            idToRawValue = new Dictionary<string, string> {
                {idS, soh.Status.ToString()},
                {idSC, NakedObjectsFramework.GetObjectId(sc)},
                {idBA, NakedObjectsFramework.GetObjectId(soh.BillingAddress)},
                {idPO, soh.PurchaseOrderNumber},
                {idSA, NakedObjectsFramework.GetObjectId(soh.ShippingAddress)},
                {idSM, NakedObjectsFramework.GetObjectId(soh.ShipMethod)},
                {idAN, soh.AccountNumber},
                {idCR, ""},
                {idCC, NakedObjectsFramework.GetObjectId(soh.CreditCard)},
                {idC, Guid.NewGuid().ToString()},
                {idSP, NakedObjectsFramework.GetObjectId(soh.SalesPerson)},
                {idST, NakedObjectsFramework.GetObjectId(soh.SalesTerritory)},
                {idMD, modifiedDate}
            };

            return GetForm(idToRawValue);
        }
        //        #region Add New Details
        //        [DescribedAs("Add multiple line items to the order")]
        //        [MultiLine()]
        //#pragma warning disable 612, 618
        //        [MemberOrder(1, "Details")]
        //#pragma warning restore 612,618
        //        public void AddNewDetails(
        //            Product product,
        //           [DefaultValue((short)1)] short quantity,
        //           IQueryable<SpecialOfferProduct> sops)
        //        {
        //            var detail = AddNewDetail(product, quantity, sops);
        //            Container.Persist(ref detail);
        //        }
        //        public virtual string DisableAddNewDetails()
        //        {
        //            return DisableAddNewDetail();
        //        }
        //        [PageSize(20)]
        //        public IQueryable<Product> AutoComplete0AddNewDetails([Range(2,0)] string name, IQueryable<Product> products)
        //        {
        //            return AutoComplete0AddNewDetail(name, products);
        //        }

        //        public string ValidateAddNewDetails(short quantity)
        //        {
        //            var rb = new ReasonBuilder();
        //            rb.AppendOnCondition(quantity <= 0, "Must be > 0");
        //            return rb.Reason;
        //        }

        //        #endregion

        //        #region Remove Detail
        //        public void RemoveDetail(SalesOrderDetail detailToRemove) {
        //            if (Details.Contains(detailToRemove)) {
        //                Details.Remove(detailToRemove);
        //            }
        //        }

        //        public IEnumerable<SalesOrderDetail> Choices0RemoveDetail() {
        //            return Details;
        //        }

        //        public SalesOrderDetail Default0RemoveDetail() {
        //            return Details.FirstOrDefault();
        //        }

        //        [MemberOrder(3)]
        //        public void RemoveDetails(this IEnumerable<SalesOrderDetail> details) {
        //            foreach (SalesOrderDetail detail in details) {
        //                if (Details.Contains(detail)) {
        //                    Details.Remove(detail);
        //                }
        //            }
        //        }
        //        #endregion

        //        #region AdjustQuantities
        //        [MemberOrder(4)]
        //        public void AdjustQuantities(this IEnumerable<SalesOrderDetail> details, short newQuantity)
        //        {
        //            foreach (SalesOrderDetail detail in details)
        //            {
        //                detail.OrderQty = newQuantity;
        //            }
        //        }

        //        public string ValidateAdjustQuantities(IEnumerable<SalesOrderDetail> details, short newQuantity)
        //        {
        //            var rb = new ReasonBuilder();
        //            rb.AppendOnCondition(details.Count(d => d.OrderQty == newQuantity) == details.Count(),
        //                "All selected details already have specified quantity");
        //            return rb.Reason;
        //        }

        //        #endregion

        //        #region CreateNewCreditCard

        //        [Hidden]
        //        public void CreatedCardHasBeenSaved(CreditCard card) {
        //            CreditCard = card;
        //        }

        //        #endregion

        //        #region AddNewSalesReason

        //#pragma warning disable 618
        //        [MemberOrder(Name= "SalesOrderHeaderSalesReason", Sequence = "1")]
        //#pragma warning restore 618
        //        public void AddNewSalesReason(SalesReason reason) {
        //            if (SalesOrderHeaderSalesReason.All(y => y.SalesReason != reason)) {
        //                var link = Container.NewTransientInstance<SalesOrderHeaderSalesReason>();
        //                link.SalesOrderHeader = this;
        //                link.SalesReason = reason;
        //                Container.Persist(ref link);
        //                SalesOrderHeaderSalesReason.Add(link);
        //            }
        //            else {
        //                Container.WarnUser(string.Format("{0} already exists in Sales Reasons", reason.Name));
        //            }
        //        }

        //        public string ValidateAddNewSalesReason(SalesReason reason) {
        //            return SalesOrderHeaderSalesReason.Any(y => y.SalesReason == reason) ? string.Format("{0} already exists in Sales Reasons", reason.Name) : null;
        //        }

        //        [MemberOrder(1)]
        //        public void RemoveSalesReason(SalesOrderHeaderSalesReason reason)
        //        {
        //            this.SalesOrderHeaderSalesReason.Remove(reason);
        //            Container.DisposeInstance(reason);
        //        }


        //        public IList<SalesOrderHeaderSalesReason> Choices0RemoveSalesReason()
        //        {
        //            return this.SalesOrderHeaderSalesReason.ToList();
        //        }

        //        [MemberOrder(2)]
        //        public void AddNewSalesReasons(IEnumerable<SalesReason> reasons) {
        //            foreach (SalesReason r in reasons) {
        //                AddNewSalesReason(r);
        //            }
        //        }

        //        public string ValidateAddNewSalesReasons(IEnumerable<SalesReason> reasons) {
        //            return reasons.Select(ValidateAddNewSalesReason).Aggregate("", (s, t) => string.IsNullOrEmpty(s) ? t : s + ", " + t);
        //        }

        //        [MemberOrder(2)]
        //        public void RemoveSalesReasons(
        //            this IEnumerable<SalesOrderHeaderSalesReason> salesOrderHeaderSalesReason)
        //        {
        //            foreach(var reason in salesOrderHeaderSalesReason)
        //            {
        //                this.RemoveSalesReason(reason);
        //            }
        //        }

        //        // This is done with an enum in order to test enum parameter handling by the framework
        //        public enum SalesReasonCategories {
        //            Other,
        //            Promotion,
        //            Marketing
        //        }

        //        [MemberOrder(3)]
        //        public void AddNewSalesReasonsByCategory(SalesReasonCategories reasonCategory) {
        //            IQueryable<SalesReason> allReasons = Container.Instances<SalesReason>();
        //            var catName = reasonCategory.ToString();

        //            foreach (SalesReason salesReason in allReasons.Where(salesReason => salesReason.ReasonType == catName)) {
        //                AddNewSalesReason(salesReason);
        //            }
        //        }

        //        [MemberOrder(4)]
        //        public void AddNewSalesReasonsByCategories(IEnumerable<SalesReasonCategories> reasonCategories) {
        //            foreach (SalesReasonCategories rc in reasonCategories) {
        //                AddNewSalesReasonsByCategory(rc);
        //            }
        //        }

        //        // Use 'hide', 'dis', 'val', 'actdef', 'actcho' shortcuts to add supporting methods here.

        //        #endregion

        //        #region ApproveOrder

        //        [MemberOrder(1)]
        //        public void ApproveOrder() {
        //            Status = (byte) OrderStatus.Approved;
        //        }

        //        public virtual bool HideApproveOrder() {
        //            return !IsInProcess();
        //        }

        //        public virtual string DisableApproveOrder() {
        //            var rb = new ReasonBuilder();
        //            if (Details.Count == 0) {
        //                rb.Append("Cannot approve orders with no Details");
        //            }
        //            return rb.Reason;
        //        }

        //        #endregion

        //        #region MarkAsShipped

        //        [DescribedAs("Indicate that the order has been shipped, specifying the date")]
        //        [Hidden] //Testing that the complementary methods don't show up either
        //        public void MarkAsShipped(DateTime shipDate) {
        //            Status = (byte) OrderStatus.Shipped;
        //            ShipDate = shipDate;
        //        }

        //        public virtual string ValidateMarkAsShipped(DateTime date) {
        //            var rb = new ReasonBuilder();
        //            if (date.Date > DateTime.Now.Date) {
        //                rb.Append("Ship Date cannot be after Today");
        //            }
        //            return rb.Reason;
        //        }

        //        public virtual string DisableMarkAsShipped() {
        //            if (!IsApproved()) {
        //                return "Order must be Approved before shipping";
        //            }
        //            return null;
        //        }

        //        public virtual bool HideMarkAsShipped() {
        //            return IsRejected() || IsShipped() || IsCancelled();
        //        }

        //        #endregion

        //        #region CancelOrder

        //        // return this for testing purposes
        //        public SalesOrderHeader CancelOrder() {
        //            Status = (byte) OrderStatus.Cancelled;
        //            return this;
        //        }

        //        public virtual bool HideCancelOrder() {
        //            return IsShipped() || IsCancelled();
        //        }

        //        #endregion

        #endregion

        internal static bool IsInProcess(this SalesOrderHeader soh)
        {
            return(soh.Status.Equals((byte)OrderStatus.InProcess));
        }
 public string ValidateCommentAsUserUnhappy(SalesOrderHeader order) {
     return order.IsShipped() ? null : "Not shipped yet";
 }
 internal static bool IsShipped(this SalesOrderHeader soh)
 {
     return(soh.Status.Equals((byte)OrderStatus.Shipped));
 }
        public void AddTo(SalesOrderHeader salesOrder)
        {
            SalesOrderDetail sod = salesOrder.AddNewDetail(Product, Number);

            Container.Persist(ref sod);
        }
 internal static bool IsCancelled(this SalesOrderHeader soh)
 {
     return(soh.Status.Equals((byte)OrderStatus.Cancelled));
 }
Esempio n. 23
0
 public static string ValidateAppendComment(string commentToAppend, SalesOrderHeader order)
 {
     return(string.IsNullOrEmpty(commentToAppend) ? "Comment required" : null);
 }
 public static ShipMethod DefaultShipMethod(this SalesOrderHeader soh, IContext context) => context.Instances <ShipMethod>().FirstOrDefault();
Esempio n. 25
0
 public static string ValidateCommentAsUserUnhappy(SalesOrderHeader order)
 {
     return(order.IsShipped() ? null : "Not shipped yet");
 }
 public static string DisableDueDate(this SalesOrderHeader soh)
 {
     return(soh.DisableIfShipped());
 }