Hoi codeEngineerKing
Hoi codeEngineerKing

Reputation: 19

save new propertie asp.net mvc

I work with a framework where you have to extend new models, controllers.

So there is a view. And now I try to add a propertie to that existing view.

The new propertie is called:

public virtual string  Project_Number { get; set; }

and the model looks like this:

public class OrderoverviewModel_ProjectNumber: OrderOverviewModel
    {

        [Display(Name = "ProjectNumber")]
        [MaxLength(50, ErrorMessageResourceName = "Validation_MaxLength")]
        public virtual string  Project_Number { get; set; }
        public OrderOverviewModel overViewModel { get; set; }
    }

the view looks like this:

@model Sana.Commerce.DomainModel.Order.OrderoverviewModel_ProjectNumber

<div class="additional-info">
    <h4>@Sana.SimpleText("OrderOverview_AdditionalInformation")</h4>
    @*@if (Shop.UserAbilities.Has(AbilityTo.AddReferenceNo))
    {*@
        <div class="form-row">
            <div class="control">
                <div class="label">
                    @Html.LabelFor(it => it.ReferenceNumber, htmlAttributes: new { @class = "lbl" })
                </div>
                <div class="field">
                    @Html.EditorFor(it => it.ReferenceNumber, new { tabindex = 1 })
                </div>
            </div>
            <div class="validation">
                @Html.ValidationMessageFor(it => it.ReferenceNumber)
            </div>
        </div>
    @*}*@

    @*@if (Shop.UserAbilities.Has(AbilityTo.AddReferenceNo))
    {*@
        <div class="form-row">
            <div class="control">
                <div class="label">
                    @Html.LabelFor(it => it.Project_Number, htmlAttributes: new { @class = "lbl" })
                </div>
                <div class="field">
                    @Html.EditorFor(it => it.Project_Number, new { tabindex = 1 })
                </div>
            </div>
            <div class="validation">
                @Html.ValidationMessageFor(it => it.Project_Number)
            </div>
        </div>
    @*}*@




    @if (Shop.UserAbilities.Has(AbilityTo.AddReferenceNo))
    {
        <div class="form-row">
            <div class="control">
                <div class="label">
                    @Html.LabelFor(it => it.Comments, htmlAttributes: new { @class = "lbl" })
                </div>
                <div class="field">
                    @Html.EditorFor(it => it.Comments, new { tabindex = 1 })
                </div>
            </div>
            <div class="validation">
                @Html.ValidationMessageFor(it => it.Comments)
            </div>
        </div>
    }
    @if (Shop.UserAbilities.Has(AbilityTo.AddRequestedDeliveryDate))
    {
        <div class="form-row">
            <div class="control">
                <div class="label">
                    @Html.LabelFor(it => it.DeliveryDate, htmlAttributes: new { @class = "lbl" })
                </div>
                <div class="field">
                    @Html.EditorFor(it => it.DeliveryDate, new { tabindex = 1 })
                </div>
            </div>
            <div class="validation">
                @Html.ValidationMessageFor(it => it.DeliveryDate)
            </div>
        </div>
    }
</div>

But I have some problems with the Controller. The controller looks like this:

 public class ExtendedOrderManager : OrderManager<IExtendedOrderProvider>
    {
        public string CustomAction(int value)
        {
            var cacheKey = CacheKey.ForErpItem<object>("customaction_" + value, cacheGroup: "abc");
            return CacheManager.FromCache(cacheKey, () => Provider.CustomAction(value));
        }

        public override IOrder SaveOrder(IOrder order)
        {
            //order.Fields.SetField(new Entities.EntityField("BlanketOrderId", "BO1") { StoreWithEntity = true });

            //order["BlanketOrderId"] = "BO1";
            //order.Fields["BlanketOrderId"].StoreWithEntity = true;

            return base.SaveOrder(order);
        }
    }

