views:

267

answers:

4

I have an application that uses one-to-many relationshipped objects like oreder-orderDetails, vith EntityFramework.

I want to use a view, that make it possible to add a new order with some orderDetails objects.

I can create a strongly typed view, that returns an order object wich has a List orderDetails property, but can't populate the orderDetails.

Has anybody a solution, how to do that?

Thanks in advance

Gabriel

A: 

I think that you need to use the order table instead of the order view to do this.

Shiraz Bhaiji
I mean an asp.net MVC view and use EntityFramework that maps database tables to objects
Gabriel Robert
A: 

Ok, say you create a view named OpenOrders that inherits from your Order entity.

<%@ Page Language="C#"  
Inherits="System.Web.Mvc.ViewPage<List<OrdersApp.Models.Order>>" %>

So then you can display items from your orders list and also add a form that will allow the input of Order Details.

So when you post to the page you can receive the Orders object and FormCollection object

//
// POST: /Orders/OpenOrders/Details

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult OpenOrders(Order order, FormCollection collection)

Then you can create a new OrderDetails object and add it to the Orders object and then save.

OrderDetails orderdetails = new OrderDetails()

orderdetails.Description = = collection["OrderDescription"].ToString();
...
...

order.OrderDetails.Add(orderdetails);
orderRepository.Save();
Nicholas Murray
A: 

It not clear! I want a demo for that. can you help me! I needing it

dctamtn
A: 
  • Topic add order orderDetails

    1. Add into Order table

    2. Choose list order in a order table by orderID

    3. Check products in orderdetail for the overlap

    4. loop thought every orderdetail in listorderdetail, add into database

    5. Check some condition, for example: quantity of product in product table ....

-Ok?

dctamtn