Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        //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));
        }
Exemplo n.º 11
0
        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());
            }
        }
Exemplo n.º 12
0
        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());
            }
        }
Exemplo n.º 13
0
        public ActionResult Purchase(string customer_id)
        {
            List <AllItemList> returnListofitems = PurchaseHistory.allhistory(customer_id);

            ViewBag.Products = returnListofitems;
            return(View());
        }
Exemplo n.º 14
0
        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();
        }
Exemplo n.º 15
0
        public ActionResult DeleteConfirmed(int id)
        {
            PurchaseHistory purchaseHistory = db.PurchaseHistories.Find(id);

            db.PurchaseHistories.Remove(purchaseHistory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 16
0
 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));
 }
Exemplo n.º 19
0
 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));
        }
Exemplo n.º 21
0
        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));
        }
Exemplo n.º 23
0
        public async Task <IHttpActionResult> GetPurchaseHistory(int id)
        {
            PurchaseHistory purchaseHistory = await db.PurchaseHistories.FindAsync(id);

            if (purchaseHistory == null)
            {
                return(NotFound());
            }

            return(Ok(purchaseHistory));
        }
Exemplo n.º 24
0
        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));
        }
Exemplo n.º 26
0
 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));
     }
 }
Exemplo n.º 28
0
        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));
     }
 }
Exemplo n.º 30
0
 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));
 }