IOrder looks like this:

 //
    // Summary:
    //     This interface represents an order in the ERP system. This can be an order that
    //     still has to be placed or an order that is already in the ERP (for example order
    //     history). There are several types of orders like regular orders, invoice and
    //     quotes. The type of order is stored in the document type property.
    public interface IOrder : IEntity, IVersionedItem
    {
        //
        // Summary:
        //     ID of the account that placed the order.
        string AccountId { get; set; }
        //
        // Summary:
        //     The type of account that placed this order.
        AccountType AccountType { get; set; }
        //
        // Summary:
        //     Gets or sets the list of order attachments.
        IList<IAttachment> Attachments { get; set; }
        //
        // Summary:
        //     Gets or sets the status of order authorization.
        OrderAuthorizationStatus AuthorizationStatus { get; set; }
        //
        // Summary:
        //     Address that will recieve the invoice.
        ICustomerAddress BillingAddress { get; set; }
        //
        // Summary:
        //     Gets or sets bill-to name.
        string BillToName { get; set; }
        //
        // Summary:
        //     Gets or sets the comment.
        string Comment { get; set; }
        //
        // Summary:
        //     Name of the Contact that placed this order.
        string Contact { get; set; }
        //
        // Summary:
        //     ID of the Contact that placed this order.
        string ContactId { get; set; }
        //
        // Summary:
        //     ID of the currency used to place this order (for example USD). This can be different
        //     from the current users default currency.
        string CurrencyId { get; set; }
        //
        // Summary:
        //     The total amount of discount the customer gets over this order. This includes
        //     linediscount over all basketlines and invoice discount.
        decimal DiscountAmount { get; set; }
        //
        // Summary:
        //     Document date.
        Date? DocumentDate { get; set; }
        //
        // Summary:
        //     The OrderId (in the case of other types than Order or Quote).
        string DocumentId { get; set; }
        //
        // Summary:
        //     Gets or sets the document type.
        string DocumentType { get; set; }
        //
        // Summary:
        //     Due date.
        Date? DueDate { get; set; }
        //
        // Summary:
        //     Gets or sets the value indicating whether this order has report.
        bool HasReport { get; set; }
        //
        // Summary:
        //     The ID of the instance.
        string Id { get; set; }
        //
        // Summary:
        //     The total amount of invoice discount the customer gets over his/her order. This
        //     is calculated using the totalprice without VAT.
        decimal InvoiceDiscount { get; set; }
        //
        // Summary:
        //     Gets or sets a value indicating whether this quote is confirmed.
        bool IsQuoteConfirmed { get; set; }
        //
        // Summary:
        //     Location code.
        string LocationCode { get; set; }
        //
        // Summary:
        //     Gets or sets the max expired date.
        DateTime? MaxExpirationDate { get; set; }
        //
        // Summary:
        //     Date on which the order was placed.
        Date OrderDate { get; set; }
        //
        // Summary:
        //     The order lines.
        IList<IOrderLine> OrderLines { get; set; }
        //
        // Summary:
        //     The number of order lines.
        int OrderLinesCount { get; set; }
        //
        // Summary:
        //     Gets or sets the order type.
        OrderType? OrderType { get; set; }
        //
        // Summary:
        //     The ID of the sales order which this document is linked to. For example, if it
        //     is an 'Invoice' document then this field should be the ID of the sales order
        //     for which this invoice has been posted. In case this is an 'Order' or 'Quote'
        //     document type then this field should be empty.
        string OriginalOrderId { get; set; }
        //
        // Summary:
        //     Gets or sets the original quote identifier.
        string OriginalQuoteId { get; set; }
        //
        // Summary:
        //     The total amount outstanding.
        decimal OutstandingAmount { get; set; }
        //
        // Summary:
        //     Address of the company the order was paid by.
        ICustomerAddress PayerAddress { get; set; }
        //
        // Summary:
        //     Payment Discount.
        decimal PaymentDiscount { get; set; }
        //
        // Summary:
        //     Payment Discount Date.
        Date? PaymentDiscountDate { get; set; }
        //
        // Summary:
        //     Name of the payment method used by the customer.
        string PaymentMethod { get; set; }
        //
        // Summary:
        //     Status of the Payment of this order.
        string PaymentStatus { get; set; }
        //
        // Summary:
        //     Payment terms code.
        string PaymentTermsCode { get; set; }
        //
        // Summary:
        //     The payment transaction ID.
        string PaymentTransactionId { get; set; }
        //
        // Summary:
        //     Posting Date.
        Date? PostingDate { get; set; }
        //
        // Summary:
        //     Gets or sets the prepayment amount.
        decimal PrepaymentAmount { get; set; }
        //
        // Summary:
        //     Gets or sets the prepayment percentage.
        decimal PrepaymentPercentage { get; set; }
        //
        // Summary:
        //     Gets or sets a value indicating whether prices include tax.
        bool PricesInclTax { get; set; }
        //
        // Summary:
        //     Promised Delivery Date.
        Date? PromisedDeliveryDate { get; set; }
        //
        // Summary:
        //     Gets or sets the reference no.
        string ReferenceNo { get; set; }
        //
        // Summary:
        //     Requested Delivery Date.
        Date? RequestedDeliveryDate { get; set; }
        //
        // Summary:
        //     The round-off value, which is added or substracted from the subtotal value when
        //     the rounding precision of total costs is corrected on the ERP side.
        decimal RoundOff { get; set; }
        //
        // Summary:
        //     Name of the sales person that placed this order.
        string SalesPerson { get; set; }
        //
        // Summary:
        //     ID of the sales person that placed this order.
        string SalesPersonId { get; set; }
        //
        // Summary:
        //     Gets or sets the Sana internal order identifier.
        string SanaOrderId { get; set; }
        //
        // Summary:
        //     Address of the company the order was selled to.
        ICustomerAddress SellToAddress { get; set; }
        //
        // Summary:
        //     Date the order was shipped.
        Date? ShipmentDate { get; set; }
        //
        // Summary:
        //     Address this order will or was shipped to.
        ICustomerAddress ShippingAddress { get; set; }
        //
        // Summary:
        //     Code (string) of the method the order was shipped by.
        string ShippingMethodCode { get; set; }
        //
        // Summary:
        //     Name of the method the order was shipped by.
        string ShippingMethodName { get; set; }
        //
        // Summary:
        //     Gets or sets the shipping status. Order is shipped only if order lines are shipped.
        string ShippingStatus { get; set; }
        //
        // Summary:
        //     The shipping tracking link provided by the shipping agent.
        string ShippingTrackingLink { get; set; }
        //
        // Summary:
        //     The shipping tracking number provided by the shipping agent.
        string ShippingTrackingNumber { get; set; }
        //
        // Summary:
        //     Gets or sets ship-to name.
        string ShipToName { get; set; }
        //
        // Summary:
        //     Gets or sets the e-mail address of the shop account who placed this order.
        string ShopAccountEmail { get; set; }
        //
        // Summary:
        //     Gets or sets the status of this order.
        OrderStatus Status { get; set; }
        //
        // Summary:
        //     The total Amount of tax the user has to pay over all basket lines.
        decimal TaxAmount { get; set; }
        //
        // Summary:
        //     The lines containing taxes.
        IList<ITaxLine> TaxLines { get; set; }
        //
        // Summary:
        //     The percentage of tax that is used for this order (for example when tax is 19%,
        //     this property contains 19).
        decimal TaxPercent { get; set; }
        //
        // Summary:
        //     The total price of all products of this order including invoice discount and
        //     VAT.
        decimal TotalPrice { get; set; }
        //
        // Summary:
        //     The total price of all products of this order without any discounts or tax added.
        decimal TotalPriceExcludingDiscount { get; set; }
        //
        // Summary:
        //     The total price of all products of this order including invoice discount, but
        //     excluding tax.
        decimal TotalPriceExcludingTax { get; set; }
        //
        // Summary:
        //     The Total number of products this order contains.
        decimal TotalQuantity { get; }
        //
        // Summary:
        //     The ID of the website.
        string WebsiteId { get; set; }
    }

