【发布时间】:2014-10-08 15:05:41
【问题描述】:
我正在开发一个MVC4 应用程序,并且我构建了一个通知系统,向订阅公司的用户发送有关印章的消息,这样我就可以保存用户最后一次访问该网站的时间以及完成销售和进入的时间下次用户返回该站点时,我会告诉用户上次访问该站点的所有产品密封时间,如果产品密封时间大于用户上次访问它会返回所有指定此条件的产品,但我无法获取用户订阅的公司,只能从这些公司获取此产品这是我的数据库:
这就是我在实体框架中尝试做的事情:
public ActionResult LastTimeVisedSales()
{
if (User.Identity.IsAuthenticated)
{
var UserCompaniesSubscribed = db.SubscribDetails.Include(sub => sub.User).Include(sub => sub.Company)
.Where(sub => sub.UserID == CurrentUserID).ToList();
var LastTimeVisetDate = db.UserProfiles.Where(p => p.UserID == CurrentUserID)
.Select(user => new
{
lastTimeViset = user.LastLogin
}).SingleOrDefault();
var lastlogin = LastTimeVisetDate.lastTimeViset;
List<ProductsIndexViewModel> Result = new List<ProductsIndexViewModel>();
foreach(var d in UserCompaniesSubscribed){
var ProductNewsLogIn = db.Products.Include(p => p.SubCategory).Include(p => p.Store)
.Where(p => p.SalesTime >= lastlogin && p.Store.Company.CompanyID == d.CompanyID )
.Select(p => new ProductsIndexViewModel
{
ProductID = p.ProductID,
ProductImageURL = p.ProductImageURL,
ProductName = p.ProductName,
Price = p.Price,
Quantity = p.Quantity,
Sales = p.Sales,
Discount = p.Discount,
NewPrice = p.NewPrice,
StoreName = p.Store.StoreName,
CategoryName = p.SubCategory.Category.CategoryName,
SubCategoryName = p.SubCategory.SubCategoryName,
CompanyName = p.Store.Company.CompanyName
}).SingleOrDefault();
Result.Add(ProductNewsLogIn);
}
return Json(Result);
}
return Json("no seals from last time log in");
}
非常感谢您的任何帮助。
【问题讨论】:
标签: asp.net asp.net-mvc database entity-framework asp.net-mvc-4