예제 #1
0
        public IActionResult Index()
        {
            AuthController.CheckUserLoggedIn(this);

            List <PurchaseViewModel> purchases = new List <PurchaseViewModel>();

            using (ApplicationContext db = new ApplicationContext())
            {
                var temp = db.Purchases.Where(a => a.Email == Request.Cookies["Email"] && a.IsDone == false).ToList();
                if (temp.Count != 0)
                {
                    foreach (var p in temp)
                    {
                        purchases.Add(new PurchaseViewModel(p));
                    }
                }
            }

            ViewBag.Purchases = purchases;

            return(View());
        }
예제 #2
0
 public string RemoveProduct(int id)
 {
     if (AuthController.IsUserLoggedIn(this) == false)
     {
         return(JsonResponse.Error("user are not logged in!"));
     }
     using (ApplicationContext db = new ApplicationContext())
     {
         var email = Request.Cookies["Email"];
         var temp  = db.Purchases.Where(a => a.Email == email && a.IsDone == false).ToList();
         if (temp.Count == 0)
         {
             return(JsonResponse.Error("no such product in the basket!"));
         }
         var purchase         = temp[0];
         var purchaseProducts = JsonSerializer.Deserialize <List <ProductViewModel> >(purchase.Products);
         purchaseProducts.Remove(purchaseProducts.Where(a => a.ID == id).ToList()[0]);
         purchase.Products = JsonSerializer.Serialize(purchaseProducts);
         db.SaveChanges();
     }
     return(JsonResponse.Success());
 }
 public IActionResult EditShopSettings()
 {
     AuthController.CheckUserLoggedIn(this, true);
     return(View());
 }
 public IActionResult Index()
 {
     AuthController.CheckUserLoggedIn(this, true);
     return(View());
 }