// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <AppDBContent>(options => options.UseSqlServer(_configurationString.GetConnectionString("DefaultConnection"))); services.AddTransient <IAllFoods, FoodRepository>(); services.AddTransient <IFoodsCategory, CategoryRepository>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped(sp => FoodCart.GetCart(sp)); services.AddRazorPages(); services.AddMemoryCache(); services.AddSession(); services.AddMvc(option => option.EnableEndpointRouting = false); }
public JsonResult SetCartValue(int id) { var foodDetails = _context.FoodItems.AsNoTracking().Where(s => s.FoodItemId == id).FirstOrDefault(); var food = new FoodCart { FoodItemId = id, Quantity = 1, FoodName = foodDetails.FoodName, FoodPrice = foodDetails.Price, FoodDescription = foodDetails.Description }; var List = HttpContext.Session.Get <List <FoodCart> >("FoodS"); if (List == null) { List = new List <FoodCart>(); List.Add(food); } else { var exist = List.Where(a => a.FoodItemId == id).FirstOrDefault(); if (exist != null) { food.Quantity = exist.Quantity + 1; food.FoodItemId = id; food.FoodPrice = food.FoodPrice; List.Remove(exist); List.Add(food); } else { List.Add(food); } } HttpContext.Session.Set("FoodS", List); var count = HttpContext.Session.Get <List <FoodCart> >("FoodS").Sum(t => t.Quantity); return(Json(count)); }
public JsonResult SetCartValueUpdated(int id, int Quantity) { var List = HttpContext.Session.Get <List <FoodCart> >("FoodS"); var up = List.Where(s => s.FoodItemId == id).FirstOrDefault(); var food = new FoodCart { FoodItemId = id, Quantity = Quantity, FoodName = up.FoodName, FoodPrice = up.FoodPrice, FoodDescription = up.FoodDescription }; List.Remove(up); List.Add(food); HttpContext.Session.Set("FoodS", List); var total = List.Sum(s => s.FoodPrice * s.Quantity); return(Json(total)); }
public FoodCartController(IAllFoods foodRepository, FoodCart foodCart) { _foodRep = foodRepository; _foodCart = foodCart; }
public static int GetOrderCount(this FoodCart <FoodOrder> cart) { }
public static int GetTotalItemsOrdered(this FoodCart <FoodOrder> cart) { }
public static double GetAmount(this FoodCart <FoodOrder> cart) { }
public static FoodOrder[] GetOrders(this FoodCart <FoodOrder> cart) { }