比较控制器中的表

时间:2016-05-16 20:23:59

标签: c# asp.net entity-framework code-first asp.net-mvc-5

我有2个表,一个是Orders,它包含产品的地址/列表,以及一个returnDetails表。当用户想要返回订单时使用。 returnDetails具有正在返回的OrderId。

如何仅在具有相同OrderID的退货的订单上显示消息?目前只有"处理"显示。

我使用视图模型来显示带产品的订单。 这是我尝试过但我还没有完成它的工作:

[Authorize]
public ActionResult Index(string date)
{
    string currentUser = this.User.Identity.GetUserName();

    List<T_shirt_Company_v3.ViewModels.MyOrdersViewModel> list = (from o in new TshirtStoreDB().Orders
            .Where(o => o.Username == currentUser)
            .OrderByDescending(o => o.OrderDate)
            .Select(o => new MyOrdersViewModel()
            {
                OrderId = o.OrderId,
                Address = o.Address,
                FirstName = o.FirstName,
                LastName = o.LastName,
                City = o.City,
                OrderDate = o.OrderDate,
                PostalCode = o.PostalCode,
                Total = o.Total,
                HasBeenShipped = o.HasBeenShipped,
               PostageList = o.PostageList,
               Details = (from d in o.OrderDetails
                          select new MyOrderDetails
                          {
                              Colour = d.Product.Colour,
                              Quantity = d.Quantity,
                              Title = d.Product.Title,
                              UnitPrice = d.UnitPrice
                          }).ToList()
            }).ToList() select o).ToList();


    if (date != null)
    {
        DateTime today = DateTime.Now.AddDays(Convert.ToInt32(date) * -1);
        return View(list.Where(x => x.OrderDate >= today).ToList());
    }


     //WORKING ON
        var returnstats = db.Orders.Where(x => x.OrderId == x.returnDetails.OrderId).ToList();
        if (returnstats != null)
        {
            ViewBag.returnstats = "Returning Item";
        }
        else
        {
            ViewBag.returnstats = "processing";
        }


    return View(list);
}

1 个答案:

答案 0 :(得分:0)

我认为问题在于您不清楚返回状态&#39;的业务逻辑是什么。根据您提供的此变量的值,它看起来像是单个订单而不是订单列表。以下是修改后的Index方法供您参考:

scale = "free_y"