Esempio n. 1
0
        // not mapped
        // handle duplicates outside
        // simple version that deals with one type of pack only
        public async Task <AppOrder> AddOneOrder(int quantity, AppOrder order)
        {
            // Order table

            var newOrder = new Order
            {
                OrderId = order.OrderId,
                UserId  = order.OrdererId,
                Date    = order.Date,
                Total   = order.Total,
            };
            await _context.Orders.AddAsync(newOrder);

            await _context.SaveChangesAsync();

            // OrderItem table
            // order packA quan 2
            // order packB quan 3
            // for loop
            var newOrderItem = new OrderItem
            {
                OrderId = order.OrderId,
                PackId  = order.PackId,
                PackQty = quantity,
            };
            await _context.OrderItems.AddAsync(newOrderItem);

            await _context.SaveChangesAsync();

            return(order);
        }
Esempio n. 2
0
        /// <summary>
        /// Enter a Trade into the db
        /// </summary>
        /// <param name="appTrade"></param>
        /// <returns>returns the trade that was entered for error handling</returns>
        public async Task <AppTrade> AddOneTrade(AppTrade appTrade)
        {
            var dbTrade = new Trade
            {
                TradeId   = appTrade.TradeId,
                OffererId = appTrade.OffererId,
                //BuyerId = appTrade.Buyer.UserId,
                IsClosed  = appTrade.IsClosed,
                TradeDate = appTrade.TradeDate,
            };
            await _context.Trades.AddAsync(dbTrade);

            await _context.SaveChangesAsync();

            var dbTradeDetail = new TradeDetail
            {
                TradeId     = appTrade.TradeId,
                OfferCardId = appTrade.OfferCardId,
                //BuyerCardId = appTrade.BuyerCardId
            };
            await _context.TradeDetails.AddAsync(dbTradeDetail);

            await _context.SaveChangesAsync();

            return(appTrade);
        }
Esempio n. 3
0
        public async Task AddOneUser(AppUser user)
        {
            var newUser = DomainDataMapper.AddOneUser(user);
            await _context.Customers.AddAsync(newUser);

            await _context.SaveChangesAsync();
        }
        //[Authorize(Roles = "Admin")]
        public async Task <IActionResult> Create([Bind("Age,Attrition,BusinessTravel,DailyRate,Department,DistanceFromHome,Education,EducationField,EmployeeCount,EmployeeNumber,EnvironmentSatisfaction,Gender,HourlyRate,JobInvolvement,JobLevel,JobRole,JobSatisfaction,MaritalStatus,MonthlyIncome,MonthlyRate,NumCompaniesWorked,Over18,OverTime,PercentSalaryHike,PerformanceRating,RelationshipSatisfaction,StandardHours,StockOptionLevel,TotalWorkingYears,TrainingTimesLastYear,WorkLifeBalance,YearsAtCompany,YearsInCurrentRole,YearsSinceLastPromotion,YearsWithCurrManager")] Cmpg323Project2Dataset cmpg323Project2Dataset)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cmpg323Project2Dataset);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cmpg323Project2Dataset));
        }
Esempio n. 5
0
        //Create an auction
        public async Task <bool> CreateAuction(AppAuction auction)
        {
            if (auction == null)
            {
                return(false);
            }
            else
            {
                //create db objects
                var dbAuction = new Auction
                {
                    AuctionId = auction.AuctionId,
                    SellerId  = auction.SellerId,
                    BuyerId   = auction.BuyerId,
                    CardId    = auction.CardId,
                    PriceSold = auction.PriceSold,
                    SellDate  = auction.SellDate
                };
                var dbAuctionDetail = new AuctionDetail
                {
                    AuctionId   = auction.AuctionId,
                    PriceListed = auction.PriceListed,
                    BuyoutPrice = auction.BuyoutPrice,
                    NumberBids  = auction.NumberBids,
                    SellType    = auction.SellType,
                    ExpDate     = auction.ExpDate
                };

                //Add to db
                try
                {
                    await _context.Auctions.AddAsync(dbAuction);

                    await _context.AuctionDetails.AddAsync(dbAuctionDetail);

                    await _context.SaveChangesAsync();

                    return(true);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Error Creating Auction: " + e);
                }
            }

            return(false);
        }
Esempio n. 6
0
        // need to handle duplicate outside
        public async Task AddOneCard(AppCard card)
        {
            var dbCard = await _context.Cards.FirstOrDefaultAsync(x => x.CardId == card.CardId);

            //only add to Cards if it does not yet exist
            if (dbCard == null)
            {
                var newCard = DomainDataMapper.AddOneCard(card);
                await _context.Cards.AddAsync(newCard);

                await _context.SaveChangesAsync();
            }
        }
Esempio n. 7
0
        //Update pack by id
        //add if manager adds more stock
        //sub if user purchases a pack to decrease stock
        public async Task <bool> UpdateStoreItemById(string id, int amount)
        {
            var pack = await _context.StoreInventories.FirstOrDefaultAsync(x => x.PackId == id);

            if (pack == null)
            {
                return(false);
            }

            try
            {
                pack.PackQty = amount;
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Try to Update Store Qty Exception: " + e);
            }

            return(false);
        }