But this is a DLL. So I cant add new properties to the IOrder class.

Because if I put a breakpoint on the Controller method: SaveOrder

and I watch the properties in the order IOrder order. I see that projectnumber is null.

So my question is: How to manage that the projectnumber gets a value?

Thank you

And this is the order class:

[Serializable]
    [DataContract(Namespace = "")]
    public class Order : Entity, IOrder
    {
        #region Properties

        /// <summary>
        /// Status of the Payment of this order.
        /// </summary>
        [DataMember]
        public string PaymentStatus { get; set; }



        [DataMember]
        [XmlField]
        public string ProjectNumber { get; set; }

        /// <summary>
        /// The address the customer should recieve the bill.
}

So I have added a new Inteface like this:

 interface IOrderProjectNumber:IOrder
    {
        string ProjectNumber { get; set; }

    }

If I look in the method: SaveOrder(Iorder order) and I hover my mouse on the order I see the propertie ProjectNumber is null

But if I look in the immediate Window And If I do this: ?order.proje... I dont see a propertie projectNumber?? How can that be?

Thank youenter image description here

Upvotes: 0

Views: 59

Answers (1)

Jacky
Jacky

Reputation: 3259

I will separate your question to 2 parts:

1) How to get Project_Number from View

2) How to save Project_Number to database

For question 1)

  • You need to check your Select. How do you display OrderoverviewModel_ProjectNumber? You might need to add Project_Number inside that Select function

  • In Edit View, you doesn't read/edit Project_Number so in-fact, it's null. In case you don't want to change Project_Number, then check back the first point,you might miss getting this from database.

For question 2)

  • A tricky part here, as you might not have the source code for IOrder. However, it's an interface, so you can check the whole solution again, may be the main class is Order?

  • In case you can't find it, i suggest to rewrite the code part, as you should not store the Project_Number differently with other properties

Update-1: Now, let add the Project_Number to IOrder.cs. Added it in Order.cs if it needed too. Finally, to store it in database, check the method SaveOrder(IOrder order) in OrderManager

Upvotes: 1

Related Questions