Ejemplo n.º 1
0
 public string Upsert(Buying o)
 {
     string result = string.Empty;
     if (null != o)
     {
         try
         {
             o.BuyerId = Credentials.UserId;
             if (o.BuyingOfferId > 0)
             {
                 BuyingFacade.UpdateOffer(o);
                 result = CommonResources.UpdateOfferSuccess;
             }
             else
             {
                 BuyingFacade.AddOffer(o);
                 result = CommonResources.AddOfferSuccess;
             }
         }
         catch (Exception e)
         {
             AssistLogger.Log<ExceptionHolder>(e);
             result = CommonResources.WebServices_Ajax_BuyingService_UpsertBuyingFailure;
         }
     }
     else
     {
         throw new NullReferenceException();
     }
     return result;
 }
Ejemplo n.º 2
0
 public static int AddSuggested(int buyingOfferId, int suggested)
 {
     int res = BuyingDataAdapter.AddSuggested(buyingOfferId, suggested);
       if (res == 1)
       {
     Selling o = new Selling().Load<Selling>(SellingDataAdapter.GetOfferById(suggested));
     Buying bo = new Buying().Load<Buying>(BuyingDataAdapter.GetOfferById(buyingOfferId));
     if (o != null && o.SellerId != Guid.Empty && bo != null && bo.BuyerId != Guid.Empty)
     {
       var u = UsersFacade.GetUser(o.SellerId);
       var msg = MessageFactory.CreateByTemplate(MessageTemplate.SellingSuggested, bo.BuyerId,
     null, new[] { o.Title, u == null ? string.Empty : u.UserName, bo.Title });
       MessageFacade.AddFromSystemUser(msg);
     }
       }
       return res;
 }
