2017-02-15 94 views
0

我使用一個框架,您必須擴展新模型,控制器。保存新屬性asp.net mvc

所以有一種觀點。現在我嘗試添加屬性到現有的視圖。

新propertie被稱爲:

public virtual string Project_Number { get; set; } 

和模型是這樣的:

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; } 
    } 

的看法是這樣的:

@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> 

但我有一些問題控制器。控制器看起來是這樣的:

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看起來是這樣的:

// 
    // 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; } 
    } 

但這是一個DLL。所以我不能添加新的屬性到IOrder類。

因爲如果我把控制器方法斷點:SaveOrder

和我看的順序IOrder順序的屬性。我看到projectnumber爲null。

所以我的問題是:如何管理projectnumber獲取價值?

謝謝

這是爲了類:

[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. 
} 

所以我添加了一個新的Inteface這樣的:

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

    } 

如果我看的方法:SaveOrder( Iorder order),我將鼠標懸停在訂單上,我看到屬性ProjectNumber爲空

但是,如果我看看直接的窗口,如果我這樣做:?order.proje ...我沒有看到一個propertie projectNumber ??怎麼可能?

謝謝enter image description here

+1

請僅發佈相關代碼。其他人可能會感到困惑。並且清楚地解釋你的問題。 – ViVi

+0

先在SaveOrder中創建一個變量並將Order轉換爲OrderoverviewModel_ProjectNumber。檢查你是否獲得價值。另外,在base.save之後保存時,您需要添加其他邏輯來保存項目編號。提取時同樣如此。 – Amit

回答

1

我將你的問題中分離到2個部分:

1)如何從查看

2)獲得Project_Number如何Project_Number保存到數據庫

對於問題1)

  • 您需要檢查您的Select。你如何顯示OrderoverviewModel_ProjectNumber?您可能需要在Select函數中添加Project_Number函數

  • 在編輯視圖中,您不會讀取/編輯Project_Number,因此實際上它爲空。 如果您不想更改Project_Number,請檢查第一個點,您可能會錯過從數據庫中獲取該點。

對於問題2)

  • 這裏的一個棘手的部分,因爲你可能沒有足夠的源代碼IOrder。但是,這是一個界面,所以你可以再次檢查整個解決方案,可能是主類是Order

  • 如果你不能找到它,我建議重寫代碼的一部分,因爲你不應該與其他屬性

更新-1不同的存儲Project_Number:現在,讓我們添加Project_NumberIOrder.cs。如果需要,也可以在Order.cs中加入。 最後,要將其存儲在數據庫中,請檢查方法SaveOrder(IOrder order)中的OrderManager

+0

謝謝你的回覆。對於問題1,我已經得到它的屬性.Project_Number,從視圖。所以這不是問題。 –

+0

@HoicodeEngineer肯定,所以你可以忽略它:) – Jacky

+0

嗨,我做了一個更新。我已經添加了Order類,新的屬性公共字符串ProjectNumber {get;組; } –