我使用的框架需要扩展新模型,控制器。
所以有一个观点。现在我尝试在现有视图中添加属性。
新属性被称为:
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类添加新属性。
因为如果我在Controller方法上放置一个断点: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为null
但是,如果我看到眼前的窗口,如果我这样做:?order.proje ...我没有看到一个属性projectNumber?怎么会这样?
答案 0 :(得分:1)
我会将您的问题分为两部分:
1)如何从View
获取Project_Number
2)如何将Project_Number
保存到数据库
问题1)
您需要检查Select
。你如何展示OrderoverviewModel_ProjectNumber
?您可能需要在Project_Number
函数
Select
在编辑视图中,您不会读取/编辑Project_Number
,所以实际上它是空的。
如果您不想更改Project_Number
,请检查第一点,您可能会错过从数据库中获取此信息。
问题2)
这里有一个棘手的部分,因为您可能没有IOrder
的源代码。但是,它是一个界面,所以你可以再次检查整个解决方案,主要类可能是Order
?
如果您无法找到它,我建议您重写代码部分,因为您不应该将Project_Number
与其他属性进行不同的存储
更新-1:现在,我们将Project_Number
添加到IOrder.cs
。如果需要,也会在Order.cs
中添加它。
最后,要将其存储在数据库中,请检查SaveOrder(IOrder order)
OrderManager