Example #1
0
        // 7.4 MarketBuy
        private void JournalMarketBuy(string jstr)
        {
            MarketBuyEvent marketbuy = JsonConvert.DeserializeObject <MarketBuyEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Cargo Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate        = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        var       existingCargoValue = cargoUpdate.AvgPurchasePrice * cargoUpdate.Qty;
                        cargoUpdate.Qty = cargoUpdate.Qty + marketbuy.Count;
                        cargoUpdate.AvgPurchasePrice = (existingCargoValue + (marketbuy.BuyPrice * marketbuy.Count)) / cargoUpdate.Qty;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = marketbuy.Count, AvgPurchasePrice = marketbuy.BuyPrice, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate        = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        var       existingCargoValue = cargoUpdate.AvgPurchasePrice * cargoUpdate.Qty;
                        cargoUpdate.Qty = cargoUpdate.Qty + marketbuy.Count;
                        cargoUpdate.AvgPurchasePrice = (existingCargoValue + (marketbuy.BuyPrice * marketbuy.Count)) / cargoUpdate.Qty;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = marketbuy.Count, AvgPurchasePrice = marketbuy.BuyPrice, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
Example #2
0
        // 7.6 Miningrefined
        private void JournalMiningRefined(string jstr)
        {
            MiningRefinedEvent miningrefined = JsonConvert.DeserializeObject <MiningRefinedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Mined Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
Example #3
0
        // 7.5 MarketSell
        private void JournalMarketSell(string jstr)
        {
            MarketSellEvent marketsell = JsonConvert.DeserializeObject <MarketSellEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Cargo Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        CargoHold cargoitem = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        if (cargoitem.Qty == marketsell.Count)
                        {
                            //Remove item of cargo
                            db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.TradeID == cargoitem.TradeID));
                            db.SaveChanges();
                        }
                        else
                        {
                            //Update quantity of cargo
                            cargoitem.Qty = cargoitem.Qty - marketsell.Count;
                            db.SaveChanges();
                        }
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        CargoHold cargoitem = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        if (cargoitem.Qty == marketsell.Count)
                        {
                            //Remove item of cargo
                            db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.TradeID == cargoitem.TradeID));
                            db.SaveChanges();
                        }
                        else
                        {
                            //Update quantity of cargo
                            cargoitem.Qty = cargoitem.Qty - marketsell.Count;
                            db.SaveChanges();
                        }
                    }
                }
                db.Dispose();
            }
        }
Example #4
0
        // 7 Trade
        // 7.2 CollectCargo
        private void JournalCollectCargo(string jstr)
        {
            CollectCargoEvent collectcargo = JsonConvert.DeserializeObject <CollectCargoEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Cargo Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    // Commodity commod = db.Commodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record because record of matching stolen status not found
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = collectcargo.Stolen, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    // Commodity commod = db.Commodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record because record of matching stolen status not found
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = collectcargo.Stolen, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }