public List <BazaarList> GetBazaarListById(int memberId) { SqlConnection connection = new SqlConnection(databaseConString); string query = "select * from tbl_Members as m inner join tbl_Users as u on m.user_id = u.u_id join tbl_BazaarLists as bl on bl.member_id = m.m_id WHERE member_id = +'" + memberId + "'"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <BazaarList> userBazaarList = new List <BazaarList>(); int serialNo = 1; while (reader.Read()) { BazaarList aBazaarList = new BazaarList(); aBazaarList.SerialNo = serialNo++; aBazaarList.MemberName = reader["user_name"].ToString(); aBazaarList.MemberEmail = reader["email"].ToString(); aBazaarList.BazaarDate = reader["bazaar_date"].ToString(); userBazaarList.Add(aBazaarList); } reader.Close(); connection.Close(); return(userBazaarList); }
public void AddToBazaar(BazaarItemDTO bazaarItem) { // we are not supposed to save each addition! we will only save them on Save() function. // that might be hard to overcome i guess... // we should never add more than 1 instance of iteminstance to bazaar! if (bazaarItem != null && !BazaarList.Any(s => s.BazaarItem.ItemInstanceId.Equals(bazaarItem.ItemInstanceId))) { ItemInstance item = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bazaarItem.ItemInstanceId)); string name = DAOFactory.CharacterDAO.LoadById(bazaarItem.SellerId)?.Name; if (item != null && !string.IsNullOrEmpty(name)) { BazaarList[bazaarItem.BazaarItemId] = new BazaarItemLink() { BazaarItem = bazaarItem, Item = item, OwnerName = name }; // we will propably need to also update the iteminstance. } } else { // log or return something } }
public void Save() { // this will need extensive testing, it needs to be the most stable piece of code in the // entire project! // add foreach (BazaarItemLink link in BazaarList.GetAllItems()) { if (DAOFactory.BazaarItemDAO.LoadById(link.BazaarItem.BazaarItemId) == null) { BazaarItemDTO item = link.BazaarItem; DAOFactory.BazaarItemDAO.InsertOrUpdate(ref item); DAOFactory.ItemInstanceDAO.InsertOrUpdate(link.Item); } } // remove foreach (BazaarItemDTO item in DAOFactory.BazaarItemDAO.LoadAll()) { if (!BazaarList.Any(s => s.BazaarItem.ItemInstanceId.Equals(item.ItemInstanceId))) { DAOFactory.BazaarItemDAO.Delete(item.BazaarItemId); DAOFactory.ItemInstanceDAO.Delete(item.ItemInstanceId); } } DAOFactory.BazaarItemDAO.RemoveOutDated(); }
protected void AddBazaarListButton_Click(object sender, EventArgs e) { BazaarList aBazaarList = new BazaarList(); aBazaarList.MemberId = int.Parse(memberNameDropDownList.SelectedValue); aBazaarList.BazaarDate = Request.Form["bazaarDateTextBox"]; message.Text = aBazaarListManager.SaveBazaarList(aBazaarList); }
public async Task <BazaarList> Create(CreateBazaarList input) { BazaarList newBazaarList = BazaarList.Create(input.Title, input.Description, input.CreatorUserId); await _context.BazaarLists.AddAsync(newBazaarList); await _context.SaveChangesAsync(); return(newBazaarList); }
public string SaveBazaarList(BazaarList aBazaarList) { if (aBazaarListGateway.SaveBazaarList(aBazaarList) > 0) { return("Added Successfully"); } else { return("Could Not Added!"); } }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { BazaarList.Dispose(); } _disposed = true; } }
public async Task GetAll() { var getResponse = new BazaarList(); await CreateFirst(); // GetAll service test var getAll = await service.GetAll(); getResponse = getAll.First(); Assert.Equal(1, await inMemoryContext.BazaarLists.CountAsync()); Assert.Equal("Test_Baslik", getResponse.Title); Assert.Equal("Test_Aciklama", getResponse.Description); }
public async Task Get() { var getResponse = new BazaarList(); await CreateFirst(); var firstData = await inMemoryContext.BazaarLists.FirstAsync(); getResponse = await service.Get(firstData.Id); Assert.Equal(1, await inMemoryContext.BazaarLists.CountAsync()); Assert.Equal("Test_Baslik", getResponse.Title); Assert.Equal("Test_Aciklama", getResponse.Description); }
public int SaveBazaarList(BazaarList aBazaarList) { SqlConnection connection = new SqlConnection(databaseConString); string query = "INSERT INTO tbl_BazaarLists VALUES ('" + aBazaarList.MemberId + "','" + aBazaarList.BazaarDate + "')"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); int dbRowAffected = command.ExecuteNonQuery(); connection.Close(); return(dbRowAffected); }
public void RemoveFromBazaar(long bazaarItemId) { // we are not supposed to save each removal! we will only save them on Save() function. // there should never be 2 objects with same id in the bazaar! BazaarItemLink bazaaritem = BazaarList.SingleOrDefault(s => s.BazaarItem.BazaarItemId.Equals(bazaarItemId)); if (bazaaritem != null) { BazaarList.Remove(bazaaritem); // we will propably need to also update the iteminstance. } else { // something is wrong, log as suspicious activity or some kind of weird behavior. the // item if sent by game should always be in the BazaarList, unless it was somehow // bought before the client got updated info. } }
public void RefreshBazaar(long bazaarItemId) { BazaarItemDTO bzdto = DAOFactory.BazaarItemDAO.LoadById(bazaarItemId); BazaarItemLink bzlink = BazaarList[bazaarItemId]; // maybe we shouldnt lock the entire list. lock (BazaarList) { if (bzdto != null) { CharacterDTO chara = DAOFactory.CharacterDAO.LoadById(bzdto.SellerId); if (bzlink != null) { // why do we do this update? this is a copy of code from ServerManager BazaarList.Remove(bzlink); bzlink.BazaarItem = bzdto; bzlink.OwnerName = chara.Name; bzlink.Item = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bzdto.ItemInstanceId)); BazaarList[bazaarItemId] = bzlink; } else { BazaarItemLink item = new BazaarItemLink { BazaarItem = bzdto }; if (chara != null) { item.OwnerName = chara.Name; item.Item = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bzdto.ItemInstanceId)); } BazaarList[bazaarItemId] = item; } } else if (bzlink != null) { BazaarList.Remove(bzlink); } } InBazaarRefreshMode = false; }