public async Task UpdateBuyListAsync(BuyList updateBuyList) { var entry = _context.Attach(updateBuyList); entry.State = EntityState.Modified; await _context.SaveChangesAsync(); }
public IActionResult List(String Act, int ItemId, int CategoryId) { UserItems uI = new UserItems(); uI.MyItems = _context.Items.OrderBy(x => x.ItemId).ToList(); uI.TheName = HttpContext.Session.GetString("UserName"); uI.TheRole = HttpContext.Session.GetString("UserRole"); if (uI.TheName != null) { Item item = _context.Items.FirstOrDefault(x => x.ItemId == ItemId); int userId = Convert.ToInt32(HttpContext.Session.GetString("UserId")); bool has = _iLikedListRepository.HasList(userId, ItemId); if (Act == "Like") { LikedList likedList = new LikedList { CategoryId = CategoryId, ItemId = ItemId, likedItems = new List <Item> { item }, UserId = userId }; _context.LikedItems.Add(likedList); _context.SaveChanges(); } if (Act == "Buy") { BuyList BuyList = new BuyList { CategoryId = CategoryId, ItemId = ItemId, BuyItemLists = new List <Item> { item }, UserId = userId }; _context.BuyListItems.Add(BuyList); _context.SaveChanges(); } } else { return(RedirectToAction("Login", "Main")); } return(View(uI)); }
public async Task <BuyList> InsertBuyListAsync(BuyList newBuyList) { _context.BuyList.Add(newBuyList); await _context.SaveChangesAsync(); return(newBuyList); }
public void MakeDeals(List <SharePacket> buy, List <SharePacket> sell)// DODELAT { int i = 0; int j = 0; while (i < buy.Count && j < sell.Count) { if (buy[i].Owner != null && buy[i].Owner == sell[j].Owner) { i++; continue; } if (buy[i].Price < sell[j].Price) { break; } var qty = Math.Min(buy[i].CurrentQuantity, sell[j].CurrentQuantity); buy[i].CurrentQuantity -= qty; sell[j].CurrentQuantity -= qty; if (buy[i].Owner == Player.Current.Name) { var price = Math.Min(buy[i].Price, sell[j].Price); OnBuy(buy[i], qty, price); } else if (sell[j].Owner == Player.Current.Name) { var price = Math.Min(buy[i].Price, sell[j].Price); OnSell(sell[j], qty, price); } else { CompaniesList.List[CompaniesList.FindNumber(sell[j].CompanyName)].CurrentQuantity += qty; } if (buy[i].CurrentQuantity == 0) { i++; continue; } if (sell[j].CurrentQuantity == 0) { j++; continue; } } foreach (var packet in buy) { BuyList.List.Add(packet); } BuyList.RemoveEmptyEntries(); foreach (var packet in sell) { SellList.List.Add(packet); } SellList.RemoveEmptyEntries(); }
public async Task <ActionResult <BuyList> > Post([FromBody] BuyList value) { if (value == null) { return(BadRequest()); } await _buyListInterface.InsertBuyListAsync(value); return(CreatedAtAction(nameof(GetAsync), new { id = value.Id }, value)); }
public void SyncLists() { if (SellList.List.Count != 0 && BuyList.List.Count != 0) { List <string> companies = SellList.ReturnAllCompanies(); foreach (var companyName in companies) { var buy = BuyList.GetPackets(companyName); var sell = SellList.GetPackets(companyName); MakeDeals(buy, sell); } } }
public IActionResult BuyList(String Act, int ItemId, int CategoryId) { UserItems uI = new UserItems(); uI.MyItems = _context.Items.OrderBy(x => x.ItemId).ToList(); uI.TheName = HttpContext.Session.GetString("UserName"); uI.TheRole = HttpContext.Session.GetString("UserRole"); if (uI.TheName != null) { Item item = _context.Items.FirstOrDefault(x => x.ItemId == ItemId); int userId = Convert.ToInt32(HttpContext.Session.GetString("UserId")); bool has = _iBuyListReository.HasList(userId, ItemId); if (Act == "Like" && !has) { LikedList LikedList = new LikedList { CategoryId = CategoryId, ItemId = ItemId, likedItems = new List <Item> { item }, UserId = userId }; _context.LikedItems.Add(LikedList); _context.SaveChanges(); } if (Act == "Delete") { BuyList items = _context.BuyListItems.Where(x => x.UserId == userId && x.ItemId == ItemId).FirstOrDefault(); _context.BuyListItems.Remove(items); _context.SaveChanges(); } } return(RedirectToAction("BuyList")); }
public async Task <IActionResult> Put([FromBody] BuyList value) { if (value == null) { return(BadRequest()); } try { await _buyListInterface.UpdateBuyListAsync(value); return(RedirectToAction("BuyList", new { id = value.Id })); } catch { string response = "Nem sikerült a változtatás"; return(StatusCode(StatusCodes.Status500InternalServerError, response)); } }
public void CreateBuyOfferings() { Random rnd = new Random(); foreach (SharePacket cmp in CompaniesList.List) { decimal coeff = 1 / CheckReferences(cmp); if (coeff > 4) { coeff = 4; } if (coeff < 0.25m) { coeff = 0.25m; } decimal border = 20 * coeff; decimal chance = rnd.Next(1, 101); while (chance <= border) { int amount = -1; int quantity = cmp.Quantity / 4; amount = rnd.Next(1, quantity + 1); if (BuyList.FindNumber(cmp.CompanyName) > 0) { decimal price = BuyList.List[BuyList.FindNumber(cmp.CompanyName)].Price * rnd.Next(95, 120) / 100m; GenerateBuyOffering(cmp.CompanyName, Math.Round(price, 2), amount, null); } else { GenerateBuyOffering(cmp.CompanyName, Math.Round((cmp.Price * rnd.Next(900, 1100) / 1000m), 2), amount, null); } Thread.Sleep(3); chance = rnd.Next(1, 101); } } }
public static ClientBasePacket HandlePacket(byte[] data, int offset, GameSession client) { // Calculate message size var size = (short)((data[offset + 1] << 8) + data[offset]); // Copy the packet to a new byte array // Skipping the header var packet = new byte[size]; Array.Copy(data, offset, packet, 0, size); ClientBasePacket msg; // Get the id var id = packet[2]; // Handle the packet // TODO: Can we group these into login / game / etc? switch (id) { case 0x00: msg = new ProtocolVersion(packet, client); break; case 0x01: msg = new ValidateClient(packet, client); break; case 0x03: msg = new ConnectClient(packet, client); break; case 0x04: msg = new ConnectSwitch(packet, client); break; case 0x05: msg = new SwitchServer(packet, client); break; case 0x06: msg = new ServerTime(packet, client); break; case 0x07: msg = new Message(packet, client); break; case 0x0d: msg = new Log(packet, client); break; case 0x0c: msg = new SyncMoney(packet, client); break; case 0x11: msg = new FactoryModifyUnit(packet, client); break; case 0x12: msg = new FactoryModifyEnd(packet, client); break; case 0x16: msg = new IsValidName(packet, client); break; case 0x17: msg = new FactoryChangeUnitName(packet, client); break; case 0x18: msg = new RequestInventory(packet, client); break; case 0x19: msg = new RequestSearchGame(packet, client); break; case 0x1b: msg = new CreateGame(packet, client); break; case 0x1c: msg = new EnterGame(packet, client); break; case 0x1f: msg = new ListUser(packet, client); break; case 0x20: msg = new Ready(packet, client); break; case 0x21: msg = new Exit(packet, client); break; case 0x22: msg = new StartGame(packet, client); break; case 0x2b: msg = new SelectBase(packet, client); break; case 0x2c: msg = new ReadyGame(packet, client); break; case 0x2e: msg = new RequestPalette(packet, client); break; case 0x2f: msg = new MoveUnit(packet, client); break; case 0x30: msg = new AimUnit(packet, client); break; case 0x31: msg = new StartAttack(packet, client); break; case 0x32: msg = new StopAttack(packet, client); break; case 0x35: msg = new RequestRegain(packet, client); break; case 0x38: msg = new ModeSniper(packet, client); break; case 0x3a: msg = new RequestChangeWeaponset(packet, client); break; case 0x3b: msg = new RequestQuitBattle(packet, client); break; case 0x3f: msg = new BuyList(packet, client); break; case 0x40: msg = new RequestGoodsData(packet, client); break; case 0x46: msg = new RequestAvatarInfo(packet, client); break; case 0x47: case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: msg = new RequestStatsInfo(packet, client); break; case 0x4e: msg = new RequestBestInfo(packet, client); break; case 0x57: msg = new TutorialSelect(packet, client); break; case 0x5a: msg = new UnAimUnit(packet, client); break; case 0x63: msg = new MsgConnect(packet, client); break; case 0x64: msg = new MsgUserStateInfo(packet, client); break; case 0x66: msg = new MsgUserClanInfo(packet, client); break; case 0x67: msg = new MsgGetBuddyList(packet, client); break; case 0x69: msg = new MsgGetChannelList(packet, client); break; case 0x6a: msg = new MsgJoinChannel(packet, client); break; case 0x6b: msg = new MsgLeaveChannel(packet, client); break; case 0x6c: msg = new MsgChannelChatting(packet, client); break; case 0x71: msg = new RequestOperator(packet, client); break; case 0x72: msg = new SelectOperator(packet, client); break; default: msg = new UnknownPacket(packet, client); //Console.WriteLine("Unknown packet id [{0}] from user {1}", id, client.GetUserName()); break; } return(msg); }
private File_Status_Is ProcessYCAValue() // BUY LIST IS INITIALLY CONSTRUCTED HERE, BUT NOT POPULATED { short ii = 0; if (this.has_yca_file == true) { foreach (string line in File.ReadLines(this.yearly_contribution_filepath)) { if (ii == 0) { string instr = CSVValues.parse_decimal_str(line), parsedstr = ""; int sii = (instr.Length - 2); foreach (char c in instr) { if (sii > 0) { parsedstr = parsedstr + c; } sii--; } try { int ycaint = Int32.Parse(parsedstr); this.buylist = new BuyList(ycaint); } catch (Exception ex) { Console.WriteLine("Failed to construct buylist from file " + this.yearly_contribution_filepath + " exception message: " + ex.Message); return(File_Status_Is.File_Found_but_Parse_Failed); } try { MYSQLEngine.WriteYCA(this.eq, parsedstr); return(File_Status_Is.File_Found_and_Parsed); } catch (Exception ex) { Console.WriteLine(ex.Message); return(File_Status_Is.Failed); } } ii++; } return(File_Status_Is.Failed); } else { this.buylist = new BuyList(Int32.Parse(MYSQLEngine.ReadYCA(this.eq))); return(File_Status_Is.No_File_Found); } }