public ShoppingCard GetShoppingCart(string id) { ShoppingCard items = new ShoppingCard(); foreach (var item in _unitOfWork.Orders.GetShoppingCart(id)) { var offerDetails = _unitOfWork.Offers.Get(x => x.ID == item.Service_ID); items.AddToCard(new Offer { AuthorId = offerDetails.Employee_ID, Id = offerDetails.ID, Description = offerDetails.Description, RatePerHour = offerDetails.RatePerHour, Title = offerDetails.Title, WorkingTime = new WorkingDetails { Date = item.Date, HoursFrom = item.HourFrom, HoursTo = item.HourTo, WeekDay = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), item.Date.DayOfWeek.ToString()), }, }); } return(items); }
/// <summary> /// This function used to changed enabled and visible. /// This function used to calculate and write price ,tax and cargo amount. /// </summary> /// <returns> This function does not return a value </returns> private void Invoice_Load(object sender, EventArgs e) { chkFirstAddress.Checked = true; txtAddress.Text = LoginedCustomer.getInstance().User.Address; txtAddress.Enabled = false; chkCreditCard.Checked = true; pnlCreditCard.Visible = true; pnlTransfer.Visible = false; pnlVerification.Visible = false; chkboxMNGCargo.Checked = true; for (int i = 0; i < StoreMainScreen.shoppingCards.Count; i++) { if (StoreMainScreen.shoppingCards[i].CustomerID == LoginedCustomer.getInstance().User.CustomerId) { temp = StoreMainScreen.shoppingCards[i]; break; } } price = temp.PaymentAmount; lblPrice.Text += price.ToString() + "₺"; tax = price * (0.18); lblTax.Text += tax.ToString() + "₺"; if (price >= 75) { cargoAmount = 0; } else { cargoAmount = mngCargo; } lblCargoPrice.Text = "Cargo Price: " + cargoAmount.ToString() + "₺"; totalPrice = price + tax + cargoAmount; lblTotal.Text = "Total (with Tax): " + totalPrice.ToString() + "₺"; }
public IActionResult OnPost() { if (ModelState.IsValid) { var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCardObj.ApplicationUserId = claim.Value; ShoppingCard cartFromDb = _unitOfWork.ShoppingCard.GetFirstOrDefault(c => c.ApplicationUserId == ShoppingCardObj.ApplicationUserId && c.MenuItemId == ShoppingCardObj.MenuItemId); if (cartFromDb == null) { _unitOfWork.ShoppingCard.Add(ShoppingCardObj); } else { cartFromDb.Count = _unitOfWork.ShoppingCard.IncrementCount(cartFromDb, ShoppingCardObj.Count); } _unitOfWork.Save(); var count = _unitOfWork.ShoppingCard.GetAll(c => c.ApplicationUserId == ShoppingCardObj.ApplicationUserId).ToList().Count; HttpContext.Session.SetInt32(SD.ShoppingCard, count); return(RedirectToPage("Index")); } else { ShoppingCardObj.MenuItem = _unitOfWork.MenuItem.GetFirstOrDefault(includeProperties: "Category,FoodType", filter: c => c.Id == ShoppingCardObj.MenuItemId); return(Page()); } }
public async Task <IActionResult> AddToShoppingCard(int id) { User user = await _userManager.GetUserAsync(HttpContext.User); Document doc = await _db.Documents.Include(x => x.Advocate).Include(x => x.Subcategory).Where(x => x.Id == id).FirstOrDefaultAsync(); if (user == null) { return(RedirectToAction("Registration", "Account")); } else { ShoppingCard SC = new ShoppingCard(); SC.Document = doc; SC.DocumentId = doc.Id; SC.User = user; SC.UserId = user.Id; await _db.ShoppingCard.AddAsync(SC); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } }
// Add: Products public ActionResult Add(ShoppingCard sc, int id) { int numberOfProducts = 0; foreach (Product art in sc) { if (art.Id == id) { numberOfProducts++; } } Product product = db.Products.Find(id); if (numberOfProducts >= product.stock) { TempData["notice_error"] = "No existe suficiente stock para el producto solicitado"; } else { sc.Add(product); TempData["notice_success"] = "Se ha Añadido el artículo al carrito"; } return(RedirectToAction("Index")); }
public void OnGet(long id) { ShoppingCardObj = new ShoppingCard() { MenuItem = _unitOfWork.MenuItem.GetFirstOrDefault(includeProperties: "Category,FoodType", filter: c => c.Id == id), MenuItemId = id }; }
public void ShowHistory() { Console.WriteLine("Caretaker: Here's the list of ShoppingCards:"); foreach (var ShoppingCard in this.savedShoppingCards) { Console.WriteLine(ShoppingCard.GetID()); } }
public void _04_Creer_une_classe_ShoppingCard_avec_une_methode_AddItem() { ShoppingCard shoppingCard = new ShoppingCard(); shoppingCard.AddItem("apple", 10); shoppingCard.AddItem("banana", 10); Assert.NotNull(shoppingCard); }
public int SaveItem(ShoppingCard item) { if (item.Id != 0) { _db.Update(item); return(item.Id); } return(_db.Insert(item)); }
/// <summary> /// This function fill the user control from shopping cards. /// </summary> /// <param name="_card"></param> /// <returns>This function returns AdminOrderDesign</returns> public AdminOrderDesign(ShoppingCard _card) { InitializeComponent(); this.card = _card; string customerName = ""; foreach (Customer cst in OceanBookStore.customerList) { if (card.CustomerID == cst.CustomerId) { customerName = cst.Name; break; } } string payType = ""; switch (card.Type) { case PaymentType.cash: payType = "Cash"; break; case PaymentType.creditcard: payType = "Credit Card"; break; case PaymentType.transfer: payType = "Transfer/EFT"; break; } string status = ""; switch (card.Status) { case OrderStatus.waitForShip: status = "Waiting for ship"; break; case OrderStatus.shipped: status = "Shipped"; break; case OrderStatus.received: status = "Received"; break; case OrderStatus.canceled: status = "Canceled"; break; } lbCustomer.Text += customerName; lbPaymentType.Text += payType; lbAmount.Text += card.PaymentAmount.ToString() + " ₺"; lbStatus.Text += status; }
public IActionResult Details(int id) { var product = _uow.product.GetFirstOrDefault(p => p.Id == id, includeProperties: "Category,CoverType"); ShoppingCard shoppingCard = new ShoppingCard() { Product = product, ProductId = product.Id }; return(View(shoppingCard)); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { ShoppingCard shoppingCard = (ShoppingCard)controllerContext.HttpContext.Session["KEY"]; if (shoppingCard == null) { shoppingCard = new ShoppingCard(); controllerContext.HttpContext.Session["KEY"] = shoppingCard; } return(shoppingCard); }
public IActionResult Details(int id) { var productFromDB = _unitOfWork.Product.GetFirstOrDefault(u => u.Id == id, includeProperties: "Category,CoverType"); ShoppingCard cardObj = new ShoppingCard() { Product = productFromDB, ProductId = productFromDB.Id }; return(View(cardObj)); }
public async Task <IActionResult> Details(int Id) { var menuItemDb = await _db.MenuItem.Include(m => m.Category).Include(m => m.SubCategory). Where(m => m.Id == Id).FirstOrDefaultAsync(); ShoppingCard shoppingCard = new ShoppingCard() { MenuItem = menuItemDb, MenuItemId = menuItemDb.Id }; return(View(shoppingCard)); }
// GET: ShoppingCard/Delete/5 public ActionResult Delete(int?id, ShoppingCard sc) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Product product = sc.Find(x => x.Id == id); if (product != null) { sc.Remove(product); } return(RedirectToAction("Index")); }
public void ConfigureServices(IServiceCollection services) { services.AddDbContext <AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity <IdentityUser>().AddEntityFrameworkStores <AppDbContext>(); services.AddControllersWithViews(); services.AddScoped <ICategoryRepository, CategoryRepository>(); services.AddScoped <ISportsGoodsRepository, SportsGoodsRepository>(); services.AddScoped <ShoppingCard>(c => ShoppingCard.GetCard(c)); services.AddScoped <IOrderRepository, OrderRepository>(); services.AddHttpContextAccessor(); services.AddSession(); services.AddRazorPages(); }
public string Post([FromBody] ShoppingCard dto) { using (OnlineDatabaseEntities entites = new OnlineDatabaseEntities()) { if (entites.ShoppingCards.ToList().Find(existingCard => existingCard.CardNumber == (dto.CardNumber)) == null) { entites.ShoppingCards.Add(dto); entites.SaveChanges(); return(""); } else { return("Card Number already exists"); } } }
public IActionResult Details(ShoppingCard cardObject) { cardObject.Id = 0; if (ModelState.IsValid) { //then we will add to card var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); cardObject.ApplicationUserId = claim.Value; ShoppingCard cardFromDb = _unitOfWork.ShoppingCard.GetFirstOrDefault( u => u.ApplicationUserId == cardObject.ApplicationUserId && u.ProductId == cardObject.ProductId, includeProperties: "Product" ); if (cardFromDb == null) { //no records exists in db for that product for that user _unitOfWork.ShoppingCard.Add(cardObject); } else { cardFromDb.Count += cardObject.Count; //_unitOfWork.ShoppingCard.Update(cardFromDb); } _unitOfWork.Save(); var count = _unitOfWork.ShoppingCard .GetAll(c => c.ApplicationUserId == cardObject.ApplicationUserId) .ToList().Count(); HttpContext.Session.SetInt32(SD.ssShoppingCard, count); return(RedirectToAction(nameof(Index))); } else { var productFromDB = _unitOfWork.Product.GetFirstOrDefault(u => u.Id == cardObject.Id, includeProperties: "Category,CoverType"); ShoppingCard cardObj = new ShoppingCard() { Product = productFromDB, ProductId = productFromDB.Id }; return(View(cardObj)); } }
public ShoppingCard GetShoppingCartForPaypal(string id) { ShoppingCard items = new ShoppingCard(); foreach (var item in _unitOfWork.Orders.GetShoppingCart(id)) { var offerDetails = _unitOfWork.Offers.Get(x => x.ID == item.Service_ID); items.AddToCardPayPal(new PayPalOffer { Id = offerDetails.ID, HoursFrom = item.HourFrom, HoursTo = item.HourTo, RatePerHour = offerDetails.RatePerHour, Title = offerDetails.Title, }); } return(items); }
public bool InsertUser(LoginData loginData) { try { var salt = UserServices.GetSalt(); var newUser = new User() { email = loginData.Email, approach = loginData.Approach, active = false, name = loginData.Username, password = BCrypt.Net.BCrypt.HashPassword(loginData.Password + salt), salt = salt, role = Roles.User }; using (MainContext context = new MainContext(new DbContextOptionsBuilder <MainContext>().UseMySql( ConfigurationManager.AppSetting.GetConnectionString("DefaultConnection") ).Options)) { context.Add(newUser); context.SaveChanges(); var shoppingCart = new ShoppingCard() { UserId = newUser.id }; this.__context.Add(shoppingCart); this.__context.SaveChanges(); } if (!newUser.active) { this.SendActivationMail(newUser); } ; return(true); } catch (System.Exception) { return(false); } }
public async Task <IActionResult> Details(ShoppingCard CardObject) { CardObject.Id = 0; if (ModelState.IsValid) { var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); CardObject.ApplicationUserId = claim.Value; ShoppingCard cardFromDb = await _db.ShoppingCard.Where(c => c.ApplicationUserId == CardObject.ApplicationUserId && c.MenuItemId == CardObject.MenuItemId) .FirstOrDefaultAsync(); if (cardFromDb == null) { await _db.ShoppingCard.AddAsync(CardObject); } else { cardFromDb.Count = cardFromDb.Count + CardObject.Count; } await _db.SaveChangesAsync(); var count = _db.ShoppingCard.Where(c => c.ApplicationUserId == CardObject.ApplicationUserId) .ToList().Count; HttpContext.Session.SetInt32(SD.ssCardCount, count); return(RedirectToAction("Index")); } else { var menuItemFromDb = await _db.MenuItem.Include(m => m.Category).Include(m => m.SubCategory) .Where(m => m.Id == CardObject.MenuItemId).FirstOrDefaultAsync(); ShoppingCard cardObj = new ShoppingCard() { MenuItem = menuItemFromDb, MenuItemId = menuItemFromDb.Id }; return(View(cardObj)); } }
public void _05_Creer_une_methode_Pay_qui_prend_en_paramètre_une_strategie_de_paiement() { ShoppingCard shoppingCard = new ShoppingCard(); shoppingCard.AddItem("apple", 10); shoppingCard.AddItem("banana", 10); string transaction = shoppingCard.Pay(new CreditCard()); Assert.Equal("20 has been charged to my credit card", transaction); shoppingCard = new ShoppingCard(); shoppingCard.AddItem("Manga", 15); transaction = shoppingCard.Pay(new Paypal()); Assert.Equal("15 has been charged to my paypal account", transaction); }
public string Put([FromBody] ShoppingCard dto) { using (OnlineDatabaseEntities entites = new OnlineDatabaseEntities()) { var existingCard = entites.ShoppingCards.ToList().Find(oldCard => oldCard.CardNumber.Equals(dto.CardNumber)); if (existingCard != null) { existingCard.BankName = dto.BankName; existingCard.FirstName = dto.FirstName; existingCard.LastName = dto.LastName; existingCard.ValidDate = dto.ValidDate; existingCard.Price = dto.Price; entites.SaveChanges(); return(""); } else { return("Card cannot be modified"); } } }
public IActionResult Details(ShoppingCard cartObj) { cartObj.Id = 0; if (ModelState.IsValid) { var claimIdentity = (ClaimsIdentity)User.Identity; var claim = claimIdentity.FindFirst(ClaimTypes.NameIdentifier); cartObj.ApplicationUserId = claim.Value; ShoppingCard fromDb = _uow.shoppingCard.GetFirstOrDefault(s => s.ApplicationUserId == cartObj.ApplicationUserId && s.ProductId == cartObj.ProductId, includeProperties: "Product"); if (fromDb == null) { //insert _uow.shoppingCard.Add(cartObj); } else { //update fromDb.Count += cartObj.Count; } _uow.Save(); var shoppingCount = _uow.shoppingCard.GetAll(a => a.ApplicationUserId == cartObj.ApplicationUserId).ToList().Count; HttpContext.Session.SetInt32(ProjectConstant.shoppingCard, shoppingCount); return(RedirectToAction("Index")); } else { var product = _uow.product.GetFirstOrDefault(p => p.Id == cartObj.ProductId, includeProperties: "Category,CoverType"); ShoppingCard shoppingCard = new ShoppingCard() { Product = product, ProductId = product.Id }; return(View(shoppingCard)); } }
public bool SaveBasket(ShoppingCard basket) { var ctx = HttpContext.Current; if (ctx != null) { try { var currentData = ((ShoppingCard[])ctx.Cache[CacheKey]).ToList(); currentData.Add(basket); ctx.Cache[CacheKey] = currentData.ToArray(); return(true); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } } return(false); }
public ShoppingCardRepository() { var ctx = HttpContext.Current; if (ctx != null) { if (ctx.Cache[CacheKey] == null) { var basket = new ShoppingCard[] { new ShoppingCard { Id = 1, Quantity = 2 }, new ShoppingCard { Id = 2, Quantity = 34 } }; ctx.Cache[CacheKey] = basket; } } }
public async Task UpdateItem(ShoppingCard shoppingCard) { dataContext.Update(shoppingCard); await dataContext.SaveChangesAsync(); }
public ShoppingCardSummary(ShoppingCard shoppingCard) { _shoppingCard = shoppingCard; }
public HttpResponseMessage AddToCart(int id) { var checkcake = _context.Cakes.SingleOrDefault(c => c.Id == id); var thecake = _context.ShoppingCards.SingleOrDefault(c => c.Name == checkcake.Name); //var addQuantityCake = _context.ShoppingCards.SingleOrDefault(c => c.Id == id); if (checkcake == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } if (thecake == null) { ShoppingCard item = new ShoppingCard(); item.Name = checkcake.Name; item.Calories = checkcake.Calories; item.InStock = checkcake.InStock == 0 ? 1 : checkcake.InStock; item.Id = id; item.Price = checkcake.Price; item.Quantity = 1; _context.ShoppingCards.Add(item); _context.SaveChanges(); _context.ShoppingCards.ToList(); //_context.ShoppingCards.ToList().Count; } else { if (thecake.Quantity + 1 >= thecake.InStock) { thecake.Quantity = thecake.InStock - 1; // ALWAYS BE 1 _context.SaveChanges(); return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } else { thecake.Quantity++; } _context.SaveChanges(); } // if (addQuantityCake == null) // { // ShoppingCard cake = new ShoppingCard(); // // cake.Name = checkcake.Name; // cake.Calories = checkcake.Calories; // cake.InStock = checkcake.InStock == 0 ? 1 : checkcake.InStock; // // // item.Id = checkcake.Id; // cake.Price = checkcake.Price; // cake.Quantity = 1; // // _context.ShoppingCards.Add(cake); // _context.SaveChanges(); // } // else // { // addQuantityCake.Quantity += 1; // _context.SaveChanges(); // } return(new HttpResponseMessage(HttpStatusCode.OK)); }
public async Task AddItemToBox(ShoppingCard shoppingCard) { await dataContext.ShoppingCards.AddAsync(shoppingCard); await dataContext.SaveChangesAsync(); }