public async Task <IActionResult> PostPurchaseHistory([FromBody] PurchaseHistory purchaseHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.PurchaseHistory.Add(purchaseHistory); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (PurchaseHistoryExists(purchaseHistory.UserId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetPurchaseHistory", new { id = purchaseHistory.UserId }, purchaseHistory)); }
public async Task <IActionResult> PutPurchaseHistory([FromRoute] int id, [FromBody] PurchaseHistory purchaseHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != purchaseHistory.UserId) { return(BadRequest()); } _context.Entry(purchaseHistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PurchaseHistoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Purchase(int id, int quant) { if (Session["username"] == null) { TempData["Error"] = "You have to Login to Purchase Product"; return(RedirectToAction("Login", "Account")); } else if ((bool)Session["is_admin"]) { return(Redirect("/")); } Product p = repo.GetById(id); if (p.Quantity <= 1) { TempData["message"] = "Insufficient Item!"; return(Redirect("/Purchase/Index/" + id)); } IRepository <User> user = new UserRepository(new MobileMineContext()); PurchaseHistory ph = new PurchaseHistory(); ph.BuyerId = (int)Session["user_id"]; ph.Date = System.DateTime.Now; ph.Price = p.Price * quant; ph.ProductId = p.Id; p.Quantity -= quant; MobileMineContext mmc = new MobileMineContext(); mmc.PurchaseHistories.Add(ph); mmc.SaveChanges(); repo.Update(p); repo.Submit(); TempData["message"] = "Purchase Successful!"; return(Redirect("/Purchase/Index/" + id)); }
public async Task <bool> BuyItem(PurchaseHistory purchase) { Purchasehistory purchasehistory = new Purchasehistory(); if (purchase != null) { purchasehistory.Id = purchase.purchaseId; purchasehistory.Bid = purchase.buyerId; purchasehistory.Transactiontype = purchase.transactionType; purchasehistory.Itemid = purchase.itemId; purchasehistory.Noofitems = purchase.noOfItems; purchasehistory.Datetime = purchase.dateTime; purchasehistory.Remarks = purchase.remarks; purchasehistory.Transactionstatus = purchase.transactionStatus; } _context.Purchasehistory.Add(purchasehistory); var buyitem = await _context.SaveChangesAsync(); if (buyitem > 0) { return(true); } else { return(false); } }
public async Task <List <PurchaseHistory> > Purchase(PurchaseHistory purchaseHistory) { Buyer buyer = _context.Buyer.Find(purchaseHistory.buyerId); if (buyer == null) { return(null); } else { List <Purchasehistory> purchasehistories = await _context.Purchasehistory.Where(e => e.Bid == buyer.Bid).ToListAsync(); if (purchasehistories == null) { return(null); } else { List <PurchaseHistory> purchaseHistories = purchasehistories.Select(s => new PurchaseHistory { purchaseId = s.Id, buyerId = s.Bid, transactionType = s.Transactiontype, itemId = s.Itemid, noOfItems = s.Noofitems, dateTime = s.Datetime, remarks = s.Remarks, transactionStatus = s.Transactionstatus, }).ToList(); return(purchaseHistories); } } }
public async Task <IHttpActionResult> PutPurchaseHistory(int id, PurchaseHistory purchaseHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != purchaseHistory.Id) { return(BadRequest()); } db.Entry(purchaseHistory).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PurchaseHistoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
//Does the same but for the items in the purchase history public static List <CHProduct> GetHistoryItems(string username) { List <CHProduct> products = new List <CHProduct>(); if (dbConnection != null && dbConnection.State == ConnectionState.Closed) { dbConnection.Open(); } UserAccount user = GetUser(username); PurchaseHistory history = GetPurchaseHistory(user.userID); List <HistoryItems> items = GetUserHistory(history.purchaseHistoryID); foreach (HistoryItems item in items) { CHProduct chProduct = new CHProduct(); chProduct.quantity = item.quantity; Product product = GetProduct(item.productID); chProduct.productID = product.productID; chProduct.productName = product.productName; chProduct.productManufacturer = product.productManufacturer; chProduct.productPrice = product.productPrice; chProduct.productImage = product.productImage; products.Add(chProduct); } dbConnection.Close(); return(products); }
public ResponsePurchaseHistory Profiles(PurchaseHistory historyItem) { List <PurchaseHistory> listHistory = new List <PurchaseHistory>(); try { var list = db.sp_HistorPerUser(historyItem.NIP).ToList(); foreach (var item in list) { historyItem = new PurchaseHistory(); historyItem.OrderNo = item.OrderNo; historyItem.OutletNo = item.OutletNo; historyItem.TransactionDate = item.TransactionDate; historyItem.Liter = item.Liter; historyItem.ExpiredDate = item.ExpiredDate; listHistory.Add(historyItem); } return(new ResponsePurchaseHistory { status = "success", message = "List Purchase History", Data = listHistory }); } catch (Exception e) { Logging.Log.getInstance().CreateLogError(e, JsonConvert.SerializeObject(listHistory)); return(new ResponsePurchaseHistory { status = "failed", message = e.Message }); } }
public ActionResult Buy(int id) { int quant = 1; BakeryContext mmc = new BakeryContext(); Item p = repo.GetById(id); if (p.Quantity <= 1) { ViewBag.Message = "Not enough item"; return(View()); } IRepository <User> user = new UsersRepository(new BakeryContext()); PurchaseHistory ph = new PurchaseHistory(); ph.BuyerId = (int)Session["user_id"]; ph.Date = System.DateTime.Now; ph.Price = p.Price * quant; ph.ProductId = p.Id; p.Quantity -= quant; mmc.PurchaseHistories.Add(ph); mmc.SaveChanges(); repo.Update(p); repo.Submit(); ViewBag.Message = "Purchase sucessful"; return(View()); }
public async Task <IActionResult> Edit(int id, [Bind("Id,CustomerName,PurchasedFood,Quantity,TotalPrice")] PurchaseHistory purchaseHistory) { if (id != purchaseHistory.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(purchaseHistory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PurchaseHistoryExists(purchaseHistory.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(purchaseHistory)); }
private void HistoryListView_SelectedIndexChanged(object sender, EventArgs e) { try { int id = historyListView.SelectedItems[0].Text.ToInt(-1); itemListView.Items.Clear(); List <ListViewItem> listViewItems = new List <ListViewItem>(); PurchaseHistory purchaseHistory = _customer.PurchaseHistory.Find(x => x.Purchase.Id == id); foreach (PurchaseDetails purchaseDetails in purchaseHistory.PurchaseDetails) { listViewItems.Add(new ListViewItem(new[] { purchaseDetails.PurchaseItem.ItemId.ToString(), purchaseDetails.Name, purchaseDetails.PurchaseItem.Price.ToString(), purchaseDetails.PurchaseItem.Quantity.ToString(), purchaseDetails.PurchaseItem.SubTotal.ToString() })); } itemListView.Items.AddRange(listViewItems.ToArray()); } catch (Exception ex) { itemListView.Items.Clear(); Logger.log.Error(ex.ToString()); } }
public IActionResult AddtoCart(int ItemsId) { if (ModelState.IsValid) { if (db_context.PurchaseHistory.Where(o => o.ItemsId == ItemsId && o.UserInfoId == 1 && o.IsPurchased == false).Count() == 0) { PurchaseHistory ph = new PurchaseHistory(); ph.ItemsId = ItemsId; ph.UserInfoId = 1; ph.Quantity = 1; ph.IsPurchased = false; db_context.PurchaseHistory.Add(ph); db_context.SaveChanges(); } else { PurchaseHistory ph = db_context.PurchaseHistory.Where(o => o.ItemsId == ItemsId && o.UserInfoId == 1 && o.IsPurchased == false).FirstOrDefault(); ph.Quantity = ph.Quantity + 1; db_context.SaveChanges(); } return(RedirectToAction("Cart")); } else { return(View()); } }
public ActionResult Purchase(string customer_id) { List <AllItemList> returnListofitems = PurchaseHistory.allhistory(customer_id); ViewBag.Products = returnListofitems; return(View()); }
public async Task <PurchaseHistory> BuyCart(int accountid, List <PurchaseItem> cookieList) { using (CookieShopDbContext context = _contextFactory.CreateDbContext()) { var account = await context.Accounts.FirstAsync((e) => e.Id == accountid); // var cookiedb = (await context.Cookies.FirstAsync((e) => e.Id == cookie.Id)); var boughtCookies = new PurchaseHistory() { //Cookie = cookiedb, //Amount = amount, Items = cookieList, AccountId = accountid, DateProcessed = DateTime.Now, IsPurchase = true }; var result = await context.PurchaseHistory.AddAsync(boughtCookies); foreach (var cookie in cookieList) { var cookiedb = (await context.Cookies.FirstAsync((e) => e.Id == cookie.CookieId)); var stock = await context.Stocks.FirstOrDefaultAsync((e) => e.Cookie.Id == cookie.CookieId); stock.Amount--; account.Balance -= cookiedb.Price * cookie.Amount; } context.SaveChanges(); return(result.Entity); } //throw new NotImplementedException(); }
public ActionResult DeleteConfirmed(int id) { PurchaseHistory purchaseHistory = db.PurchaseHistories.Find(id); db.PurchaseHistories.Remove(purchaseHistory); db.SaveChanges(); return(RedirectToAction("Index")); }
public static bool SetPurchaseHistory(PurchaseHistory content) { if (Content == null || content == null) { return(false); } Content = content; return(true); }
public ActionResult Edit([Bind(Include = "pId,typeId,pName,pDetail,pPrice,pImage,pTexture,XS,S,M,L,XL,Date")] PurchaseHistory productStore) { if (ModelState.IsValid) { db.Entry(productStore).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productStore)); }
public ActionResult Edit([Bind(Include = "CustomerID")] PurchaseHistory purchaseHistory) { if (ModelState.IsValid) { db.Entry(purchaseHistory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(purchaseHistory)); }
public static PurchaseHistoryModel Map(this PurchaseHistory source) { return(new PurchaseHistoryModel { Id = source.Id, ProductId = source.ProductId, CreatedOn = source.CreatedOn, Quantity = source.Quantity, UserId = source.UserId }); }
public ActionResult Create([Bind(Include = "pId,typeId,pName,pDetail,pPrice,pImage,pTexture,XS,S,M,L,XL,Date")] PurchaseHistory productStore) { if (ModelState.IsValid) { db.ProductStores.Add(productStore); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productStore)); }
public async Task <IActionResult> Create([Required][FromBody] JObject body) { if (body["name"] == null) { return(this.errorBadRequest("purchasehistories name is required")); } PurchaseHistory purchasehistory = new PurchaseHistory(); await _purchasehistoryService.CreateAsync(purchasehistory); return(this.successRequest(purchasehistory)); }
public async Task <IActionResult> Create([Bind("Id,CustomerName,PurchasedFood,Quantity,TotalPrice")] PurchaseHistory purchaseHistory) { if (ModelState.IsValid) { _context.Add(purchaseHistory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(purchaseHistory)); }
public async Task <IHttpActionResult> GetPurchaseHistory(int id) { PurchaseHistory purchaseHistory = await db.PurchaseHistories.FindAsync(id); if (purchaseHistory == null) { return(NotFound()); } return(Ok(purchaseHistory)); }
public static async Task <PurchaseHistory> GetPurchaseHistory() { try { await semaphore.WaitAsync(); if (Content != null) { return(Content); } if (!System.IO.File.Exists(Path)) { return(Content = new PurchaseHistory()); } try { Content = await SerializationHelper.DeserializeAsync <PurchaseHistory>(Path); if (Content != null) { return(Content); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(String.Format("Failed to load'{0}'", Path)); System.Diagnostics.Debug.WriteLine(e.Message); } try { Content = await SerializationHelper.DeserializeAsync <PurchaseHistory>(PathBup); if (System.IO.File.Exists(Path)) { System.IO.File.Delete(Path); } if (System.IO.File.Exists(PathBup)) { System.IO.File.Move(PathBup, Path); } return(Content = Content ?? new PurchaseHistory()); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(String.Format("Failed to load'{0}'", PathBup)); System.Diagnostics.Debug.WriteLine(e.Message); } return(Content = new PurchaseHistory()); } finally { semaphore.Release(); } }
public ActionResult Create([Bind(Include = "CustomerID")] PurchaseHistory purchaseHistory) { if (ModelState.IsValid) { db.PurchaseHistory.Add(purchaseHistory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(purchaseHistory)); }
private void Window_Loaded(object sender, RoutedEventArgs e) { // TODO: Fetch data and load it into the data grid //Get order/purchase history if (Account.IsLoggedIn) { PurchaseHistory history = new PurchaseHistory(); history.GetPurchaseInfo(Account.currentUser.Username); this.listPurchaseHistory.ItemsSource = history.PurchaseHistoryList; } }
public IActionResult BuyItem(PurchaseHistory item) { try { _repo.BuyItem(item); return(Ok()); } catch (Exception e) { return(NotFound(e.InnerException.Message)); } }
public async Task <IHttpActionResult> PostPurchaseHistory(PurchaseHistory purchaseHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.PurchaseHistories.Add(purchaseHistory); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = purchaseHistory.Id }, purchaseHistory)); }
public IActionResult Additem(PurchaseHistory obj) { try { _repo.Additem(obj); return(Ok()); } catch (Exception e) { return(NotFound(e.InnerException.Message)); } }
public ActionResult Edit([Bind(Include = "Id,Price,Date,ProductId,BuyerId")] PurchaseHistory purchaseHistory) { if (ModelState.IsValid) { db.Entry(purchaseHistory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductId = new SelectList(db.Items, "Id", "Name", purchaseHistory.ProductId); ViewBag.BuyerId = new SelectList(db.Users, "Id", "Username", purchaseHistory.BuyerId); return(View(purchaseHistory)); }