Esempio n. 1
0
 public ActionResult Mypurchases()
 {
     using (var db = new ShoppingCartDbContext())
     {
         string sessionId = (string)Session["SessionId"];
         //select purchases based on customer id and session id from DB
         var mypurchases = (from cp in db.CustomerPurchase
                            join customer in db.Customer
                            on cp.CustomerId equals customer.Id
                            join product in db.Product
                            on cp.ProductId equals product.Id
                            where customer.SessionId == sessionId
                            select new {
             cp.ActivationCode,
             cp.DatePurchased,
             product.Name,
             product.Description,
             product.Img
         });
         List <MyPurchaseModel> PmList = new List <MyPurchaseModel>();
         foreach (var purchase in mypurchases)
         {
             MyPurchaseModel pm = new MyPurchaseModel();
             pm.ActivationCode = purchase.ActivationCode;
             pm.DateOfPurchase = purchase.DatePurchased;
             pm.Name           = purchase.Name;
             pm.Description    = purchase.Description;
             pm.Image          = purchase.Img;
             PmList.Add(pm);
         } // add List to MypurchaseModel
         ViewData["mypurchases"] = PmList;;
         return(View());
     }
 }
Esempio n. 2
0
        // GET: ViewPurchase
        public ActionResult MyPurchase(string SessionId)
        {
            //Check for session. if does not exist,redirect back to login screen
            if (!Util.SessionExist(SessionId))
            {
                return(RedirectToAction("Login", "Login"));
            }

            List <MyPurchaseModel> listofpurchase = new List <MyPurchaseModel>();

            using (var db = new ShoppingCartDbContext())
            {
                var purchases = (from customerpurchase in db.CustomerPurchase
                                 join customer in db.Customer
                                 on customerpurchase.CustomerId equals customer.Id
                                 join product in db.Product
                                 on customerpurchase.ProductId equals product.Id
                                 where customer.SessionId == SessionId
                                 orderby customerpurchase.DatePurchased descending, product.Name ascending
                                 select new
                {
                    product.ImageUrl,
                    product.Name,
                    product.Description,
                    customerpurchase.DatePurchased,
                    customerpurchase.ActivationCode
                }).ToList();
                foreach (var purchase in purchases)
                {
                    MyPurchaseModel p = new MyPurchaseModel();
                    p.ImageUrl       = purchase.ImageUrl;
                    p.Name           = purchase.Name;
                    p.Description    = purchase.Description;
                    p.DatePurchased  = purchase.DatePurchased;
                    p.ActivationCode = purchase.ActivationCode;
                    listofpurchase.Add(p);
                }
            }

            ViewData["CustomerPurchase"] = listofpurchase;
            ViewData["SessionId"]        = SessionId;

            return(View());
        }