Ejemplo n.º 3
0
 static void AddSuggested(out Buying bo, out Selling o)
 {
     bo = AddOffer(null);
       var seller = UsersFacadeHelper.GetRandomUser(new[] {bo.BuyerId});
       o = SellingFacadeHelper.AddOffer(seller.UserId(), null);
       o.GameServerId = bo.GameServerId;
       SellingFacade.Update(o);
       Thread.Sleep(1000);
       int res = BuyingFacade.AddSuggested(bo.BuyingOfferId, o.SellingId);
       Assert.AreEqual(res, 1);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds new BuyingOffer object in the database with checking
        /// </summary>
        /// <returns>Returns the added BuyingOffer object</returns>
        private static Buying AddOffer(int? productCategoryId)
        {
            var buyer = UsersFacadeHelper.GetRandomUser(null);
              int serverId = DictionariesHelper.GetRandomDictionaryEntryId(DictionaryTypes.GameServer, GameServerFields.GameServerId);

              Guid key = Guid.NewGuid();

              Buying bo = new Buying();
              bo.BuyerId = buyer.UserId();
              bo.GameServerId = serverId;
              bo.Title = string.Format("Test add: title {0}", key);
              bo.Description = string.Format("Test add: description {0}", key);
              bo.Price = new Random((int)DateTime.Now.Ticks).Next(1, 10);
              bo.ProductCategoryId = productCategoryId.HasValue == true
            ? productCategoryId.Value
            : DictionariesHelper.GetRandomDictionaryEntryId(DictionaryTypes.ProductCategory, ProductCategoryFields.ProductCategoryId);
              if (bo.ProductCategoryId == 4)
              {
            bo.ProductCategoryMisc = "test product category";
              }
              int historyId = 0;
              Buying nbo = BuyingFacade.AddOffer(bo, out historyId);

              Assert.IsNotNull(nbo);

              Assert.GreaterOrEqual(historyId, 1);
              Assert.GreaterOrEqual(nbo.BuyingOfferId, 1);
              Assert.AreEqual(bo.BuyerId, nbo.BuyerId);
              Assert.AreEqual(bo.GameServerId, nbo.GameServerId);
              Assert.AreEqual(bo.Title, nbo.Title);
              Assert.AreEqual(bo.Description, nbo.Description);
              Assert.AreEqual(bo.Price, nbo.Price);
              Assert.AreNotEqual(nbo.CreateDate, DateTime.MinValue);
              Assert.AreEqual(bo.ProductCategoryId, nbo.ProductCategoryId);
              Assert.AreEqual(bo.ProductCategoryMisc, nbo.ProductCategoryMisc);
              return nbo;
        }
Ejemplo n.º 5
0
        public void TestSearchOffers()
        {
            Buying o = AddOffer(null);
              BuyingSearchFilter filter = new BuyingSearchFilter();
              //#1 search by game server Id
              filter.GameServerId = o.GameServerId;
              DataSet ds = BuyingFacade.SearchOffers(filter);
              Assert.GreaterOrEqual(ds.Tables[0].Rows.Count, 1);
              Assert.IsTrue(ds.Tables[0].Select().All(dr
              => new Buying().Load<Buying>(dr).GameServerId.Equals(o.GameServerId)));

              //#2 search by game Id
              int gameId = Dictionaries.Instance.GetGameIdByGameServerId(o.GameServerId);
              filter = new BuyingSearchFilter();
              filter.GameId = gameId;
              ds = BuyingFacade.SearchOffers(filter);
              Assert.GreaterOrEqual(ds.Tables[0].Rows.Count, 1);
              Assert.IsTrue(ds.Tables[0].Select().All(dr
              => Dictionaries.Instance.GetGameIdByGameServerId(new Buying().Load<Buying>(dr).GameServerId).Equals(gameId)));

              //#3 search by game name
              string gameName = Dictionaries.Instance.GetGameNameByGameServerId(o.GameServerId);
              filter = new BuyingSearchFilter();
              filter.GameName = gameName;
              ds = BuyingFacade.SearchOffers(filter);
              Assert.GreaterOrEqual(ds.Tables[0].Rows.Count, 1);
              Assert.IsTrue(ds.Tables[0].Select().All(dr
              => Dictionaries.Instance.GetGameNameByGameServerId(new Buying().Load<Buying>(dr).GameServerId).Contains(gameName)));

              //#4 search by game server name
              string gameServerName = Dictionaries.Instance.GetGameServerNameById(o.GameServerId);
              filter = new BuyingSearchFilter();
              filter.GameServerName = gameServerName;
              ds = BuyingFacade.SearchOffers(filter);
              Assert.GreaterOrEqual(ds.Tables[0].Rows.Count, 1);
              Assert.IsTrue(ds.Tables[0].Select().All(dr
              => Dictionaries.Instance.GetGameServerNameById(new Buying().Load<Buying>(dr).GameServerId).Contains(gameServerName)));

              //#5 search by title
              string title = o.Title;
              filter = new BuyingSearchFilter();
              filter.Title = title;
              ds = BuyingFacade.SearchOffers(filter);
              Assert.GreaterOrEqual(ds.Tables[0].Rows.Count, 1);
              Assert.IsTrue(ds.Tables[0].Select().All(dr
              => new Buying().Load<Buying>(dr).Title.Contains(title)));

              //#6 search by description
              string description = o.Description;
              filter = new BuyingSearchFilter();
              filter.Description = description;
              ds = BuyingFacade.SearchOffers(filter);
              Assert.GreaterOrEqual(ds.Tables[0].Rows.Count, 1);
              Assert.IsTrue(ds.Tables[0].Select().All(dr
              => new Buying().Load<Buying>(dr).Description.Contains(description)));

              //#7 search by sellerId
              var buyerId = o.BuyerId;
              filter = new BuyingSearchFilter();
              filter.UserId = buyerId;
              ds = BuyingFacade.SearchOffers(filter);
              Assert.GreaterOrEqual(ds.Tables[0].Rows.Count, 1);
              Assert.IsTrue(ds.Tables[0].Select().All(dr
              => new Buying().Load<Buying>(dr).BuyerId == buyerId));

              //#8 search by productCategoryId
              var category = o.ProductCategoryId;
              filter = new BuyingSearchFilter() { ProductCategoryId = o.ProductCategoryId };
              ds = BuyingFacade.SearchOffers(filter);
              Assert.GreaterOrEqual(ds.Tables[0].Rows.Count, 1);
              Assert.IsTrue(ds.Tables[0].Select().All(dr
              => { var b = new Buying().Load<Buying>(dr); return b.ProductCategoryId == category || b.ProductCategoryId == 0; }));
        }
Ejemplo n.º 6
0
 public static Buying AddOffer(Buying bo, out int historyId)
 {
     return new Buying().Load<Buying>(BuyingDataAdapter.AddOffer(bo, out historyId));
 }
Ejemplo n.º 7
0
 public static Buying AddOffer(Buying bo)
 {
     int hId = 0;
       return AddOffer(bo, out hId);
 }
Ejemplo n.º 8
0
 public static Buying UpdateOffer(Buying bo)
 {
     int hid = 0;
       return UpdateOffer(bo, out hid);
 }